mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-22 20:02:39 -05:00
fix: Favorites page fails to load when sorted by random (#6517)
Co-authored-by: “a24ithay” <“abilan.ithayakumar@imt-atlantique.net”> Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
@@ -90,6 +90,14 @@
|
|||||||
<v-list-item-title>{{ $t("general.last-made") }}</v-list-item-title>
|
<v-list-item-title>{{ $t("general.last-made") }}</v-list-item-title>
|
||||||
</div>
|
</div>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
|
<v-list-item @click="sortRecipes(EVENTS.shuffle)">
|
||||||
|
<div class="d-flex align-center flex-nowrap">
|
||||||
|
<v-icon class="mr-2" inline>
|
||||||
|
{{ $globals.icons.diceMultiple }}
|
||||||
|
</v-icon>
|
||||||
|
<v-list-item-title>{{ $t("general.random") }}</v-list-item-title>
|
||||||
|
</div>
|
||||||
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
<ContextMenu
|
<ContextMenu
|
||||||
@@ -223,6 +231,7 @@ const displayTitleIcon = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sortLoading = ref(false);
|
const sortLoading = ref(false);
|
||||||
|
const randomSeed = ref(Date.now().toString());
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const groupSlug = computed(() => route.params.groupSlug as string || $auth.user.value?.groupSlug || "");
|
const groupSlug = computed(() => route.params.groupSlug as string || $auth.user.value?.groupSlug || "");
|
||||||
@@ -256,13 +265,18 @@ const queryFilter = computed(() => {
|
|||||||
async function fetchRecipes(pageCount = 1) {
|
async function fetchRecipes(pageCount = 1) {
|
||||||
const orderDir = props.query?.orderDirection || preferences.value.orderDirection;
|
const orderDir = props.query?.orderDirection || preferences.value.orderDirection;
|
||||||
const orderByNullPosition = props.query?.orderByNullPosition || orderDir === "asc" ? "first" : "last";
|
const orderByNullPosition = props.query?.orderByNullPosition || orderDir === "asc" ? "first" : "last";
|
||||||
|
const orderBy = props.query?.orderBy || preferences.value.orderBy;
|
||||||
|
const localQuery = { ...props.query };
|
||||||
|
if (orderBy === "random") {
|
||||||
|
localQuery._searchSeed = randomSeed.value;
|
||||||
|
}
|
||||||
return await fetchMore(
|
return await fetchMore(
|
||||||
page.value,
|
page.value,
|
||||||
perPage * pageCount,
|
perPage * pageCount,
|
||||||
props.query?.orderBy || preferences.value.orderBy,
|
orderBy,
|
||||||
orderDir,
|
orderDir,
|
||||||
orderByNullPosition,
|
orderByNullPosition,
|
||||||
props.query,
|
localQuery,
|
||||||
// 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,
|
||||||
);
|
);
|
||||||
@@ -288,6 +302,9 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
async function initRecipes() {
|
async function initRecipes() {
|
||||||
|
if (preferences.value.orderBy === "random") {
|
||||||
|
randomSeed.value = Date.now().toString();
|
||||||
|
}
|
||||||
page.value = 1;
|
page.value = 1;
|
||||||
hasMore.value = true;
|
hasMore.value = true;
|
||||||
|
|
||||||
@@ -380,6 +397,15 @@ async function sortRecipes(sortType: string) {
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case EVENTS.shuffle:
|
||||||
|
setter(
|
||||||
|
"random",
|
||||||
|
$globals.icons.diceMultiple,
|
||||||
|
$globals.icons.diceMultiple, // icon in asc and desc is the same for random
|
||||||
|
);
|
||||||
|
// We update the seed value to have a different order
|
||||||
|
randomSeed.value = Date.now().toString();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unknown Event", sortType);
|
console.log("Unknown Event", sortType);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user