refactor: remove unused code (#2425)

This commit is contained in:
Himself65 2023-05-17 17:15:12 -07:00 committed by GitHub
parent f875b37641
commit d6b640726e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 3 additions and 94 deletions

View File

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

View File

@ -1,5 +1,3 @@
export * from './helper';
export * from './mui-theme';
export * from './mui-theme-provider';
export * from './types';
export * from './utils';

View File

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

View File

@ -1,5 +1,3 @@
import '@emotion/react';
import type {
Breakpoint,
BreakpointsOptions,

View File

@ -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 {}
}

View File

@ -1,2 +0,0 @@
export * from './local-storage-theme-helper';
export * from './system-theme-helper';

View File

@ -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();

View File

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