mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
feat: (preferences) hook react display settings into user settings
This commit is contained in:
parent
ce4c7aed5e
commit
3dd26c7785
13 changed files with 530 additions and 46 deletions
|
@ -0,0 +1,32 @@
|
|||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import themeManager from 'scripts/themeManager';
|
||||
import { Theme } from 'types/webConfig';
|
||||
|
||||
export function useServerThemes() {
|
||||
const [themes, setThemes] = useState<Theme[]>();
|
||||
|
||||
useEffect(() => {
|
||||
async function getServerThemes() {
|
||||
const loadedThemes = await themeManager.getThemes();
|
||||
|
||||
setThemes(loadedThemes ?? []);
|
||||
}
|
||||
|
||||
if (!themes) {
|
||||
void getServerThemes();
|
||||
}
|
||||
// We've intentionally left the dependency array here to ensure that the effect happens only once.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const defaultTheme = useMemo(() => {
|
||||
if (!themes) return null;
|
||||
return themes.find((theme) => theme.default);
|
||||
}, [themes]);
|
||||
|
||||
return {
|
||||
themes: themes ?? [],
|
||||
defaultTheme
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue