feat(themes): theme layout and rearrangements

This commit is contained in:
StroepWafel committed 2026-08-26 17:29:53 +09:30
1 parent 7685df564d
commit 95acfc139d
10 files changed
+356 -101

No files matched your search

@@ -4,9 +4,10 @@
masterGridDisplayDownloadCount,
gridCardPreviewImageUrls,
} from '@/interface/utils/themeStoreFlavours'
import { isStoreThemeInstalled } from '@/interface/utils/themeListFilters'
import emblaCarouselSvelte from 'embla-carousel-svelte';
import Autoplay from 'embla-carousel-autoplay';
let { theme, onClick, toggleFavorite, isLoggedIn, onRequestSignIn, allStoreThemeRows } = $props<{
let { theme, onClick, toggleFavorite, isLoggedIn, onRequestSignIn, allStoreThemeRows, installedThemeIds = [] } = $props<{
theme: Theme;
onClick: () => void;
toggleFavorite: (theme: Theme) => void;
@@ -14,6 +15,7 @@
onRequestSignIn?: () => void;
/** Raw API themes (includes hidden slaves) for aggregated master download totals */
allStoreThemeRows?: Theme[];
installedThemeIds?: string[];
}>();
const displayDownloadCount = $derived(
@@ -47,6 +49,8 @@
];
});
const isInstalled = $derived(isStoreThemeInstalled(theme, installedThemeIds));
function handleCardClick(e: MouseEvent) {
if ((e.target as HTMLElement).closest('[data-theme-favorite]')) return;
onClick();
@@ -85,6 +89,19 @@
</span>
</div>
{/if}
{#if isInstalled}
<div class="absolute top-2 z-20 pointer-events-none {theme.featured === true ? 'left-[5.5rem]' : 'left-2'}">
<span
class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-emerald-100 text-emerald-900 dark:bg-emerald-950 dark:text-emerald-100 shadow-sm"
aria-label="Installed"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-3.5 h-3.5">
<path fill-rule="evenodd" d="M19.916 4.626a.75.75 0 01.208 1.04l-9 13.5a.75.75 0 01-1.154.114l-6-6a.75.75 0 011.06-1.06l5.353 5.353 8.493-12.739a.75.75 0 011.04-.208z" clip-rule="evenodd" />
</svg>
Installed
</span>
</div>
{/if}
<button
type="button"
data-theme-favorite
@@ -10,6 +10,7 @@
isLoggedIn,
onRequestSignIn,
allStoreThemeRows,
installedThemeIds = [],
} = $props<{
themes: Theme[];
searchTerm: string;
@@ -19,6 +20,7 @@
onRequestSignIn?: () => void;
/** Raw API list (includes `slave` rows) for master download aggregation */
allStoreThemeRows?: Theme[];
installedThemeIds?: string[];
}>();
let filteredThemes = $derived(themes.filter((theme: Theme) => {
@@ -39,21 +41,10 @@
{isLoggedIn}
{onRequestSignIn}
{allStoreThemeRows}
{installedThemeIds}
/>
{/each}
{#if filteredThemes.length !== 0}
<a href="https://docs.betterseqta.org/theme-creation/" class="block relative z-0 hover:z-20 w-full cursor-pointer">
<div class="bg-zinc-50 h-48 w-full transition-[transform,box-shadow,border-color] duration-300 ease-out relative overflow-clip rounded-xl border group group/card flex flex-col justify-center items-center hover:scale-[1.02] hover:shadow-xl dark:hover:shadow-black/60 dark:bg-zinc-800 dark:border-white/[0.1]">
<div class="text-2xl font-IconFamily">{'\uecb3'}</div>
<div class="text-xl font-bold text-center transition-all duration-500 dark:text-white">
Got a Theme Idea?
<p class="text-lg font-light subtitle">Transform it into a stunning theme!</p>
</div>
</div>
</a>
{/if}
</div>
{#if filteredThemes.length === 0}
<div class="absolute top-0 flex flex-col items-center justify-center w-full text-center h-96">
@@ -15,18 +15,21 @@ currentThemes,
setDisplayTheme,
onInstall,
onRemove,
onApply,
allThemes,
allStoreThemeRows,
displayTheme,
toggleFavorite,
isLoggedIn,
onRequestSignIn,
selectedThemeId = '',
} = $props<{
theme: Theme | null
currentThemes: string[]
setDisplayTheme: (theme: Theme | null) => void
onInstall: (themeId: string) => void | Promise<void>
onRemove: (themeId: string) => void | Promise<void>
onApply: (themeId: string) => void | Promise<void>
allThemes: Theme[]
/** Raw API themes (includes slaves) — same aggregation as grid download count */
allStoreThemeRows?: Theme[]
@@ -34,6 +37,7 @@ displayTheme: Theme | null
toggleFavorite?: (theme: Theme) => void
isLoggedIn?: boolean
onRequestSignIn?: () => void
selectedThemeId?: string
}>()
const modalDisplayDownloadCount = $derived.by(() => {
const t = theme
@@ -145,6 +149,14 @@ await onRemove(id)
installingId = null
}
}
async function runApply(id: string) {
installingId = id
try {
await onApply(id)
} finally {
installingId = null
}
}
async function onFlavourClick(flIdx: number, themeId: string, action: 'install' | 'remove') {
scrollHeroToFlavourIndex(flIdx)
if (action === 'install') await runInstall(themeId)
@@ -277,12 +289,8 @@ aria-label="Next hero slide"
<p class="mb-2 text-sm font-semibold text-zinc-800 dark:text-zinc-100">Variants</p>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 mb-6 w-full">
{#if currentThemes.includes(theme.id)}
<button
type="button"
onclick={() => onMasterVariantClick('remove')}
disabled={installingId !== null}
class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11rem] text-left shadow-md border border-zinc-400/70 dark:border-zinc-500 transition-all duration-200 hover:scale-[1.02] active:scale-[0.98] focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 dark:focus:ring-offset-zinc-800 disabled:opacity-70 group ring-1 ring-black/10 dark:ring-white/10"
title="Remove {theme.name} (master)"
<div
class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11rem] text-left shadow-md border border-zinc-400/70 dark:border-zinc-500 group ring-1 ring-black/10 dark:ring-white/10"
>
{#if masterThumb}
<img src={masterThumb} alt="" class="absolute inset-0 w-full h-full object-cover transition-transform duration-200 group-hover:scale-[1.03]" draggable="false" />
@@ -297,11 +305,31 @@ title="Remove {theme.name} (master)"
</span>
{/if}
<span class="text-lg sm:text-xl font-bold text-white drop-shadow-md tracking-tight leading-snug">
Remove · {theme.name}
{theme.id === selectedThemeId ? 'Applied · ' : ''}{theme.name}
</span>
<span class="mt-1 text-sm font-medium text-white/85">Master</span>
</div>
<span class="mt-1 text-sm font-medium text-white/85">Master · Installed</span>
<div class="mt-3 flex flex-wrap gap-2">
{#if theme.id !== selectedThemeId}
<button
type="button"
onclick={(e) => { e.stopPropagation(); void runApply(theme.id) }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-emerald-500 text-white hover:bg-emerald-600 disabled:opacity-70"
>
Apply
</button>
{/if}
<button
type="button"
onclick={(e) => { e.stopPropagation(); void onMasterVariantClick('remove') }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-white/20 text-white hover:bg-white/30 disabled:opacity-70"
>
Remove
</button>
</div>
</div>
</div>
{:else}
<button
type="button"
@@ -330,12 +358,8 @@ title="Install {theme.name} (master)"
{#each theme.flavours ?? [] as f, flavourIdx (f.id)}
{@const thumb = flavourCarouselImageUrl(f)}
{#if currentThemes.includes(f.id)}
<button
type="button"
onclick={() => onFlavourClick(flavourIdx, f.id, 'remove')}
disabled={installingId !== null}
class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11rem] text-left shadow-md border border-zinc-400/70 dark:border-zinc-500 transition-all duration-200 hover:scale-[1.02] active:scale-[0.98] focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 dark:focus:ring-offset-zinc-800 disabled:opacity-70 group ring-1 ring-black/10 dark:ring-white/10"
title="Remove {f.name}"
<div
class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11rem] text-left shadow-md border border-zinc-400/70 dark:border-zinc-500 group ring-1 ring-black/10 dark:ring-white/10"
>
{#if thumb}
<img src={thumb} alt="" class="absolute inset-0 w-full h-full object-cover transition-transform duration-200 group-hover:scale-[1.03]" draggable="false" />
@@ -350,10 +374,31 @@ title="Remove {f.name}"
</span>
{/if}
<span class="text-lg sm:text-xl font-bold text-white drop-shadow-md tracking-tight leading-snug">
Remove · {f.name}
{f.id === selectedThemeId ? 'Applied · ' : ''}{f.name}
</span>
</div>
<span class="mt-1 text-sm font-medium text-white/85">Installed</span>
<div class="mt-3 flex flex-wrap gap-2">
{#if f.id !== selectedThemeId}
<button
type="button"
onclick={(e) => { e.stopPropagation(); scrollHeroToFlavourIndex(flavourIdx); void runApply(f.id) }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-emerald-500 text-white hover:bg-emerald-600 disabled:opacity-70"
>
Apply
</button>
{/if}
<button
type="button"
onclick={(e) => { e.stopPropagation(); void onFlavourClick(flavourIdx, f.id, 'remove') }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-white/20 text-white hover:bg-white/30 disabled:opacity-70"
>
Remove
</button>
</div>
</div>
</div>
{:else}
<button
type="button"
@@ -401,6 +446,29 @@ aria-label={theme.is_favorited ? 'Unfavorite' : 'Favorite'}
{/if}
{#if !hasFlavours}
{#if currentThemes.includes(theme.id)}
{#if theme.id === selectedThemeId}
<button
type="button"
disabled
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-emerald-700 rounded-lg dark:text-emerald-300 bg-emerald-100 dark:bg-emerald-950/50 opacity-90"
>
Applied
</button>
{:else}
<button
type="button"
onclick={() => runApply(theme.id)}
disabled={installingId !== null}
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-white rounded-lg bg-emerald-600 hover:bg-emerald-700 transition-all duration-200 hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 disabled:opacity-70"
>
{#if installingId === theme.id}
<svg class="absolute w-4 h-4 animate-spin" width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke="currentColor" fill="currentColor" class="origin-center animate-spin-fast" d="M2,12A11.2,11.2,0,0,1,13,1.05C12.67,1,12.34,1,12,1a11,11,0,0,0,0,22c.34,0,.67,0,1-.05C6,23,2,17.74,2,12Z"/>
</svg>
{/if}
<span class="{installingId === theme.id ? 'opacity-0' : 'opacity-100'}">Apply</span>
</button>
{/if}
<button
type="button"
onclick={() => runRemove(theme.id)}
@@ -8,13 +8,15 @@
import { cloudAuth } from '@/seqta/utils/CloudAuth'
import SignInToFavoriteModal from '@/interface/components/SignInToFavoriteModal.svelte'
import ThemeBlobImage from '@/interface/components/themes/ThemeBlobImage.svelte'
import { filterThemesByMode, type ThemeListMode } from '@/interface/utils/themeListFilters'
const themeManager = ThemeManager.getInstance();
let themes = $state<ThemeList | null>(null);
let { isEditMode, showNavigation = true } = $props<{
let { isEditMode, showNavigation = true, listMode = 'all' } = $props<{
isEditMode: boolean;
showNavigation?: boolean;
listMode?: ThemeListMode;
}>();
let isDragging = $state(false);
let tempTheme = $state(null);
@@ -165,6 +167,10 @@
onDestroy(() => {
themeUpdates.removeListener(fetchThemes);
})
const visibleThemes = $derived(
themes ? filterThemesByMode(themes.themes, listMode) : [],
);
</script>
<div
@@ -192,7 +198,7 @@
</div>
<div class="flex flex-col gap-2 px-2">
{#if themes}
{#each themes.themes as theme (theme.id)}
{#each visibleThemes as theme (theme.id)}
<button
class="relative group w-full aspect-theme flex justify-center items-center rounded-xl transition ring dark:ring-white ring-zinc-300 {theme.id === themes.selectedTheme ? 'dark:ring-2 ring-4' : 'ring-0'}"
onclick={(e) => handleThemeClick(theme, e)}
@@ -222,15 +228,17 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
</svg>
</div>
<div
class="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1/4 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-1/2 -translate-y-1/2"
onclick={(event) => { event.stopPropagation(); void openThemeCreator(theme.id) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') void openThemeCreator(theme.id) }}
role="button"
tabindex="-1"
>
<span class="text-lg font-IconFamily">&#xeaa5;</span>
</div>
{#if theme.isEditable}
<div
class="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1/4 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-1/2 -translate-y-1/2"
onclick={(event) => { event.stopPropagation(); void openThemeCreator(theme.id) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') void openThemeCreator(theme.id) }}
role="button"
tabindex="-1"
>
<span class="text-lg font-IconFamily">&#xeaa5;</span>
</div>
{/if}
<div
class="flex absolute right-12 top-1/4 z-20 place-items-center p-2 w-8 h-8 text-center rounded-full opacity-0 transition-all -translate-y-1/2 text-white/80 bg-black/50 group-hover:opacity-100 group-hover:top-1/2"
@@ -268,53 +276,117 @@
</div>
{/if}
{#if themes && themes.themes.length === 0 && !tempTheme}
{#if themes && visibleThemes.length === 0 && !tempTheme}
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center">
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
No themes installed
</h3>
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
Install a theme from the store or create one of your own.
</p>
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2 sm:grid-cols-2">
<button
type="button"
onclick={() => void openStorePage()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xecc5;</span>
Install a theme
</button>
<button
type="button"
onclick={() => void openThemeCreator()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xec60;</span>
Create a theme
</button>
</div>
{#if listMode === 'custom'}
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
No custom themes yet
</h3>
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
Create your own theme or follow our guide to get started.
</p>
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2">
<button
type="button"
onclick={() => void openThemeCreator()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xec60;</span>
Create a theme
</button>
</div>
{:else if listMode === 'downloaded'}
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
No downloaded themes
</h3>
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
Browse the theme store to find and install themes.
</p>
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2">
<button
type="button"
onclick={() => void openStorePage()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xecc5;</span>
Browse the store
</button>
</div>
{:else}
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
No themes installed
</h3>
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
Install a theme from the store or create one of your own.
</p>
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2 sm:grid-cols-2">
<button
type="button"
onclick={() => void openStorePage()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xecc5;</span>
Install a theme
</button>
<button
type="button"
onclick={() => void openThemeCreator()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xec60;</span>
Create a theme
</button>
</div>
{/if}
</div>
{/if}
{#if showNavigation && themes && themes.themes.length > 0}
{#if themes && ((showNavigation && visibleThemes.length > 0) || (listMode === 'custom' && visibleThemes.length > 0) || (listMode === 'downloaded' && visibleThemes.length > 0))}
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"></div>
<button
onclick={() => void openStorePage()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xecc5;</span>
<span class="ml-2">Theme Store</span>
</button>
{#if listMode === 'custom'}
<button
onclick={() => void openThemeCreator()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xec60;</span>
<span class="ml-2">Create theme</span>
</button>
<button
onclick={() => void openThemeCreator()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xec60;</span>
<span class="ml-2">Create your own</span>
</button>
<a href="https://docs.betterseqta.org/theme-creation/" class="block w-full cursor-pointer">
<div class="flex flex-col justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white hover:bg-zinc-200 dark:hover:bg-zinc-800">
<div class="text-2xl font-IconFamily">{'\uecb3'}</div>
<div class="text-lg font-bold text-center">
Got a Theme Idea?
<p class="text-base font-light text-zinc-600 dark:text-zinc-400">Transform it into a stunning theme!</p>
</div>
</div>
</a>
{:else if listMode === 'downloaded'}
<button
onclick={() => void openStorePage()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xecc5;</span>
<span class="ml-2">Theme Store</span>
</button>
{:else}
<button
onclick={() => void openStorePage()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xecc5;</span>
<span class="ml-2">Theme Store</span>
</button>
<button
onclick={() => void openThemeCreator()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
>
<span class="text-xl font-IconFamily">&#xec60;</span>
<span class="ml-2">Create your own</span>
</button>
{/if}
{/if}
</div>
</div>
+22 -17
View File
@@ -39,7 +39,7 @@
} from "@/utils/githubReleaseUpdate";
type PageId = "settings" | "themes" | "backgrounds";
type StoreTab = "themes" | "backgrounds";
type ThemeView = "theme-settings" | "theme-store";
type ThemeView = "theme-settings" | "theme-store" | "create-theme";
type BackgroundView = "background-settings" | "background-store";
type NavItem = {
@@ -94,8 +94,8 @@
label: "Themes",
items: [
{ id: "theme-store", label: "Store" },
{ id: "theme-settings", label: "Theme settings" },
{ id: "create-theme", label: "Create theme" },
{ id: "theme-settings", label: "Downloaded themes" },
{ id: "create-theme", label: "Custom themes" },
],
},
];
@@ -142,11 +142,21 @@
);
const sectionTitle = $derived.by(() => {
if (activePage === "themes") return "Themes";
if (activePage === "themes") {
if (activeThemeView === "theme-settings") return "Downloaded themes";
if (activeThemeView === "create-theme") return "Custom themes";
return "Themes";
}
if (activePage === "backgrounds") return "Backgrounds";
return [...userNav, ...appNav].find((item) => item.id === activeSection)?.label ?? "Settings";
});
const activeThemeListMode = $derived.by(() => {
if (activeThemeView === "create-theme") return "custom" as const;
if (activeThemeView === "theme-settings") return "downloaded" as const;
return "all" as const;
});
const isStoreView = $derived(
(activePage === "themes" && activeThemeView === "theme-store") ||
(activePage === "backgrounds" && activeBackgroundView === "background-store"),
@@ -256,11 +266,7 @@
}
if (activePage === "themes") {
if (id === "create-theme") {
void openThemeCreator();
} else {
activeThemeView = id as ThemeView;
}
activeThemeView = id as ThemeView;
return;
}
@@ -272,18 +278,17 @@
}
};
const openThemeCreator = async () => {
const { OpenThemeCreator } = await import("@/plugins/built-in/themes/ThemeCreator");
OpenThemeCreator();
closeExtensionPopup();
};
const applyDestination = (destination: SettingsDestination) => {
activePage = destination.page;
if (destination.page === "settings" && destination.section) {
activeSection = destination.section;
} else if (destination.page === "themes" && destination.view) {
activeThemeView = destination.view === "store" ? "theme-store" : "theme-settings";
activeThemeView =
destination.view === "store"
? "theme-store"
: destination.view === "custom"
? "create-theme"
: "theme-settings";
} else if (destination.page === "backgrounds" && destination.view) {
activeBackgroundView = destination.view === "store" ? "background-store" : "background-settings";
}
@@ -467,7 +472,7 @@
/>
{/if}
{:else if activePage === "themes"}
<Theme section="themes" />
<Theme section="themes" listMode={activeThemeListMode} />
{:else}
<Theme section="backgrounds" />
{/if}
+4 -2
View File
@@ -2,9 +2,11 @@
import BackgroundSelector from "@/interface/components/themes/BackgroundSelector.svelte"
import ThemeSelector from "@/interface/components/themes/ThemeSelector.svelte"
import { standalone } from "@/interface/utils/standalone.svelte"
import type { ThemeListMode } from "@/interface/utils/themeListFilters"
let { section = "all" } = $props<{
let { section = "all", listMode = "all" } = $props<{
section?: "all" | "themes" | "backgrounds";
listMode?: ThemeListMode;
}>();
// backgrounds
@@ -41,7 +43,7 @@
<BackgroundSelector isEditMode={editMode} bind:selectedBackground={selectedBackground} bind:selectNoBackground={selectNoBackground} />
{/if}
{#if showThemes}
<ThemeSelector isEditMode={editMode} showNavigation={section === "all"} />
<ThemeSelector isEditMode={editMode} showNavigation={section === "all"} {listMode} />
{/if}
</div>
{:else}
+16
View File
@@ -53,6 +53,7 @@
let loading = $state(true);
let displayTheme = $state<Theme | null>(null);
let currentThemes = $state<string[]>([]);
let selectedThemeId = $state('');
let error = $state<string | null>(null);
let fetchAttempt = $state(0);
@@ -74,6 +75,7 @@
const fetchCurrentThemes = async () => {
const themes = await themeManager.getAvailableThemes();
currentThemes = themes.filter(theme => theme !== null).map(theme => theme.id);
selectedThemeId = themeManager.getSelectedThemeId() || '';
};
const setDisplayTheme = (theme: Theme | null) => {
@@ -174,6 +176,7 @@
// On mount
onMount(async () => {
window.addEventListener('bsplus:highlight-theme', onHighlightThemeEvent);
themeUpdates.addListener(fetchCurrentThemes);
await fetchThemes();
await fetchCurrentThemes();
@@ -183,6 +186,7 @@
return () => {
window.removeEventListener('bsplus:highlight-theme', onHighlightThemeEvent);
themeUpdates.removeListener(fetchCurrentThemes);
};
});
@@ -219,6 +223,13 @@
await fetchCurrentThemes();
}
async function applyThemeFromStore(themeId: string) {
await themeManager.setTheme(themeId);
selectedThemeId = themeId;
themeUpdates.triggerUpdate();
void browser.runtime.sendMessage({ type: 'cloudSettingsRequestDebouncedUpload' }).catch(() => {});
}
$effect(() => {
loadBackground();
selectedBackground
@@ -287,6 +298,7 @@
{toggleFavorite}
isLoggedIn={cloudLoggedIn}
onRequestSignIn={() => (showSignInOverlay = true)}
installedThemeIds={currentThemes}
/>
{#if displayTheme}
@@ -300,6 +312,7 @@
{toggleFavorite}
isLoggedIn={cloudLoggedIn}
onRequestSignIn={() => (showSignInOverlay = true)}
{selectedThemeId}
onInstall={async (themeId: string) => {
if (displayTheme) await installThemeFromStore(themeId, displayTheme);
}}
@@ -307,6 +320,9 @@
console.debug('deleting theme', themeId);
await removeThemeFromStore(themeId);
}}
onApply={async (themeId: string) => {
await applyThemeFromStore(themeId);
}}
/>
{/if}
{:else if activeTab === 'backgrounds'}
@@ -0,0 +1,68 @@
import type { CustomTheme } from '@/types/CustomThemes';
import type { Theme } from '@/interface/types/Theme';
import { filterThemesByMode, isStoreThemeInstalled } from './themeListFilters';
function makeCustomTheme(overrides: Partial<CustomTheme> & Pick<CustomTheme, 'id' | 'name'>): CustomTheme {
return {
description: '',
defaultColour: '#000000',
CanChangeColour: true,
allowBackgrounds: true,
CustomCSS: '',
CustomImages: [],
coverImage: null,
isEditable: false,
hideThemeName: false,
...overrides,
};
}
function makeStoreTheme(overrides: Partial<Theme> & Pick<Theme, 'id' | 'name'>): Theme {
return {
description: '',
coverImage: '',
...overrides,
};
}
describe('filterThemesByMode', () => {
const downloaded = makeCustomTheme({ id: 'store-1', name: 'Store Theme', isEditable: false });
const custom = makeCustomTheme({ id: 'custom-1', name: 'Custom Theme', isEditable: true });
it('returns all themes in all mode', () => {
expect(filterThemesByMode([downloaded, custom], 'all')).toEqual([downloaded, custom]);
});
it('returns only non-editable themes in downloaded mode', () => {
expect(filterThemesByMode([downloaded, custom], 'downloaded')).toEqual([downloaded]);
});
it('returns only editable themes in custom mode', () => {
expect(filterThemesByMode([downloaded, custom], 'custom')).toEqual([custom]);
});
});
describe('isStoreThemeInstalled', () => {
it('returns true when master id is installed', () => {
const theme = makeStoreTheme({ id: 'master-1', name: 'Master' });
expect(isStoreThemeInstalled(theme, ['master-1'])).toBe(true);
});
it('returns true when a flavour id is installed', () => {
const theme = makeStoreTheme({
id: 'master-1',
name: 'Master',
flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#000', cover_image: '' }],
});
expect(isStoreThemeInstalled(theme, ['flavour-1'])).toBe(true);
});
it('returns false when neither master nor flavours are installed', () => {
const theme = makeStoreTheme({
id: 'master-1',
name: 'Master',
flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#000', cover_image: '' }],
});
expect(isStoreThemeInstalled(theme, ['other-theme'])).toBe(false);
});
});
+16
View File
@@ -0,0 +1,16 @@
import type { CustomTheme } from '@/types/CustomThemes';
import type { Theme } from '@/interface/types/Theme';
export type ThemeListMode = 'downloaded' | 'custom' | 'all';
export function filterThemesByMode(themes: CustomTheme[], mode: ThemeListMode): CustomTheme[] {
if (mode === 'all') return themes;
if (mode === 'custom') return themes.filter((theme) => theme.isEditable === true);
return themes.filter((theme) => theme.isEditable !== true);
}
export function isStoreThemeInstalled(theme: Theme, installedIds: string[]): boolean {
const installed = new Set(installedIds);
if (installed.has(theme.id)) return true;
return (theme.flavours ?? []).some((flavour) => installed.has(flavour.id));
}
+1 -1
View File
@@ -1,6 +1,6 @@
export type SettingsDestination =
| { page: "settings"; section?: string }
| { page: "themes" | "backgrounds"; view?: "settings" | "store" };
| { page: "themes" | "backgrounds"; view?: "settings" | "store" | "custom" };
export const SETTINGS_NAVIGATION_EVENT = "bsplus:navigate-settings";