This commit is contained in:
2026-05-01 01:30:02 +08:00
parent aabad6407f
commit 2e9d0f4640
92 changed files with 4548 additions and 248 deletions

View File

@@ -35,6 +35,12 @@ export type CreationWorkShelfMetric = {
tone: CreationWorkShelfMetricTone;
};
export type CreationWorkShelfPointIncentive = {
totalHalfPoints: number;
totalPoints: number;
claimablePoints: number;
};
export type CreationWorkShelfSource =
| {
kind: 'rpg';
@@ -66,6 +72,7 @@ export type CreationWorkShelfItem = {
canShare: boolean;
badges: CreationWorkShelfBadge[];
metrics: CreationWorkShelfMetric[];
pointIncentive?: CreationWorkShelfPointIncentive;
source: CreationWorkShelfSource;
};
@@ -238,6 +245,21 @@ function mapPuzzleWorkToShelfItem(
likeCount: item.likeCount,
})
: [],
pointIncentive:
status === 'published'
? {
totalHalfPoints: normalizeMetricCount(
item.pointIncentiveTotalHalfPoints,
),
totalPoints: normalizePointIncentiveTotal(
item.pointIncentiveTotalPoints,
item.pointIncentiveTotalHalfPoints,
),
claimablePoints: normalizeMetricCount(
item.pointIncentiveClaimablePoints,
),
}
: undefined,
source: { kind: 'puzzle', item },
};
}
@@ -286,6 +308,24 @@ export function formatCreationMetricCount(value?: number | null) {
return `${normalized}`;
}
export function formatCreationPointIncentiveTotal(value?: number | null) {
const normalized = Math.max(0, value ?? 0);
return Number.isInteger(normalized)
? normalized.toFixed(0)
: normalized.toFixed(1);
}
function normalizePointIncentiveTotal(
totalPoints?: number | null,
totalHalfPoints?: number | null,
) {
if (Number.isFinite(totalPoints)) {
return Math.max(0, totalPoints ?? 0);
}
return normalizeMetricCount(totalHalfPoints) / 2;
}
function buildStatusBadge(
status: CreationWorkShelfStatus,
): CreationWorkShelfBadge {