1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-19 05:09:40 +02:00

fix: Random Recipes not choosing from all recipes (#4435)

Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
Michael Genson 2024-10-29 09:47:54 -05:00 committed by GitHub
parent 8d1ce5c190
commit 6e045bf0c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 29 deletions

View file

@ -205,23 +205,14 @@ export default defineComponent({
const route = useRoute();
const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "");
const router = useRouter();
function navigateRandom() {
if (props.recipes.length > 0) {
const recipe = props.recipes[Math.floor(Math.random() * props.recipes.length)];
if (recipe.slug !== undefined) {
router.push(`/g/${groupSlug.value}/r/${recipe.slug}`);
}
}
}
const page = ref(1);
const perPage = 32;
const hasMore = ref(true);
const ready = ref(false);
const loading = ref(false);
const { fetchMore } = useLazyRecipes(isOwnGroup.value ? null : groupSlug.value);
const { fetchMore, getRandom } = useLazyRecipes(isOwnGroup.value ? null : groupSlug.value);
const router = useRouter();
const queryFilter = computed(() => {
const orderBy = props.query?.orderBy || preferences.value.orderBy;
@ -383,6 +374,15 @@ export default defineComponent({
}, useAsyncKey());
}
async function navigateRandom() {
const recipe = await getRandom(props.query, queryFilter.value);
if (!recipe?.slug) {
return;
}
router.push(`/g/${groupSlug.value}/r/${recipe.slug}`);
}
function toggleMobileCards() {
preferences.value.useMobileCards = !preferences.value.useMobileCards;
}