From 18b4bdbf364b0bd2e4161f43622b44c521068ee8 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Tue, 4 Jun 2024 21:14:36 +0800 Subject: [PATCH] feat: Add useTheme hook to components --- src/features/metrics/components/disks/disk.info.tsx | 4 +++- src/features/processes/components/processes.table.tsx | 7 ++----- src/layout/index.tsx | 5 ++--- src/providers/theme.provider.tsx | 6 +++++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/features/metrics/components/disks/disk.info.tsx b/src/features/metrics/components/disks/disk.info.tsx index ef6ad1fe..ed88fea9 100644 --- a/src/features/metrics/components/disks/disk.info.tsx +++ b/src/features/metrics/components/disks/disk.info.tsx @@ -7,6 +7,7 @@ import DynamicProgress from "@/components/dynamic-progress"; import useDisksStore from "@/features/metrics/stores/disk.store"; import useSystemStoreSelectors from "@/features/metrics/stores/system.store"; import formatBytes from "@/features/metrics/utils/format-bytes"; +import useTheme from "@/hooks/useTheme"; import { commands, Disk } from "@/lib"; import hasBytesTextChanged from "@/utils/has-text-changed"; import { @@ -118,6 +119,7 @@ const DiskInfoSection: React.FC<{ disk?: Disk }> = ({ disk }) => { const DiskActionGroup: React.FC<{ disk: Disk }> = ({ disk }) => { const { classes } = useStyles(); + const { isMidnight } = useTheme(); const setSelectedDisk = useDisksStore.use.setSelectedDisk(); const navigate = useNavigate(); const system = useSystemStoreSelectors(useShallow((state) => state.info)); @@ -137,7 +139,7 @@ const DiskActionGroup: React.FC<{ disk: Disk }> = ({ disk }) => { return ( - diff --git a/src/features/processes/components/processes.table.tsx b/src/features/processes/components/processes.table.tsx index 2a2c4ad6..37c1e4d7 100644 --- a/src/features/processes/components/processes.table.tsx +++ b/src/features/processes/components/processes.table.tsx @@ -23,7 +23,7 @@ interface ProcessTableProps { ModuleRegistry.registerModules([ClientSideRowModelModule]); const ProcessTable: React.FC = ({ title, columnDefs }) => { - const { currentTheme } = useTheme(); + const { isMidnight } = useTheme(); const processes = useProcessesSelectors.use.processes(); const [columnDefState, setColumnDefsState] = React.useState(columnDefs); const [opened, setOpened] = React.useState(false); @@ -68,10 +68,7 @@ const ProcessTable: React.FC = ({ title, columnDefs }) => { -
+
{ const theme = useMantineTheme(); - const { currentTheme } = useTheme(); - const isMidnight = currentTheme === THEME_OPTION.MIDNIGHT; + const { isMidnight } = useTheme(); + const styles: Styles<"body" | "main" | "root", never> | undefined = { main: { background: theme.colors.dark[8], diff --git a/src/providers/theme.provider.tsx b/src/providers/theme.provider.tsx index ccdbe290..807a2daf 100644 --- a/src/providers/theme.provider.tsx +++ b/src/providers/theme.provider.tsx @@ -14,16 +14,19 @@ interface ThemeProviderProps { interface ThemeContextType { currentTheme: THEME_OPTION; setTheme: (theme: THEME_OPTION) => void; + isMidnight: boolean; } export const ThemeContext = createContext({ currentTheme: THEME_OPTION.SLATE, setTheme: () => {}, + isMidnight: true, }); const ThemeProvider: React.FC = ({ children }) => { const [theme, setTheme] = useState(themes[THEME_OPTION.MIDNIGHT]); const [currentTheme, setCurrentTheme] = useState(THEME_OPTION.MIDNIGHT); + const [isMidnight, setIsMidnight] = useState(true); useEffect(() => { const loadTheme = async () => { @@ -34,6 +37,7 @@ const ThemeProvider: React.FC = ({ children }) => { } handleSetTheme(THEME_OPTION.SLATE); }; + setIsMidnight(currentTheme === THEME_OPTION.MIDNIGHT); loadTheme(); }, []); @@ -46,7 +50,7 @@ const ThemeProvider: React.FC = ({ children }) => { }; return ( - + {children}