Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions frontend/src/ts/components/pages/connections/FriendsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,24 @@ function getColumns({
defineColumn("completedTests", {
enableSorting: true,
header: "tests",
cell: (info) => `${info.getValue()}/${info.row.original.startedTests}`,
cell: (info) => {
const completedTests = info.getValue<number | undefined>();
const startedTests = info.row.original.startedTests;

return `${completedTests ?? 0}/${startedTests ?? 0}`;
},
meta: {
breakpoint: "lg",
cellMeta: ({ row }) => {
const testStats = formatTypingStatsRatio(row);

if (testStats.completedPercentage === "") {
return {};
}

return {
"data-balloon-pos": "up",
"aria-label": `${testStats.completedPercentage}% (${
testStats.restartRatio
} restarts per completed test)`,
"aria-label": `${testStats.completedPercentage}% (${testStats.restartRatio} restarts per completed test)`,
};
},
},
Expand Down
23 changes: 12 additions & 11 deletions frontend/src/ts/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,21 +715,22 @@ export function formatTypingStatsRatio(stats: {
completedPercentage: string;
restartRatio: string;
} {
if (
stats.completedTests === undefined ||
stats.startedTests === undefined ||
stats.startedTests === 0
) {
return { completedPercentage: "", restartRatio: "" };
const startedTests = stats.startedTests ?? 0;
const completedTests = stats.completedTests ?? 0;

if (startedTests === 0) {
return { completedPercentage: "0", restartRatio: "0" };
}

const abandonedTests = startedTests - completedTests;
const restartRatio =
completedTests === 0 ? "0" : (abandonedTests / completedTests).toFixed(1);

return {
completedPercentage: Math.floor(
(stats.completedTests / stats.startedTests) * 100,
(completedTests / startedTests) * 100,
).toString(),
restartRatio: (
(stats.startedTests - stats.completedTests) /
stats.completedTests
).toFixed(1),
restartRatio,
};
}

Expand Down
Loading