move showAll to user preferences

This commit is contained in:
Michael Genson 2024-03-06 15:11:43 +00:00
parent c9fdf862a3
commit 29368d9cc4
3 changed files with 12 additions and 6 deletions

View File

@ -23,7 +23,7 @@
{{ $t("general.cancel") }} {{ $t("general.cancel") }}
</v-btn> </v-btn>
<div class="d-flex justify-end" style="width: 100%;"> <div class="d-flex justify-end" style="width: 100%;">
<v-checkbox v-model="showAll" hide-details :label="$tc('general.show-all')" class="my-auto mr-4" /> <v-checkbox v-model="preferences.viewAllLists" hide-details :label="$tc('general.show-all')" class="my-auto mr-4" />
</div> </div>
</template> </template>
</BaseDialog> </BaseDialog>
@ -132,6 +132,7 @@ import { toRefs } from "@vueuse/core";
import RecipeIngredientListItem from "./RecipeIngredientListItem.vue"; import RecipeIngredientListItem from "./RecipeIngredientListItem.vue";
import { useUserApi } from "~/composables/api"; import { useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast"; import { alert } from "~/composables/use-toast";
import { useShoppingListPreferences } from "~/composables/use-users/preferences";
import { ShoppingListSummary } from "~/lib/api/types/group"; import { ShoppingListSummary } from "~/lib/api/types/group";
import { Recipe, RecipeIngredient } from "~/lib/api/types/recipe"; import { Recipe, RecipeIngredient } from "~/lib/api/types/recipe";
@ -178,6 +179,7 @@ export default defineComponent({
setup(props, context) { setup(props, context) {
const { $auth, i18n } = useContext(); const { $auth, i18n } = useContext();
const api = useUserApi(); const api = useUserApi();
const preferences = useShoppingListPreferences();
// v-model support // v-model support
const dialog = computed({ const dialog = computed({
@ -193,11 +195,10 @@ export default defineComponent({
const state = reactive({ const state = reactive({
shoppingListDialog: true, shoppingListDialog: true,
shoppingListIngredientDialog: false, shoppingListIngredientDialog: false,
showAll: false,
}); });
const shoppingListChoices = computed(() => { const shoppingListChoices = computed(() => {
return props.shoppingLists.filter((list) => state.showAll || list.userId === $auth.user?.id); return props.shoppingLists.filter((list) => preferences.value.viewAllLists || list.userId === $auth.user?.id);
}); });
const recipeIngredientSections = ref<ShoppingListRecipeIngredientSection[]>([]); const recipeIngredientSections = ref<ShoppingListRecipeIngredientSection[]>([]);
@ -351,6 +352,7 @@ export default defineComponent({
return { return {
dialog, dialog,
preferences,
shoppingListChoices, shoppingListChoices,
...toRefs(state), ...toRefs(state),
addRecipesToList, addRecipesToList,

View File

@ -22,6 +22,7 @@ export interface UserRecipePreferences {
} }
export interface UserShoppingListPreferences { export interface UserShoppingListPreferences {
viewAllLists: boolean;
viewByLabel: boolean; viewByLabel: boolean;
} }
@ -70,6 +71,7 @@ export function useShoppingListPreferences(): Ref<UserShoppingListPreferences> {
const fromStorage = useLocalStorage( const fromStorage = useLocalStorage(
"shopping-list-preferences", "shopping-list-preferences",
{ {
viewAllLists: false,
viewByLabel: false, viewByLabel: false,
}, },
{ mergeDefaults: true } { mergeDefaults: true }

View File

@ -17,7 +17,7 @@
</BasePageTitle> </BasePageTitle>
<v-container class="d-flex justify-end px-0 pt-0 pb-4"> <v-container class="d-flex justify-end px-0 pt-0 pb-4">
<v-checkbox v-model="showAll" hide-details :label="$tc('general.show-all')" class="my-auto mr-4" /> <v-checkbox v-model="preferences.viewAllLists" hide-details :label="$tc('general.show-all')" class="my-auto mr-4" />
<BaseButton create @click="createDialog = true" /> <BaseButton create @click="createDialog = true" />
</v-container> </v-container>
@ -51,6 +51,7 @@
import { computed, defineComponent, useAsync, useContext, reactive, toRefs, useRoute } from "@nuxtjs/composition-api"; import { computed, defineComponent, useAsync, useContext, reactive, toRefs, useRoute } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api"; import { useUserApi } from "~/composables/api";
import { useAsyncKey } from "~/composables/use-utils"; import { useAsyncKey } from "~/composables/use-utils";
import { useShoppingListPreferences } from "~/composables/use-users/preferences";
export default defineComponent({ export default defineComponent({
middleware: "auth", middleware: "auth",
@ -59,13 +60,13 @@ export default defineComponent({
const userApi = useUserApi(); const userApi = useUserApi();
const route = useRoute(); const route = useRoute();
const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || ""); const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "");
const preferences = useShoppingListPreferences();
const state = reactive({ const state = reactive({
createName: "", createName: "",
createDialog: false, createDialog: false,
deleteDialog: false, deleteDialog: false,
deleteTarget: "", deleteTarget: "",
showAll: false,
}); });
const shoppingLists = useAsync(async () => { const shoppingLists = useAsync(async () => {
@ -77,7 +78,7 @@ export default defineComponent({
return []; return [];
} }
return shoppingLists.value.filter((list) => state.showAll || list.userId === $auth.user?.id); return shoppingLists.value.filter((list) => preferences.value.viewAllLists || list.userId === $auth.user?.id);
}); });
async function fetchShoppingLists() { async function fetchShoppingLists() {
@ -118,6 +119,7 @@ export default defineComponent({
return { return {
...toRefs(state), ...toRefs(state),
groupSlug, groupSlug,
preferences,
shoppingListChoices, shoppingListChoices,
createOne, createOne,
deleteOne, deleteOne,