Skip to content

Commit a66846c

Browse files
committed
fix(operation): 修复评分不足时渲染错误的问题
1 parent 9583d8e commit a66846c

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/components/viewer/OperationRating.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@ type PickedOperation = Pick<
1313
'notEnoughRating' | 'ratingRatio' | 'ratingLevel' | 'like' | 'dislike'
1414
>
1515

16-
const GetLevelDescription = (operation: PickedOperation) => {
17-
return `有${Math.round(
18-
(operation.like / (operation.like + operation.dislike)) * 100,
19-
)}%的人对本作业点了个赞(${operation.like}/${
20-
operation.like + operation.dislike
21-
})`
16+
const GetLevelDescription: FC<{
17+
operation: PickedOperation
18+
layout?: 'horizontal' | 'vertical'
19+
}> = ({ operation, layout }) => {
20+
return operation.notEnoughRating ? (
21+
layout === 'vertical' ? (
22+
<>还没有足够的评分</>
23+
) : (
24+
<>评分不足</>
25+
)
26+
) : (
27+
<Tooltip2
28+
className="!inline-block !mt-0"
29+
interactionKind={Popover2InteractionKind.HOVER}
30+
content={`有${Math.round(
31+
(operation.like / (operation.like + operation.dislike)) * 100,
32+
)}%的人为本作业点了个赞(${operation.like}/${
33+
operation.like + operation.dislike
34+
})`}
35+
position="bottom-left"
36+
>
37+
{ratingLevelToString(operation.ratingLevel)}
38+
</Tooltip2>
39+
)
2240
}
2341

2442
export const OperationRating: FC<{
@@ -74,18 +92,7 @@ export const OperationRating: FC<{
7492
layout === 'horizontal' && !operation.notEnoughRating && 'mr-1.5',
7593
)}
7694
>
77-
<Tooltip2
78-
className="!inline-block !mt-0"
79-
interactionKind={Popover2InteractionKind.HOVER}
80-
content={GetLevelDescription(operation)}
81-
position="bottom-left"
82-
>
83-
{operation.notEnoughRating
84-
? layout === 'vertical'
85-
? '还没有足够的评分'
86-
: '评分不足'
87-
: ratingLevelToString(operation.ratingLevel)}
88-
</Tooltip2>
95+
<GetLevelDescription layout={layout} operation={operation} />
8996
</div>
9097
</div>
9198
)

0 commit comments

Comments
 (0)