mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(core): set edgeless theme on doc created (#8670)
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user