fix: Update the random button flow (#6248)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
aliyyanWijaya
2025-11-03 15:52:17 +13:00
committed by GitHub
parent a460c32674
commit 5e8c4a6cee
2 changed files with 38 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ interface RecipeExplorerSearchState {
requireAllTags: boolean;
requireAllTools: boolean;
requireAllFoods: boolean;
randomSeed: number;
}>;
selectedCategories: Ref<NoUndefinedField<RecipeCategory>[]>;
selectedFoods: Ref<IngredientFood[]>;
@@ -41,6 +42,7 @@ interface RecipeExplorerSearchState {
reset: () => void;
toggleOrderDirection: () => void;
setOrderBy: (value: string) => void;
setRandomOrderBy: () => void;
filterItems: (item: RecipeCategory | RecipeTag | RecipeTool, urlPrefix: string) => void;
initialize: () => Promise<void>;
}
@@ -67,6 +69,7 @@ function createRecipeExplorerSearchState(groupSlug: ComputedRef<string>): Recipe
requireAllTags: false,
requireAllTools: false,
requireAllFoods: false,
randomSeed: 0,
});
// Store references
@@ -131,9 +134,16 @@ function createRecipeExplorerSearchState(groupSlug: ComputedRef<string>): Recipe
return {
...passedQuery.value,
_searchSeed: Date.now().toString(),
_randomSeed: state.value.randomSeed,
};
});
// Update the seed to trigger a new search
function setRandomOrderBy() {
state.value.orderBy = "random";
state.value.randomSeed = Date.now();
}
// Wait utility for async hydration
function waitUntilAndExecute(
condition: () => boolean,
@@ -442,6 +452,7 @@ function createRecipeExplorerSearchState(groupSlug: ComputedRef<string>): Recipe
reset,
toggleOrderDirection,
setOrderBy,
setRandomOrderBy,
filterItems,
initialize,
};