diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 1294f88bb..a186c07f3 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -86,6 +86,7 @@ export default { this.$store.dispatch("refreshToken"); this.$store.dispatch("requestCurrentGroup"); this.$store.dispatch("requestCategories"); + this.$store.dispatch("requestTags"); this.darkModeSystemCheck(); this.darkModeAddEventListener(); }, diff --git a/frontend/src/api/category.js b/frontend/src/api/category.js index 6855a822b..25377aad4 100644 --- a/frontend/src/api/category.js +++ b/frontend/src/api/category.js @@ -9,12 +9,12 @@ const categoryURLs = { delete_category: category => `${prefix}/${category}`, }; -export default { +export const categoryAPI = { async getAll() { let response = await apiReq.get(categoryURLs.get_all); return response.data; }, - async get_recipes_in_category(category) { + async getRecipesInCategory(category) { let response = await apiReq.get(categoryURLs.get_category(category)); return response.data; }, @@ -23,3 +23,26 @@ export default { return response.data; }, }; + +const tagPrefix = baseURL + "tags"; + +const tagURLs = { + getAll: `${tagPrefix}`, + getTag: tag => `${tagPrefix}/${tag}`, + deleteTag: tag => `${tagPrefix}/${tag}`, +}; + +export const tagAPI = { + async getAll() { + let response = await apiReq.get(tagURLs.getAll); + return response.data; + }, + async getRecipesInTag(tag) { + let response = await apiReq.get(tagURLs.getTag(tag)); + return response.data; + }, + async delete(tag) { + let response = await apiReq.delete(tagURLs.deleteTag(tag)); + return response.data; + }, +}; diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index fc224be9b..b139baec5 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -5,7 +5,7 @@ import settings from "./settings"; import themes from "./themes"; import migration from "./migration"; import myUtils from "./upload"; -import category from "./category"; +import { categoryAPI, tagAPI } from "./category"; import meta from "./meta"; import users from "./users"; import signUps from "./signUps"; @@ -24,7 +24,8 @@ export const api = { themes: themes, migrations: migration, utils: myUtils, - categories: category, + categories: categoryAPI, + tags: tagAPI, meta: meta, users: users, signUps: signUps, diff --git a/frontend/src/components/Recipe/RecipeEditor/index.vue b/frontend/src/components/Recipe/RecipeEditor/index.vue index e50d9080d..7b0d28faa 100644 --- a/frontend/src/components/Recipe/RecipeEditor/index.vue +++ b/frontend/src/components/Recipe/RecipeEditor/index.vue @@ -148,7 +148,7 @@ deletable-chips v-model="value.tags" hide-selected - :items="tags" + :items="allTags" :search-input.sync="tagsSearchInput" @change="tagssSearchInput = ''" > @@ -284,8 +284,6 @@ export default { }, categoriesSearchInput: "", tagsSearchInput: "", - categories: [], - tags: [], }; }, computed: { @@ -293,6 +291,10 @@ export default { const categories = this.$store.getters.getAllCategories; return categories.map(cat => cat.name); }, + allTags() { + const tags = this.$store.getters.getAllTags; + return tags.map(cat => cat.name); + }, }, methods: { uploadImage() { diff --git a/frontend/src/pages/HomePage.vue b/frontend/src/pages/HomePage.vue index 6f9a0f483..ac6b06a6f 100644 --- a/frontend/src/pages/HomePage.vue +++ b/frontend/src/pages/HomePage.vue @@ -59,7 +59,7 @@ export default { }); }, async getRecipeByCategory(category) { - return await api.categories.get_recipes_in_category(category); + return await api.categories.getRecipesInCategory(category); }, getRecentRecipes() { this.$store.dispatch("requestRecentRecipes"); diff --git a/frontend/src/pages/Recipes/CategoryPage.vue b/frontend/src/pages/Recipes/CategoryPage.vue index 34514a455..7663e305b 100644 --- a/frontend/src/pages/Recipes/CategoryPage.vue +++ b/frontend/src/pages/Recipes/CategoryPage.vue @@ -42,7 +42,7 @@ export default { }, methods: { async getRecipes() { - let data = await api.categories.get_recipes_in_category( + let data = await api.categories.getRecipesInCategory( this.currentCategory ); this.title = data.name; diff --git a/frontend/src/pages/Recipes/CustomPage.vue b/frontend/src/pages/Recipes/CustomPage.vue index a022ee9de..eb7783c7c 100644 --- a/frontend/src/pages/Recipes/CustomPage.vue +++ b/frontend/src/pages/Recipes/CustomPage.vue @@ -76,7 +76,7 @@ export default { }); }, async getRecipeByCategory(category) { - return await api.categories.get_recipes_in_category(category); + return await api.categories.getRecipesInCategory(category); }, filterRecipe(slug) { const storeCategory = this.recipeStore.find( diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 7065f70f0..09c07cdd2 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -27,19 +27,22 @@ const store = new Vuex.Store({ allRecipes: [], mealPlanCategories: [], allCategories: [], + allTags: [], }, mutations: { setRecentRecipes(state, payload) { state.recentRecipes = payload; }, - setMealPlanCategories(state, payload) { state.mealPlanCategories = payload; }, setAllCategories(state, payload) { state.allCategories = payload; }, + setAllTags(state, payload) { + state.allTags = payload; + }, }, actions: { @@ -60,6 +63,10 @@ const store = new Vuex.Store({ const categories = await api.categories.getAll(); commit("setAllCategories", categories); }, + async requestTags({ commit }) { + const tags = await api.tags.getAll(); + commit("setAllTags", tags); + }, }, getters: { @@ -67,6 +74,8 @@ const store = new Vuex.Store({ getMealPlanCategories: state => state.mealPlanCategories, getAllCategories: state => state.allCategories.sort((a, b) => (a.slug > b.slug ? 1 : -1)), + getAllTags: state => + state.allTags.sort((a, b) => (a.slug > b.slug ? 1 : -1)), }, }); diff --git a/mealie/routes/recipe/tag_routes.py b/mealie/routes/recipe/tag_routes.py index 50dfd379a..4fa542ac7 100644 --- a/mealie/routes/recipe/tag_routes.py +++ b/mealie/routes/recipe/tag_routes.py @@ -8,15 +8,15 @@ from sqlalchemy.orm.session import Session router = APIRouter(tags=["Recipes"]) router = APIRouter( - prefix="/api/recipes/tags", + prefix="/api/tags", tags=["Recipe Tags"], ) -@router.get("/") +@router.get("") async def get_all_recipe_tags(session: Session = Depends(generate_session)): """ Returns a list of available tags in the database """ - return db.tags.get_all_primary_keys(session) + return db.tags.get_all_limit_columns(session, ["slug", "name"]) @router.get("/{tag}")