refactor(core): set edgeless theme on doc created (#8670)

This commit is contained in:
EYHN
2024-11-04 04:38:03 +00:00
parent a4f27ef391
commit 12e3cf1d07
27 changed files with 107 additions and 126 deletions

View File

@@ -1,30 +0,0 @@
import { ProviderComposer } from '@affine/component/provider-composer';
import { ThemeProvider } from '@affine/component/theme-provider';
import type { createStore } from 'jotai';
import { Provider } from 'jotai';
import type { PropsWithChildren } from 'react';
import { useMemo } from 'react';
import { ConfirmModalProvider } from '../../ui/modal';
export type AffineContextProps = PropsWithChildren<{
store?: ReturnType<typeof createStore>;
}>;
export function AffineContext(props: AffineContextProps) {
return (
<ProviderComposer
contexts={useMemo(
() =>
[
<Provider key="JotaiProvider" store={props.store} />,
<ThemeProvider key="ThemeProvider" />,
<ConfirmModalProvider key="ConfirmModalProvider" />,
].filter(Boolean),
[props.store]
)}
>
{props.children}
</ProviderComposer>
);
}

View File

@@ -1,26 +0,0 @@
import { AppThemeService, useService } from '@toeverything/infra';
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
import type { PropsWithChildren } from 'react';
import { useEffect } from 'react';
const themes = ['dark', 'light'];
export function ThemeObserver() {
const { resolvedTheme } = useTheme();
const service = useService(AppThemeService);
useEffect(() => {
service.appTheme.theme$.next(resolvedTheme);
}, [resolvedTheme, service.appTheme.theme$]);
return null;
}
export const ThemeProvider = ({ children }: PropsWithChildren) => {
return (
<NextThemeProvider themes={themes} enableSystem={true}>
{children}
<ThemeObserver />
</NextThemeProvider>
);
};