feat: If only 1 shopping list, navigate straight to it (Shopping List QoL) (#3764)

Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
boc-the-git 2024-06-21 22:17:39 +10:00 committed by GitHub
parent d923b4c7fa
commit eb36912e5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View File

@ -2,7 +2,16 @@
<v-container v-if="shoppingList" class="md-container">
<BasePageTitle divider>
<template #header>
<v-img max-height="100" max-width="100" :src="require('~/static/svgs/shopping-cart.svg')"></v-img>
<v-container>
<v-row>
<v-col cols="3" class="text-left">
<ButtonLink :to="`/shopping-lists?disableRedirect=true`" :text="$tc('general.back')" :icon="$globals.icons.backArrow" />
</v-col>
<v-col cols="6" class="d-flex justify-center">
<v-img max-height="100" max-width="100" :src="require('~/static/svgs/shopping-cart.svg')"></v-img>
</v-col>
</v-row>
</v-container>
</template>
<template #title> {{ shoppingList.name }} </template>
</BasePageTitle>

View File

@ -48,7 +48,7 @@
</template>
<script lang="ts">
import { computed, defineComponent, useAsync, useContext, reactive, toRefs, useRoute } from "@nuxtjs/composition-api";
import { computed, defineComponent, useAsync, useContext, reactive, toRefs, useRoute, useRouter } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api";
import { useAsyncKey } from "~/composables/use-utils";
import { useShoppingListPreferences } from "~/composables/use-users/preferences";
@ -59,7 +59,9 @@ export default defineComponent({
const { $auth } = useContext();
const userApi = useUserApi();
const route = useRoute();
const router = useRouter();
const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "");
const disableRedirect = computed(() => route.value.query.disableRedirect === "true");
const preferences = useShoppingListPreferences();
const state = reactive({
@ -116,6 +118,15 @@ export default defineComponent({
}
}
if (!disableRedirect.value) {
useAsync(async () => {
await refresh();
if (shoppingListChoices.value?.length === 1) {
router.push(`/shopping-lists/${shoppingListChoices.value[0].id}`);
}
}, useAsyncKey());
}
return {
...toRefs(state),
groupSlug,