Skip to content

Commit

Permalink
Merge pull request #8938 from weseek/fix/146898-149469-fix-the-gap-be…
Browse files Browse the repository at this point in the history
…tween-user-themes-and-editor-themes

fix: Page history colorscheme is broken
  • Loading branch information
yuki-takei authored Jul 3, 2024
2 parents f512b7c + 144b90a commit 131104e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
31 changes: 27 additions & 4 deletions apps/app/src/client/components/PageHistory/RevisionDiff.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useMemo } from 'react';

import type { IRevisionHasPageId } from '@growi/core';
import { GrowiThemeSchemeType } from '@growi/core';
import { returnPathForURL } from '@growi/core/dist/utils/path-utils';
import { PresetThemesMetadatas } from '@growi/preset-themes';
import { createPatch } from 'diff';
import type { Diff2HtmlConfig } from 'diff2html';
import { html } from 'diff2html';
Expand All @@ -10,14 +12,19 @@ import { useTranslation } from 'next-i18next';
import Link from 'next/link';
import urljoin from 'url-join';


import { Themes, useNextThemes } from '~/stores-universal/use-next-themes';

import UserDate from '../../../components/User/UserDate';
import { useSWRxGrowiThemeSetting } from '../../../stores/admin/customize';


import styles from './RevisionDiff.module.scss';

import 'diff2html/bundles/css/diff2html.min.css';

const moduleClass = styles['revision-diff-container'];

type RevisioinDiffProps = {
currentRevision: IRevisionHasPageId,
previousRevision: IRevisionHasPageId,
Expand All @@ -34,18 +41,34 @@ export const RevisionDiff = (props: RevisioinDiffProps): JSX.Element => {
currentRevision, previousRevision, revisionDiffOpened, currentPageId, currentPagePath, onClose,
} = props;

const { theme } = useNextThemes();
const { theme: userTheme } = useNextThemes();
const { data: growiTheme } = useSWRxGrowiThemeSetting();

const colorScheme: ColorSchemeType = useMemo(() => {
switch (theme) {
if (growiTheme == null) {
return ColorSchemeType.AUTO;
}

const growiThemeSchemeType = growiTheme.pluginThemesMetadatas[0]?.schemeType
?? PresetThemesMetadatas.find(theme => theme.name === growiTheme.currentTheme)?.schemeType;

switch (growiThemeSchemeType) {
case GrowiThemeSchemeType.DARK:
return ColorSchemeType.DARK;
case GrowiThemeSchemeType.LIGHT:
return ColorSchemeType.LIGHT;
default:
// growiThemeSchemeType === GrowiThemeSchemeType.BOTH
}
switch (userTheme) {
case Themes.DARK:
return ColorSchemeType.DARK;
case Themes.LIGHT:
return ColorSchemeType.LIGHT;
default:
return ColorSchemeType.AUTO;
}
}, [theme]);
}, [growiTheme, userTheme]);

const previousText = (currentRevision._id === previousRevision._id) ? '' : previousRevision.body;

Expand All @@ -66,7 +89,7 @@ export const RevisionDiff = (props: RevisioinDiffProps): JSX.Element => {
const diffView = { __html: diffViewHTML };

return (
<div className={`${styles['revision-diff-container']}`}>
<div className={moduleClass}>
<div className="container">
<div className="row mt-2">
<div className="col px-0 py-2">
Expand Down
3 changes: 2 additions & 1 deletion apps/app/src/stores/admin/customize.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback } from 'react';

import useSWR, { SWRResponse } from 'swr';
import type { SWRResponse } from 'swr';
import useSWR from 'swr';
import useSWRImmutable from 'swr/immutable';

import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client';
Expand Down

0 comments on commit 131104e

Please sign in to comment.