diff --git a/web/src/components/layout/scaffold/Header.vue b/web/src/components/layout/scaffold/Header.vue index 0b44ff056..84de5f87a 100644 --- a/web/src/components/layout/scaffold/Header.vue +++ b/web/src/components/layout/scaffold/Header.vue @@ -62,7 +62,10 @@ const props = defineProps<{ search?: string; fullWidth?: boolean; }>(); -defineEmits(['update:search']); + +defineEmits<{ + (event: 'update:search', query: string): void; +}>(); const searchBoxPresent = props.search !== undefined; diff --git a/web/src/components/layout/scaffold/Scaffold.vue b/web/src/components/layout/scaffold/Scaffold.vue index dd60494d5..f211b1662 100644 --- a/web/src/components/layout/scaffold/Scaffold.vue +++ b/web/src/components/layout/scaffold/Scaffold.vue @@ -18,7 +18,7 @@ diff --git a/web/src/components/layout/scaffold/Tabs.vue b/web/src/components/layout/scaffold/Tabs.vue index 8dcf584a3..e9ac69d05 100644 --- a/web/src/components/layout/scaffold/Tabs.vue +++ b/web/src/components/layout/scaffold/Tabs.vue @@ -26,7 +26,7 @@ import { Tab, useTabsClient } from '~/compositions/useTabs'; const router = useRouter(); const route = useRoute(); -const { activeTab, tabs, disableHashMode } = useTabsClient(); +const { activeTab, tabs, disableUrlHashMode } = useTabsClient(); async function selectTab(tab: Tab) { if (tab.id === undefined) { @@ -34,7 +34,8 @@ async function selectTab(tab: Tab) { } activeTab.value = tab.id; - if (!disableHashMode.value) { + + if (!disableUrlHashMode.value) { await router.replace({ params: route.params, hash: `#${tab.id}` }); } } diff --git a/web/src/compositions/useTabs.ts b/web/src/compositions/useTabs.ts index 657016b6d..2da91300e 100644 --- a/web/src/compositions/useTabs.ts +++ b/web/src/compositions/useTabs.ts @@ -1,4 +1,4 @@ -import { computed, inject, onMounted, provide, Ref, ref } from 'vue'; +import { inject, onMounted, provide, Ref, ref } from 'vue'; import { useRoute } from 'vue-router'; export type Tab = { @@ -7,58 +7,39 @@ export type Tab = { }; export function useTabsProvider({ - activeTabProp, - disableHashMode, - updateActiveTabProp, + activeTab, + disableUrlHashMode, }: { - activeTabProp: Ref; - updateActiveTabProp: (tab: string) => void; - disableHashMode: Ref; + activeTab: Ref; + disableUrlHashMode: Ref; }) { const route = useRoute(); const tabs = ref([]); - const activeTab = ref(''); provide('tabs', tabs); - provide( - 'disable-hash-mode', - computed(() => disableHashMode.value), - ); - provide( - 'active-tab', - computed({ - get: () => activeTab.value, - set: (value) => { - activeTab.value = value; - updateActiveTabProp(value); - }, - }), - ); + provide('disable-url-hash-mode', disableUrlHashMode); + provide('active-tab', activeTab); onMounted(() => { - if (activeTabProp.value) { - activeTab.value = activeTabProp.value; + if (activeTab.value !== undefined) { return; } const hashTab = route.hash.replace(/^#/, ''); - if (hashTab) { - activeTab.value = hashTab; - return; - } - activeTab.value = tabs.value[0].id; + // eslint-disable-next-line no-param-reassign + activeTab.value = hashTab ?? tabs.value[0].id; }); } export function useTabsClient() { const tabs = inject>('tabs'); - const disableHashMode = inject>('disable-hash-mode'); + const disableUrlHashMode = inject>('disable-url-hash-mode'); const activeTab = inject>('active-tab'); - if (activeTab === undefined || tabs === undefined || disableHashMode === undefined) { + if (activeTab === undefined || tabs === undefined || disableUrlHashMode === undefined) { throw new Error('Please use this "useTabsClient" composition inside a component running "useTabsProvider".'); } - return { activeTab, tabs, disableHashMode }; + return { activeTab, tabs, disableUrlHashMode }; } diff --git a/web/src/views/repo/RepoWrapper.vue b/web/src/views/repo/RepoWrapper.vue index ca3eb51ba..9ee57f4ad 100644 --- a/web/src/views/repo/RepoWrapper.vue +++ b/web/src/views/repo/RepoWrapper.vue @@ -3,7 +3,7 @@ v-if="repo && repoPermissions && $route.meta.repoHeader" v-model:activeTab="activeTab" enable-tabs - disable-hash-mode + disable-tab-url-hash-mode >