mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-18 21:55:12 -04:00
c3cf8a6ebb
(cherry picked from commit d6d90a64a39d3b9d3a95fb6b265517693a70fdd7) (cherry picked from commit 428569106499b5e3a463f1990ae2996d1ae4ab49) (cherry picked from commit d0e9504af0d88391a74e04b90638e4b2d99fb476) (cherry picked from commit ee80564dd427ca1dc14c192955efaa61f386ad44) (cherry picked from commit 76650af9fdc7ef06d13ce252986d21574903d293)
34 lines
854 B
TypeScript
34 lines
854 B
TypeScript
import { useCallback, useEffect } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { createSelector } from 'reselect';
|
|
import themes from 'Styles/Themes';
|
|
import AppState from './State/AppState';
|
|
|
|
function createThemeSelector() {
|
|
return createSelector(
|
|
(state: AppState) => state.settings.ui.item.theme || window.Prowlarr.theme,
|
|
(theme) => {
|
|
return theme;
|
|
}
|
|
);
|
|
}
|
|
|
|
function ApplyTheme() {
|
|
const theme = useSelector(createThemeSelector());
|
|
|
|
const updateCSSVariables = useCallback(() => {
|
|
Object.entries(themes[theme]).forEach(([key, value]) => {
|
|
document.documentElement.style.setProperty(`--${key}`, value);
|
|
});
|
|
}, [theme]);
|
|
|
|
// On Component Mount and Component Update
|
|
useEffect(() => {
|
|
updateCSSVariables();
|
|
}, [updateCSSVariables, theme]);
|
|
|
|
return null;
|
|
}
|
|
|
|
export default ApplyTheme;
|