Skip to content

Commit

Permalink
fix(core): error page 500 status dark mode (#5180)
Browse files Browse the repository at this point in the history
close #5155
  • Loading branch information
joooye34 committed Dec 5, 2023
1 parent 246fbd8 commit 48f4d6a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button } from '@affine/component/ui/button';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useAsyncCallback } from '@toeverything/hooks/affine-async-hooks';
import { useTheme } from 'next-themes';
import {
type FC,
type PropsWithChildren,
Expand All @@ -10,7 +11,8 @@ import {
} from 'react';

import imageUrlFor404 from '../error-assets/404-status.assets.svg';
import imageUrlFor500 from '../error-assets/500-status.assets.svg';
import imageUrlForDark500 from '../error-assets/dark-500-status.assets.svg';
import imageUrlForLight500 from '../error-assets/light-500-status.assets.svg';
import * as styles from './error-detail.css';

export enum ErrorStatus {
Expand All @@ -30,8 +32,20 @@ export interface ErrorDetailProps extends PropsWithChildren {
}

const imageMap = new Map([
[ErrorStatus.NotFound, imageUrlFor404],
[ErrorStatus.Unexpected, imageUrlFor500],
[
ErrorStatus.NotFound,
{
light: imageUrlFor404, // TODO: Ask designer for dark/light mode image.
dark: imageUrlFor404,
},
],
[
ErrorStatus.Unexpected,
{
light: imageUrlForLight500, // TODO: Split assets lib and use image hook to handle light and dark.
dark: imageUrlForDark500,
},
],
]);

/**
Expand All @@ -49,6 +63,7 @@ export const ErrorDetail: FC<ErrorDetailProps> = props => {
const descriptions = Array.isArray(description) ? description : [description];
const [isBtnLoading, setBtnLoading] = useState(false);
const t = useAFFiNEI18N();
const { resolvedTheme } = useTheme();

const onBtnClick = useAsyncCallback(async () => {
try {
Expand Down Expand Up @@ -83,7 +98,11 @@ export const ErrorDetail: FC<ErrorDetailProps> = props => {
{withoutImage ? null : (
<div
className={styles.errorImage}
style={{ backgroundImage: `url(${imageMap.get(status)})` }}
style={{
backgroundImage: `url(${imageMap.get(status)?.[
resolvedTheme as 'light' | 'dark'
]})`,
}}
/>
)}
</div>
Expand Down

0 comments on commit 48f4d6a

Please sign in to comment.