Skip to content

Commit

Permalink
fix: resolve lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmch committed Jul 21, 2023
1 parent f9dac62 commit 68e6bc9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/context/theme/ThemeController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export const GlobalThemeController = ({children}: CommonThemeControllerProps) =>
const theme = useTheme();
const [prevTheme, setPrevTheme] = React.useState(theme);

const updateBodyClassName = (theme: Theme) => {
const updateBodyClassName = (newTheme: Theme) => {
const bodyEl = document.body;

if (!bodyEl.classList.contains('yc-root')) {
bodyEl.classList.add('yc-root');
}

bodyEl.classList.toggle('yc-root_theme_light', theme === Theme.Light);
bodyEl.classList.toggle('yc-root_theme_dark', theme === Theme.Dark);
bodyEl.classList.toggle('yc-root_theme_light', newTheme === Theme.Light);
bodyEl.classList.toggle('yc-root_theme_dark', newTheme === Theme.Dark);
};

React.useEffect(() => {
Expand All @@ -40,7 +40,9 @@ export const GlobalThemeController = ({children}: CommonThemeControllerProps) =>
}, [theme, prevTheme]);

React.useEffect(() => {
updateBodyClassName(prevTheme);
updateBodyClassName(theme);
// need to render only once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return <>{children}</>;
Expand Down
6 changes: 3 additions & 3 deletions src/editor/components/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const ControlPanel = ({
</div>
<div className={b('theme-switch')}>
<Select value={[theme]} onUpdate={(value) => onThemeSwitch(value[0] as Theme)}>
{Object.values(Theme).map((theme) => (
<Select.Option key={theme} value={theme}>
{themeNames[theme]}
{Object.values(Theme).map((item) => (
<Select.Option key={item} value={item}>
{themeNames[item]}
</Select.Option>
))}
</Select>
Expand Down
3 changes: 2 additions & 1 deletion src/editor/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function useEditorState({content: intialContent, custom}: Omit<EditorProp
dispatch({type: UPDATE_CONTENT, payload: newContent});
const onViewModeUpdate = (newViewMode: ViewModeItem) =>
dispatch({type: UPDATE_VIEW_MODE, payload: newViewMode});
const onThemeUpdate = (theme: Theme) => dispatch({type: UPDATE_THEME, payload: theme});
const onThemeUpdate = (newTheme: Theme) =>
dispatch({type: UPDATE_THEME, payload: newTheme});

const injectEditBlockProps = ({
type,
Expand Down

0 comments on commit 68e6bc9

Please sign in to comment.