From d65579ae9e3554c4c15aa9ab4bc81aae6f928dd5 Mon Sep 17 00:00:00 2001 From: lauirf <592184299@qq.com> Date: Tue, 4 Feb 2025 01:26:58 +0800 Subject: [PATCH 1/4] add rating in card --- src/components/OperationCard.tsx | 160 ++++++++++++++++------ src/components/OperationList.tsx | 4 +- src/components/viewer/OperationViewer.tsx | 36 ++--- src/services/operation.ts | 34 +++++ 4 files changed, 167 insertions(+), 67 deletions(-) diff --git a/src/components/OperationCard.tsx b/src/components/OperationCard.tsx index 7bee455a..2f9ff430 100644 --- a/src/components/OperationCard.tsx +++ b/src/components/OperationCard.tsx @@ -1,23 +1,49 @@ -import { Button, Card, Elevation, H4, H5, Icon, Tag } from '@blueprintjs/core' +import { Button, ButtonGroup, Card, Elevation, H4, H5, Icon, Tag } from '@blueprintjs/core' import { Tooltip2 } from '@blueprintjs/popover2' import clsx from 'clsx' -import { copyShortCode, handleDownloadJSON } from 'services/operation' +import { copyShortCode, handleDownloadJSON, handleRating } from 'services/operation' import { ReLink } from 'components/ReLink' import { RelativeTime } from 'components/RelativeTime' import { AddToOperationSetButton } from 'components/operation-set/AddToOperationSet' import { OperationRating } from 'components/viewer/OperationRating' -import { OpDifficulty, Operation } from 'models/operation' +import { OpDifficulty, Operation, OpRatingType } from 'models/operation' import { useLevels } from '../apis/level' import { createCustomLevel, findLevelByStageName } from '../models/level' import { Paragraphs } from './Paragraphs' import { EDifficulty } from './entity/EDifficulty' import { EDifficultyLevel, NeoELevel } from './entity/ELevel' +import { useEffect } from 'react' +import { useOperation } from 'apis/operation' +import { AppToaster } from './Toaster' +import { formatError } from 'utils/error' -export const NeoOperationCard = ({ operation }: { operation: Operation }) => { +export const NeoOperationCard = ({operationId}:{operationId: Operation['id']}) => { const { data: levels } = useLevels() + const { + data: operation, + error, + } = useOperation({ + id: operationId, + suspense: true, + }) + + // make eslint happy: we got Suspense out there + if (!operation) throw new Error('unreachable') + + useEffect(() => { + }, [operation]) + + useEffect(() => { + if (error) { + AppToaster.show({ + intent: 'danger', + message: `刷新作业失败:${formatError(error)}`, + }) + } + }, [error]) return ( @@ -111,9 +137,32 @@ export const NeoOperationCard = ({ operation }: { operation: Operation }) => { ) } -export const OperationCard = ({ operation }: { operation: Operation }) => { +export const OperationCard = ({operationId}:{operationId: Operation['id']}) => { const { data: levels } = useLevels() + const { + data: operation, + error, + } = useOperation({ + id: operationId, + suspense: true, + }) + + // make eslint happy: we got Suspense out there + if (!operation) throw new Error('unreachable') + + useEffect(() => { + }, [operation]) + + useEffect(() => { + if (error) { + AppToaster.show({ + intent: 'danger', + message: `刷新作业失败:${formatError(error)}`, + }) + } + }, [error]) + return ( { return ( -
- 下载原 JSON
- } - > -