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
|
import axios from "@nextcloud/axios";
import { generateUrl } from "@nextcloud/router";
import { AppState, ActionParams } from 'src/store'
import { Folder } from '../types/Folder'
export const FOLDER_MUTATION_TYPES = {
SET_FOLDERS: 'SET_FOLDERS',
DELETE_FOLDER: 'DELETE_FOLDER'
}
export const FOLDER_ACTION_TYPES = {
FETCH_FOLDERS: 'FETCH_FOLDERS',
ADD_FOLDERS: 'ADD_FOLDER',
DELETE_FOLDER: 'DELETE_FOLDER'
}
const folderUrl = generateUrl("/apps/news/folders")
export const FOLDER_ACTIONS = {
async [FOLDER_ACTION_TYPES.FETCH_FOLDERS] ({ commit }: ActionParams) {
const folders = await axios.get(
generateUrl("/apps/news/folders")
);
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, folders.data.folders);
},
[FOLDER_ACTION_TYPES.ADD_FOLDERS] ({ commit }: ActionParams, { folder }: { folder: Folder}) {
console.log(folder)
axios.post(folderUrl, {folderName: folder.name}).then(
response => commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, response.data.folders)
);
},
[FOLDER_ACTION_TYPES.DELETE_FOLDER] ({ commit }: ActionParams, { folder }: { folder: Folder}) {
/**
this.getByFolderId(folderId).forEach(function (feed) {
promises.push(self.reversiblyDelete(feed.id, false, true));
});
this.updateUnreadCache();
*/
axios.delete(folderUrl + '/' + folder.id).then(() => commit(FOLDER_MUTATION_TYPES.DELETE_FOLDER, folder))
},
// loadFolder({commit}) {
// console.log('loading folders')
// axios.get(folderUrl).then(
// response => {
// commit('addFolders', response.data.folders);
// axios.get(feedUrl).then(
// response => commit('addFeeds', response.data.feeds)
// )
// }
// )
// },
}
export const FOLDER_MUTATIONS = {
[FOLDER_MUTATION_TYPES.SET_FOLDERS] (state: AppState, folders: Folder[]) {
folders.forEach(it => {
it.feedCount = 0
it.feeds = []
state.folders.push(it)
})
},
[FOLDER_MUTATION_TYPES.DELETE_FOLDER] (state: AppState, folder: Folder) {
const index = state.folders.indexOf(folder);
state.folders.splice(index, 1);
}
}
|