mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-10 13:56:35 +03:00
refactor: remove unused code (#2425)
This commit is contained in:
parent
f875b37641
commit
d6b640726e
@ -1,4 +1,3 @@
|
||||
import type { ThemeProviderProps } from '@affine/component';
|
||||
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { memo, useRef } from 'react';
|
||||
@ -21,12 +20,9 @@ const DesktopThemeSync = memo(function DesktopThemeSync() {
|
||||
return null;
|
||||
});
|
||||
|
||||
export const ThemeProvider = ({
|
||||
children,
|
||||
...props
|
||||
}: PropsWithChildren<ThemeProviderProps>) => {
|
||||
export const ThemeProvider = ({ children }: PropsWithChildren) => {
|
||||
return (
|
||||
<NextThemeProvider themes={themes} enableSystem={true} {...props}>
|
||||
<NextThemeProvider themes={themes} enableSystem={true}>
|
||||
{children}
|
||||
<DesktopThemeSync />
|
||||
</NextThemeProvider>
|
||||
|
@ -1,5 +1,3 @@
|
||||
export * from './helper';
|
||||
export * from './mui-theme';
|
||||
export * from './mui-theme-provider';
|
||||
export * from './types';
|
||||
export * from './utils';
|
||||
|
@ -1,29 +1,3 @@
|
||||
import { CssBaseline } from '@mui/material';
|
||||
import {
|
||||
alpha,
|
||||
createTheme as createMuiTheme,
|
||||
css,
|
||||
keyframes,
|
||||
styled,
|
||||
type ThemeOptions,
|
||||
ThemeProvider as MuiThemeProvider,
|
||||
} from '@mui/material/styles';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { alpha, css, keyframes, styled } from '@mui/material/styles';
|
||||
|
||||
export { alpha, css, keyframes, styled };
|
||||
|
||||
export const AffineMuiThemeProvider = ({
|
||||
theme,
|
||||
children,
|
||||
}: PropsWithChildren<{
|
||||
theme: ThemeOptions;
|
||||
}>) => {
|
||||
const muiTheme = useMemo(() => createMuiTheme(theme), [theme]);
|
||||
return (
|
||||
<MuiThemeProvider theme={muiTheme}>
|
||||
<CssBaseline />
|
||||
{children}
|
||||
</MuiThemeProvider>
|
||||
);
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
import '@emotion/react';
|
||||
|
||||
import type {
|
||||
Breakpoint,
|
||||
BreakpointsOptions,
|
||||
|
@ -1,13 +0,0 @@
|
||||
import type { AffineTheme } from '@toeverything/theme';
|
||||
|
||||
export type ThemeProviderProps = {
|
||||
defaultTheme?: Theme;
|
||||
};
|
||||
|
||||
export type Theme = 'light' | 'dark';
|
||||
export type ThemeMode = Theme | 'auto';
|
||||
|
||||
declare module '@emotion/react' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface Theme extends AffineTheme {}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
export * from './local-storage-theme-helper';
|
||||
export * from './system-theme-helper';
|
@ -1,13 +0,0 @@
|
||||
import type { ThemeMode } from '../types';
|
||||
|
||||
export class LocalStorageThemeHelper {
|
||||
name = 'Affine-theme-mode';
|
||||
get = (): ThemeMode | null => {
|
||||
return localStorage.getItem(this.name) as ThemeMode | null;
|
||||
};
|
||||
set = (mode: ThemeMode) => {
|
||||
localStorage.setItem(this.name, mode);
|
||||
};
|
||||
}
|
||||
|
||||
export const localStorageThemeHelper = new LocalStorageThemeHelper();
|
@ -1,29 +0,0 @@
|
||||
import type { Theme } from '../types';
|
||||
|
||||
export class SystemThemeHelper {
|
||||
media: MediaQueryList = window.matchMedia('(prefers-color-scheme: light)');
|
||||
eventList: Array<(e: Event) => void> = [];
|
||||
eventHandler = (e: Event) => {
|
||||
this.eventList.forEach(fn => fn(e));
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.media.addEventListener('change', this.eventHandler);
|
||||
}
|
||||
|
||||
get = (): Theme => {
|
||||
if (typeof window === 'undefined') {
|
||||
return 'light';
|
||||
}
|
||||
return this.media.matches ? 'light' : 'dark';
|
||||
};
|
||||
|
||||
onChange = (callback: () => void) => {
|
||||
this.eventList.push(callback);
|
||||
};
|
||||
|
||||
dispose = () => {
|
||||
this.eventList = [];
|
||||
this.media.removeEventListener('change', this.eventHandler);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user