aboutsummaryrefslogtreecommitdiff
path: root/src/site/store
diff options
context:
space:
mode:
Diffstat (limited to 'src/site/store')
-rw-r--r--src/site/store/images.js27
-rw-r--r--src/site/store/tags.js40
2 files changed, 67 insertions, 0 deletions
diff --git a/src/site/store/images.js b/src/site/store/images.js
index 0d5e82a..be04c8a 100644
--- a/src/site/store/images.js
+++ b/src/site/store/images.js
@@ -93,6 +93,20 @@ export const actions = {
return response;
},
+ async addTag({ commit }, { fileId, tagName }) {
+ const response = await this.$axios.$post('file/tag/add', { fileId, tagName });
+
+ commit('addTagToFile', response.data);
+
+ return response;
+ },
+ async removeTag({ commit }, { fileId, tagName }) {
+ const response = await this.$axios.$post('file/tag/del', { fileId, tagName });
+
+ commit('removeTagFromFile', response.data);
+
+ return response;
+ },
};
export const mutations = {
@@ -138,6 +152,19 @@ export const mutations = {
state.fileAlbumsMap[fileId].splice(foundIndex, 1);
}
},
+ addTagToFile(state, { fileId, tag }) {
+ if (!state.fileTagsMap[fileId]) return;
+
+ state.fileTagsMap[fileId].push(tag);
+ },
+ removeTagFromFile(state, { fileId, tag }) {
+ if (!state.fileTagsMap[fileId]) return;
+
+ const foundIndex = state.fileTagsMap[fileId].findIndex(({ id }) => id === tag.id);
+ if (foundIndex > -1) {
+ state.fileTagsMap[fileId].splice(foundIndex, 1);
+ }
+ },
resetState(state) {
Object.assign(state, getDefaultState());
},
diff --git a/src/site/store/tags.js b/src/site/store/tags.js
new file mode 100644
index 0000000..c06b741
--- /dev/null
+++ b/src/site/store/tags.js
@@ -0,0 +1,40 @@
+export const state = () => ({
+ tagsList: [],
+});
+
+export const actions = {
+ async fetch({ commit }) {
+ const response = await this.$axios.$get('tags');
+
+ commit('setTags', response.tags);
+
+ return response;
+ },
+ async createTag({ commit }, name) {
+ const response = await this.$axios.$post('tag/new', { name });
+
+ commit('addTag', response.data);
+
+ return response;
+ },
+ async deleteTag({ commit }, tagId) {
+ const response = await this.$axios.$delete(`tag/${tagId}`);
+
+ commit('deleteTag', response.data);
+
+ return response;
+ },
+};
+
+export const mutations = {
+ setTags(state, tags) {
+ state.tagsList = tags;
+ },
+ addTag(state, tag) {
+ state.tagsList.unshift(tag);
+ },
+ deleteTag(state, { id: tagId }) {
+ const foundIndex = state.tagsList.findIndex(({ id }) => id === tagId);
+ state.tagsList.splice(foundIndex, 1);
+ },
+};