mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move theme and custom css to react components
This commit is contained in:
parent
27f4b8a7e5
commit
88b247596a
8 changed files with 159 additions and 143 deletions
37
src/components/CustomCss.tsx
Normal file
37
src/components/CustomCss.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import React, { FC, useEffect, useState } from 'react';
|
||||
|
||||
import { useApi } from 'hooks/useApi';
|
||||
import { useUserSettings } from 'hooks/useUserSettings';
|
||||
|
||||
const CustomCss: FC = () => {
|
||||
const { api } = useApi();
|
||||
const { customCss: userCustomCss, disableCustomCss } = useUserSettings();
|
||||
const [ brandingCssUrl, setBrandingCssUrl ] = useState<string>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) return;
|
||||
|
||||
setBrandingCssUrl(api.getUri('/Branding/Css.css'));
|
||||
}, [ api ]);
|
||||
|
||||
if (!api) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{!disableCustomCss && brandingCssUrl && (
|
||||
<link
|
||||
rel='stylesheet'
|
||||
type='text/css'
|
||||
href={brandingCssUrl}
|
||||
/>
|
||||
)}
|
||||
{userCustomCss && (
|
||||
<style>
|
||||
{userCustomCss}
|
||||
</style>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default CustomCss;
|
34
src/components/ThemeCss.tsx
Normal file
34
src/components/ThemeCss.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import React, { FC, useEffect, useState } from 'react';
|
||||
|
||||
import { useUserTheme } from 'hooks/useUserTheme';
|
||||
import { getDefaultTheme } from 'scripts/settings/webSettings';
|
||||
|
||||
interface ThemeCssProps {
|
||||
dashboard?: boolean
|
||||
}
|
||||
|
||||
const getThemeUrl = (id: string) => `themes/${id}/theme.css`;;
|
||||
|
||||
const DEFAULT_THEME_URL = getThemeUrl(getDefaultTheme().id);
|
||||
|
||||
const ThemeCss: FC<ThemeCssProps> = ({
|
||||
dashboard = false
|
||||
}) => {
|
||||
const { theme, dashboardTheme } = useUserTheme();
|
||||
const [ themeUrl, setThemeUrl ] = useState(DEFAULT_THEME_URL);
|
||||
|
||||
useEffect(() => {
|
||||
const id = dashboard ? dashboardTheme : theme;
|
||||
if (id) setThemeUrl(getThemeUrl(id));
|
||||
}, [dashboard, dashboardTheme, theme]);
|
||||
|
||||
return (
|
||||
<link
|
||||
rel='stylesheet'
|
||||
type='text/css'
|
||||
href={themeUrl}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeCss;
|
Loading…
Add table
Add a link
Reference in a new issue