Skip to content

Commit a1549f2

Browse files
Merge pull request #10 from kcoderhtml/Fix-leaderboard-formatting
Fix leaderboard formatting
2 parents 139c79b + c707efb commit a1549f2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

utils/slack.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ function generateLeaderboardTable(users: user[]): string {
3636

3737
const userCell = ` ${user.user}${" ".repeat(maxUsernameLength - user.user.length)} `;
3838
const cells = uniqueTimestamps.map((timestamp, index) => {
39-
const date = postsByDate.has(timestamp)
40-
? user.posts.find(
41-
(p) => p.timestamp.toISOString().split("T")[0] === timestamp,
42-
)
43-
: null;
39+
const date = user.posts.filter(
40+
(post) => post.timestamp.toISOString().split("T")[0] === timestamp,
41+
);
4442

45-
return date
46-
? ` ${date.timestamp.getUTCHours()}:${user.posts[0].timestamp.getUTCMinutes()}:${user.posts[0].timestamp.getUTCSeconds()}`.padEnd(
43+
return date[0]
44+
? `${date.length > 1 ? `${date.length}` : "✓"} ${date[0].timestamp.getUTCHours()}:${date[0].timestamp.getUTCMinutes()}:${date[0].timestamp.getUTCSeconds()}`.padEnd(
4745
dateLengths[index] + 2,
4846
)
4947
: " ".repeat(dateLengths[index] + 2);
@@ -100,7 +98,7 @@ export async function get10DaysLeaderboard(start: Date, end: Date) {
10098
});
10199

102100
// display the leaderboard in markdown format
103-
const leaderboardFormatted = `# 10 Days in Public Leaderboard from ${start.toISOString().split("T")[0]} to ${end.toISOString().split("T")[0]}\n\nGood Luck and have fun!\nTime next to the checkmarks is given in h:m:s local time for that user🚀\n\n${generateLeaderboardTable(users)}`;
101+
const leaderboardFormatted = `# 10 Days in Public Leaderboard from ${start.toISOString().split("T")[0]} to ${end.toISOString().split("T")[0]}\n\nGood Luck and have fun!\nTime next to the checkmarks is given in h:m:s local time for that user🚀\n\n${generateLeaderboardTable(users)}\n`;
104102

105103
return leaderboardFormatted;
106104
}

0 commit comments

Comments
 (0)