1
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user