diff --git a/materialious/src/lib/components/settings/DeArrow.svelte b/materialious/src/lib/components/settings/DeArrow.svelte index f6e0adb1..0a06fe51 100644 --- a/materialious/src/lib/components/settings/DeArrow.svelte +++ b/materialious/src/lib/components/settings/DeArrow.svelte @@ -22,7 +22,7 @@ {$_('layout.instanceUrl')} - + done @@ -35,7 +35,7 @@ {$_('layout.deArrow.thumbnailInstanceUrl')} - + done diff --git a/materialious/src/lib/components/settings/Interface.svelte b/materialious/src/lib/components/settings/Interface.svelte index 2939b39c..10939f72 100644 --- a/materialious/src/lib/components/settings/Interface.svelte +++ b/materialious/src/lib/components/settings/Interface.svelte @@ -166,7 +166,7 @@ > {/if} - + done diff --git a/materialious/src/lib/components/settings/RYD.svelte b/materialious/src/lib/components/settings/RYD.svelte index e8f8ae04..d7984e89 100644 --- a/materialious/src/lib/components/settings/RYD.svelte +++ b/materialious/src/lib/components/settings/RYD.svelte @@ -20,7 +20,7 @@ {$_('layout.instanceUrl')} - + done diff --git a/materialious/src/lib/components/settings/Settings.svelte b/materialious/src/lib/components/settings/Settings.svelte index e8038828..7c36ad59 100644 --- a/materialious/src/lib/components/settings/Settings.svelte +++ b/materialious/src/lib/components/settings/Settings.svelte @@ -12,13 +12,29 @@ import { isUnrestrictedPlatform } from '$lib/misc'; import { isOwnBackend } from '$lib/shared'; import InternalAccount from './InternalAccount.svelte'; + import { Tabs } from 'melt/builders'; + import { mergeAttrs } from 'melt'; - let activeTab = $state('interface'); - const isActive = (id: string) => activeTab === id; + type TabCategories = + | 'interface' + | 'player' + | 'ryd' + | 'sponsorblock' + | 'dearrow' + | 'about' + | 'engine' + | 'account'; + + const tabCategories: Tabs = new Tabs({ + value: 'interface', + orientation: 'vertical' + }); + + const isActive = (id: string) => tabCategories.value === id; let mobileCategoriesButton: HTMLElement | undefined = $state(); - let tabs: { id: string; label: string; icon: string; component: Component }[] = $state([ + let tabs: { id: TabCategories; label: string; icon: string; component: Component }[] = $state([ { id: 'interface', label: $_('layout.interface'), icon: 'grid_view', component: Interface }, { id: 'player', label: $_('layout.player.title'), icon: 'smart_display', component: Player }, { id: 'ryd', label: 'Return YT Dislike', icon: 'thumb_down', component: Ryd }, @@ -71,41 +87,9 @@ } } - function onKeydown(event: KeyboardEvent, idx: number) { - const keys = ['ArrowRight', 'ArrowLeft', 'Home', 'End'] as const; - if (!keys.includes(event.key as (typeof keys)[number])) return; - - event.preventDefault(); - - let next = idx; - switch (event.key) { - case 'ArrowRight': - next = (idx + 1) % tabs.length; - break; - case 'ArrowLeft': - next = (idx - 1 + tabs.length) % tabs.length; - break; - case 'Home': - next = 0; - break; - case 'End': - next = tabs.length - 1; - break; - } - - activeTab = tabs[next].id; - - const els = document.querySelectorAll('[role="tab"]'); - els[next]?.focus(); - } - onMount(() => { checkWidth(); - addEventListener('resize', () => checkWidth()); - if ($isAndroidTvStore) { - document.getElementById(`tab-${activeTab}`)?.focus(); - } }); @@ -118,7 +102,7 @@ {#if tabs} - {@const currentTab = tabs.find((tab) => tab.id === activeTab)} + {@const currentTab = tabs.find((tab) => tab.id === tabCategories.value)} {#if currentTab} {currentTab.icon} {currentTab.label} - + {#each tabs as tab (tab)} { - activeTab = tab.id; - mobileCategoriesButton?.click(); - }} + {...mergeAttrs(tabCategories.getTrigger(tab.id), { + onclick: () => { + mobileCategoriesButton?.click(); + } + })} > {tab.icon} {tab.label} @@ -154,18 +143,13 @@ - - {#each tabs as tab, index (tab)} + + {#each tabs as tab (tab)} (activeTab = tab.id)} - onkeydown={(event) => onKeydown(event, index)} + {...tabCategories.getTrigger(tab.id)} > {tab.icon} {tab.label} @@ -177,14 +161,7 @@ {#each tabs as tab (tab)} - + {/each} diff --git a/materialious/src/lib/components/settings/SponsorBlock.svelte b/materialious/src/lib/components/settings/SponsorBlock.svelte index b11f3cf3..a33d0f34 100644 --- a/materialious/src/lib/components/settings/SponsorBlock.svelte +++ b/materialious/src/lib/components/settings/SponsorBlock.svelte @@ -58,7 +58,7 @@ /> {$_('layout.instanceUrl')} - + done