diff --git a/src/components/minimal-tiptap/components/section/three.tsx b/src/components/minimal-tiptap/components/section/three.tsx index e0b5b42..99dc88c 100644 --- a/src/components/minimal-tiptap/components/section/three.tsx +++ b/src/components/minimal-tiptap/components/section/three.tsx @@ -6,8 +6,8 @@ import { ToolbarButton } from '../toolbar-button'; import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'; import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; -import { useTheme } from '../../hooks/use-theme'; import { memo, FC, useState, useCallback, useEffect } from 'react'; +import { useTheme } from '@/components/theme-provider/use-theme'; type ColorItem = { cssVar: string; @@ -75,7 +75,8 @@ const MemoizedColorButton = memo( inverse: string; onClick: (value: string) => void; }) => { - const isDarkMode = useTheme(); + const { theme } = useTheme(); + const isDarkMode = theme === 'dark'; const label = isDarkMode && color.darkLabel ? color.darkLabel : color.label; return ( diff --git a/src/components/minimal-tiptap/hooks/use-theme.ts b/src/components/minimal-tiptap/hooks/use-theme.ts deleted file mode 100644 index 00aa3b3..0000000 --- a/src/components/minimal-tiptap/hooks/use-theme.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useEffect, useState } from 'react'; - -export const useTheme = () => { - const [isDarkMode, setIsDarkMode] = useState(false); - - useEffect(() => { - const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); - setIsDarkMode(darkModeMediaQuery.matches); - - const handleChange = (e: MediaQueryListEvent) => { - const newDarkMode = e.matches; - setIsDarkMode(newDarkMode); - }; - - darkModeMediaQuery.addEventListener('change', handleChange); - - return () => { - darkModeMediaQuery.removeEventListener('change', handleChange); - }; - }, []); - - return isDarkMode; -}; diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsx index 7f7cd44..80fcbc2 100644 --- a/src/components/ui/sonner.tsx +++ b/src/components/ui/sonner.tsx @@ -1,5 +1,5 @@ -import { useTheme } from 'next-themes'; import { Toaster as Sonner } from 'sonner'; +import { useTheme } from '../theme-provider/use-theme'; type ToasterProps = React.ComponentProps; @@ -10,6 +10,7 @@ export const Toaster = ({ ...props }: ToasterProps) => { { + if (experiments.devMode) toast.info('Checking for sw update'); + registration.update(); + }, 20000 /* 20s for testing purposes */); + } else { + if (experiments.devMode) toast.info('SW Registered: ' + registration); + } + }, + onNeedRefresh() { + toast.info('The app has been updated. Please refresh'); + }, + onRegisterError(error) { + if (experiments.devMode) toast.info('SW registration error', error); + }, + }); + return ( <> @@ -92,7 +114,7 @@ function Root() { }} /> )} - + diff --git a/vite.config.ts b/vite.config.ts index 420e34f..36bf3b4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,25 +10,21 @@ import { execSync } from 'child_process'; const commitHash = execSync('git rev-parse --short HEAD').toString().trim(); const buildDate = new Date().toISOString(); -const define = JSON.parse( - JSON.stringify({ - __APP_NAME__: `"${name}"`, - __APP_VERSION__: `"${version}"`, - __COMMIT_HASH__: `"${commitHash}"`, - __BUILD_DATE__: `"${buildDate}"`, - }), -); - // https://vitejs.dev/config/ export default defineConfig({ - define, + define: { + __APP_NAME__: JSON.stringify(name), + __APP_VERSION__: JSON.stringify(version), + __COMMIT_HASH__: JSON.stringify(commitHash), + __BUILD_DATE__: JSON.stringify(buildDate), + }, plugins: [ TanStackRouterVite({ routeFileIgnorePattern: 'components', }), react({}), VitePWA({ - registerType: 'autoUpdate', + registerType: 'prompt', devOptions: { enabled: process.env.NODE_ENV !== 'test', },