1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-21 22:29:39 +02:00

fix: Fixed LastMade recipes sorting order (#4980)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
PancakeZik 2025-01-30 09:33:58 +00:00 committed by GitHub
parent cb05adeb48
commit a52fda72d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View file

@ -236,14 +236,17 @@ export default defineComponent({
}); });
async function fetchRecipes(pageCount = 1) { async function fetchRecipes(pageCount = 1) {
const orderDir = props.query?.orderDirection || preferences.value.orderDirection;
const orderByNullPosition = props.query?.orderByNullPosition || orderDir === "asc" ? "first" : "last";
return await fetchMore( return await fetchMore(
page.value, page.value,
perPage * pageCount, perPage * pageCount,
props.query?.orderBy || preferences.value.orderBy, props.query?.orderBy || preferences.value.orderBy,
props.query?.orderDirection || preferences.value.orderDirection, orderDir,
orderByNullPosition,
props.query, props.query,
// we use a computed queryFilter to filter out recipes that have a null value for the property we're sorting by // we use a computed queryFilter to filter out recipes that have a null value for the property we're sorting by
queryFilter.value queryFilter.value,
); );
} }

View file

@ -2,7 +2,7 @@ import { useAsync, useRouter, ref } from "@nuxtjs/composition-api";
import { useAsyncKey } from "../use-utils"; import { useAsyncKey } from "../use-utils";
import { usePublicExploreApi } from "~/composables/api/api-client"; import { usePublicExploreApi } from "~/composables/api/api-client";
import { useUserApi } from "~/composables/api"; import { useUserApi } from "~/composables/api";
import { Recipe } from "~/lib/api/types/recipe"; import { OrderByNullPosition, Recipe } from "~/lib/api/types/recipe";
import { RecipeSearchQuery } from "~/lib/api/user/recipes/recipe"; import { RecipeSearchQuery } from "~/lib/api/user/recipes/recipe";
export const allRecipes = ref<Recipe[]>([]); export const allRecipes = ref<Recipe[]>([]);
@ -11,12 +11,14 @@ export const recentRecipes = ref<Recipe[]>([]);
function getParams( function getParams(
orderBy: string | null = null, orderBy: string | null = null,
orderDirection = "desc", orderDirection = "desc",
orderByNullPosition: OrderByNullPosition | null = null,
query: RecipeSearchQuery | null = null, query: RecipeSearchQuery | null = null,
queryFilter: string | null = null queryFilter: string | null = null
) { ) {
return { return {
orderBy, orderBy,
orderDirection, orderDirection,
orderByNullPosition,
paginationSeed: query?._searchSeed, // propagate searchSeed to stabilize random order pagination paginationSeed: query?._searchSeed, // propagate searchSeed to stabilize random order pagination
searchSeed: query?._searchSeed, // unused, but pass it along for completeness of data searchSeed: query?._searchSeed, // unused, but pass it along for completeness of data
search: query?.search, search: query?.search,
@ -47,6 +49,7 @@ export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
perPage: number, perPage: number,
orderBy: string | null = null, orderBy: string | null = null,
orderDirection = "desc", orderDirection = "desc",
orderByNullPosition: OrderByNullPosition | null = null,
query: RecipeSearchQuery | null = null, query: RecipeSearchQuery | null = null,
queryFilter: string | null = null, queryFilter: string | null = null,
) { ) {
@ -54,7 +57,7 @@ export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
const { data, error } = await api.recipes.getAll( const { data, error } = await api.recipes.getAll(
page, page,
perPage, perPage,
getParams(orderBy, orderDirection, query, queryFilter), getParams(orderBy, orderDirection, orderByNullPosition, query, queryFilter),
); );
if (error?.response?.status === 404) { if (error?.response?.status === 404) {
@ -88,7 +91,7 @@ export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
} }
async function getRandom(query: RecipeSearchQuery | null = null, queryFilter: string | null = null) { async function getRandom(query: RecipeSearchQuery | null = null, queryFilter: string | null = null) {
const { data } = await api.recipes.getAll(1, 1, getParams("random", "desc", query, queryFilter)); const { data } = await api.recipes.getAll(1, 1, getParams("random", "desc", null, query, queryFilter));
if (data?.items.length) { if (data?.items.length) {
return data.items[0]; return data.items[0];
} }

View file

@ -84,6 +84,7 @@ export type RecipeSearchQuery = {
page?: number; page?: number;
perPage?: number; perPage?: number;
orderBy?: string; orderBy?: string;
orderByNullPosition?: "first" | "last";
_searchSeed?: string; _searchSeed?: string;
}; };