fix: flash screen when creating new page (#1657)

This commit is contained in:
Himself65
2023-03-22 02:36:49 -05:00
committed by GitHub
parent 17e29f50ab
commit e8b7ff527c
3 changed files with 19 additions and 6 deletions

View 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);
};

View File

@@ -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),