sort 'recent recipes' by updated

This commit is contained in:
hay-kot 2021-05-07 09:27:52 -08:00
commit 273438156e
2 changed files with 13 additions and 7 deletions

View file

@ -1,5 +1,6 @@
import { api } from "@/api";
import Vue from "vue";
import { recipe } from "@/utils/recipe";
const state = {
recentRecipes: [],
@ -36,13 +37,14 @@ const mutations = {
const actions = {
async requestRecentRecipes() {
const payload = await api.recipes.allSummary(0, 30);
payload.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
recipe.sortByUpdated(payload);
const hash = Object.fromEntries(payload.map(e => [e.id, e]));
this.commit("setRecentRecipes", hash);
},
async requestAllRecipes({ getters }) {
const all = getters.getAllRecipes;
const payload = await api.recipes.allSummary(all.length, 9999);
recipe.sortByUpdated(payload);
const hash = Object.fromEntries([...all, ...payload].map(e => [e.id, e]));
this.commit("setAllRecipes", hash);
@ -60,7 +62,11 @@ const actions = {
const getters = {
getAllRecipes: state => Object.values(state.allRecipes),
getAllRecipesHash: state => state.allRecipes,
getRecentRecipes: state => Object.values(state.recentRecipes),
getRecentRecipes: state => {
let list = Object.values(state.recentRecipes);
recipe.sortByUpdated(list);
return list;
},
getRecentRecipesHash: state => state.recentRecipes,
};

View file

@ -26,17 +26,17 @@ async def get_recipe_summary(
"""
return db.recipes.get_all(session, limit=limit, start=start, override_schema=RecipeSummary)
return db.recipes.get_all(session, limit=limit, start=start, order_by="date_updated", override_schema=RecipeSummary)
@router.get("/api/recipes/summary/untagged", response_model=list[RecipeSummary])
async def get_untagged_recipes(session: Session = Depends(generate_session)):
return db.recipes.count_untagged(session, False, override_schema=RecipeSummary)
async def get_untagged_recipes(count: bool = False, session: Session = Depends(generate_session)):
return db.recipes.count_untagged(session, count=count, override_schema=RecipeSummary)
@router.get("/api/recipes/summary/uncategorized", response_model=list[RecipeSummary])
async def get_uncategorized_recipes(session: Session = Depends(generate_session)):
return db.recipes.count_uncategorized(session, False, override_schema=RecipeSummary)
async def get_uncategorized_recipes(count: bool = False, session: Session = Depends(generate_session)):
return db.recipes.count_uncategorized(session, count=count, override_schema=RecipeSummary)
@router.post("/api/recipes/category")