From d6f0291a27df6ad124d37a08914c1c95a173116b Mon Sep 17 00:00:00 2001 From: Florian Dupret <34862846+sephrat@users.noreply.github.com> Date: Thu, 29 Apr 2021 09:18:45 +0200 Subject: [PATCH] Provide feedback for tags CRUD --- frontend/src/api/category.js | 44 ++++++++++++++----- .../FormHelpers/CategoryTagSelector.vue | 2 +- .../components/Recipe/RecipeEditor/index.vue | 2 +- .../components/Recipe/RecipeViewer/index.vue | 4 +- frontend/src/locales/messages/en-US.json | 10 ++++- .../CategoryTagEditor/RemoveUnused.vue | 2 +- frontend/src/pages/Admin/ToolBox/index.vue | 2 +- 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/frontend/src/api/category.js b/frontend/src/api/category.js index 633e7c481..ed0e37524 100644 --- a/frontend/src/api/category.js +++ b/frontend/src/api/category.js @@ -84,28 +84,48 @@ export const tagAPI = { return response.data; }, async create(name) { - let response = await apiReq.post(tagURLs.getAll, { name: name }); - store.dispatch("requestTags"); - return response.data; + const response = await apiReq.post( + tagURLs.getAll, + { name: name }, + function() { return i18n.t('tag.tag-creation-failed'); }, + function() { return i18n.t('tag.tag-created'); } + ); + if(response) { + store.dispatch("requestTags"); + return response.data; + } }, async getRecipesInTag(tag) { let response = await apiReq.get(tagURLs.getTag(tag)); return response.data; }, async update(name, newName, overrideRequest = false) { - let response = await apiReq.put(tagURLs.updateTag(name), { name: newName }); + const response = await apiReq.put( + tagURLs.updateTag(name), + { name: newName }, + function() { return i18n.t('tag.tag-update-failed'); }, + function() { return i18n.t('tag.tag-updated'); } + ); - if (!overrideRequest) { - store.dispatch("requestTags"); + if(response) { + if (!overrideRequest) { + store.dispatch("requestTags"); + } + return response.data; } - - return response.data; }, async delete(tag, overrideRequest = false) { - let response = await apiReq.delete(tagURLs.deleteTag(tag)); - if (!overrideRequest) { - store.dispatch("requestTags"); + const response = await apiReq.delete( + tagURLs.deleteTag(tag), + null, + function() { return i18n.t('tag.tag-deletion-failed'); }, + function() { return i18n.t('tag.tag-deleted'); } + ); + if(response) { + if (!overrideRequest) { + store.dispatch("requestTags"); + } + return response.data; } - return response.data; }, }; diff --git a/frontend/src/components/FormHelpers/CategoryTagSelector.vue b/frontend/src/components/FormHelpers/CategoryTagSelector.vue index c31f0a017..526699086 100644 --- a/frontend/src/components/FormHelpers/CategoryTagSelector.vue +++ b/frontend/src/components/FormHelpers/CategoryTagSelector.vue @@ -90,7 +90,7 @@ export default { computed: { inputLabel() { if (!this.showLabel) return null; - return this.tagSelector ? this.$t('recipe.tags') : this.$t('recipe.categories'); + return this.tagSelector ? this.$t('tag.tags') : this.$t('recipe.categories'); }, activeItems() { let ItemObjects = []; diff --git a/frontend/src/components/Recipe/RecipeEditor/index.vue b/frontend/src/components/Recipe/RecipeEditor/index.vue index b8b894d78..cd675c5db 100644 --- a/frontend/src/components/Recipe/RecipeEditor/index.vue +++ b/frontend/src/components/Recipe/RecipeEditor/index.vue @@ -74,7 +74,7 @@ :show-label="false" /> -

{{ $t("recipe.tags") }}

+

{{ $t("tag.tags") }}

- {{ $t("recipe.tags") }} + {{ $t("tag.tags") }} @@ -69,7 +69,7 @@
- +
diff --git a/frontend/src/locales/messages/en-US.json b/frontend/src/locales/messages/en-US.json index 9db0d3f1f..64666570f 100644 --- a/frontend/src/locales/messages/en-US.json +++ b/frontend/src/locales/messages/en-US.json @@ -204,7 +204,6 @@ "sodium-content": "Sodium", "step-index": "Step: {step}", "sugar-content": "Sugar", - "tags": "Tags", "title": "Title", "total-time": "Total Time", "unable-to-delete-recipe": "Unable to Delete Recipe", @@ -310,6 +309,15 @@ "webhook-url": "Webhook URL" } }, + "tag": { + "tag-created": "Tag created", + "tag-creation-failed": "Tag creation failed", + "tag-deleted": "Tag deleted", + "tag-deletion-failed": "Tag deletion failed", + "tag-update-failed": "Tag update failed", + "tag-updated": "Tag updated", + "tags": "Tags" + }, "user": { "admin": "Admin", "are-you-sure-you-want-to-delete-the-link": "Are you sure you want to delete the link {link}?", diff --git a/frontend/src/pages/Admin/ToolBox/CategoryTagEditor/RemoveUnused.vue b/frontend/src/pages/Admin/ToolBox/CategoryTagEditor/RemoveUnused.vue index 2bc52d2a9..2fb873cbc 100644 --- a/frontend/src/pages/Admin/ToolBox/CategoryTagEditor/RemoveUnused.vue +++ b/frontend/src/pages/Admin/ToolBox/CategoryTagEditor/RemoveUnused.vue @@ -7,7 +7,7 @@ :title=" $t('general.delete') + ' ' + - (isTags ? $t('recipe.tags') : $t('recipe.categories')) + (isTags ? $t('tag.tags') : $t('recipe.categories')) " :loading="loading" modal-width="400" diff --git a/frontend/src/pages/Admin/ToolBox/index.vue b/frontend/src/pages/Admin/ToolBox/index.vue index a65bc552f..3e422e237 100644 --- a/frontend/src/pages/Admin/ToolBox/index.vue +++ b/frontend/src/pages/Admin/ToolBox/index.vue @@ -16,7 +16,7 @@ - {{ $t("recipe.tags") }} + {{ $t("tag.tags") }} mdi-tag-multiple-outline