mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
fix: flash screen when creating new page (#1657)
This commit is contained in:
16
apps/web/src/hooks/current/use-current-mode.ts
Normal file
16
apps/web/src/hooks/current/use-current-mode.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
|
||||
import { currentPageIdAtom, workspacePreferredModeAtom } from '../../atoms';
|
||||
|
||||
const currentModeAtom = atom<'page' | 'edgeless'>(get => {
|
||||
const pageId = get(currentPageIdAtom);
|
||||
const record = get(workspacePreferredModeAtom);
|
||||
if (pageId) return record[pageId] ?? 'page';
|
||||
else {
|
||||
return 'page';
|
||||
}
|
||||
});
|
||||
|
||||
export const useCurrentMode = () => {
|
||||
return useAtomValue(currentModeAtom);
|
||||
};
|
||||
@@ -6,14 +6,12 @@ import {
|
||||
ThemeProvider as AffineThemeProvider,
|
||||
} from '@affine/component';
|
||||
import { GlobalStyles } from '@mui/material';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import type React from 'react';
|
||||
import { memo, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { workspacePreferredModeAtom } from '../atoms';
|
||||
import { useCurrentPage } from '../hooks/current/use-current-page-id';
|
||||
import { useCurrentMode } from '../hooks/current/use-current-mode';
|
||||
|
||||
const ThemeInjector = memo<{
|
||||
themeStyle: AffineTheme;
|
||||
@@ -40,9 +38,7 @@ const ThemeInjector = memo<{
|
||||
const ThemeProviderInner = memo<React.PropsWithChildren>(
|
||||
function ThemeProviderInner({ children }) {
|
||||
const { resolvedTheme: theme } = useTheme();
|
||||
const currentPage = useCurrentPage();
|
||||
const record = useAtomValue(workspacePreferredModeAtom);
|
||||
const editorMode = currentPage ? record[currentPage.id] ?? 'page' : 'page';
|
||||
const editorMode = useCurrentMode();
|
||||
const themeStyle = useMemo(() => getLightTheme(editorMode), [editorMode]);
|
||||
const darkThemeStyle = useMemo(
|
||||
() => getDarkTheme(editorMode),
|
||||
|
||||
Reference in New Issue
Block a user