aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/views/Blog/components/Channels.vue
blob: df717206b6c5470d001e724e8bba6fdee9575686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
    <div id="channel-editor">
        <EditorTable title="Manage channels" :show-edit="showEdit" :pagination="pagination" @open-new="openNew">
            <template #table>
                <ChannelTable 
                    :items="items"
                    @open-edit="openEdit" 
                />
            </template>
            <template #editor>
                <ChannelEdit 
                    @close="closeEdit"
                    @on-submit="onSubmit"
                    @on-delete="onDelete"
                />
            </template>
        </EditorTable>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { isEmpty, filter as _filter } from 'lodash-es';
import { apiCall } from '@vnuge/vnlib.browser';
import { BlogChannel, ChannelFeed } from '@vnuge/cmnext-admin';
import { useStore } from '../../../store';
import ChannelEdit from './Channels/ChannelEdit.vue';
import ChannelTable from './Channels/ChannelTable.vue';
import EditorTable from './EditorTable.vue';

const emit = defineEmits(['close'])

const store = useStore()
const { items, pagination } = store.channels.createPages()

const showEdit = computed(() => !isEmpty(store.channels.editChannel))

const openEdit = (channel: BlogChannel) => store.channels.editId = channel.id;

const closeEdit = (update?:boolean) => {
     store.channels.editId = ''
    //reload channels
    if(update){
        store.channels.refresh()
    }
    //Reset page to top
    window.scrollTo(0, 0)
}

const openNew = () => {
     store.channels.editId = 'new'
    //Reset page to top
    window.scrollTo(0, 0)
}

const onSubmit = async ({channel, feed} : { channel:BlogChannel, feed? : ChannelFeed}) => {

    //Check for new channel, or updating old channel
    if(store.channels.editId === 'new'){
        //Exec create call
        await apiCall(async () => {
            await store.channels.add(channel, feed);
            //Close the edit panel
            closeEdit(true);
        })
    }
    else if(!isEmpty(store.channels.editId)){
        //Exec update call
        await apiCall(async () => {
            await store.channels.update(channel, feed);
            //Close the edit panel
            closeEdit(true);
        })
    }
    //Notify error state
}

const onDelete = async (channel : BlogChannel) => {
    //Exec delete call
    await apiCall(async () => {
        await store.channels.delete(channel);
        //Close the edit panel
        closeEdit(true);
    })
}

</script>

<style lang="scss">

</style>