Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show CMs the current week's vote count #2823

Merged
merged 2 commits into from
Sep 11, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/lib/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ export function getCurrentGameId() {
return null;
}

// x is a date, y is data for that date
// x is a date, y is data for that date
// sets y for the last date in the data array to null
export function dropCurrentPeriod(data: { x: string; y: number | null }[]) {
const newData = [...data];
if (newData.length > 0) {
Expand Down
24 changes: 19 additions & 5 deletions src/views/User/VoteActivityGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { get } from "@/lib/requests";
import * as data from "@/lib/data";
import { ResponsiveLine } from "@nivo/line";
import { ResponsiveLine, Serie } from "@nivo/line";

Check warning on line 22 in src/views/User/VoteActivityGraph.tsx

View workflow job for this annotation

GitHub Actions / build

Unknown word (Serie)
import { dropCurrentPeriod } from "@/lib/misc";

interface VoteCountPerDay {
Expand Down Expand Up @@ -49,6 +49,7 @@
[key: string]: number;
} = {};

// Note: The vote_data.counts array is sorted by date in the backend
vote_data.counts.forEach((day) => {
const weekStart = startOfWeek(new Date(day.date)).toISOString().slice(0, 10); // Format as YYYY-MM-DD
if (!aggregatedByWeek[weekStart]) {
Expand All @@ -65,10 +66,17 @@
y: count, // y-axis will use the aggregated count
}));

const completed_weeks = dropCurrentPeriod(data);
const current_week = data.pop();

return [
{
id: "votes",
data: dropCurrentPeriod(data),
id: "weekly_votes",
data: completed_weeks,
},
{
id: "current_week",
data: [current_week],
},
];
}, [vote_data]);
Expand All @@ -88,13 +96,19 @@
return <div>No activity yet</div>;
}

const line_colors = {
weekly_votes: "rgba(230,183,151, 1)", // matches default in pie charts
current_week: "rgba(55, 200, 67, 1)", // visually matches nearby green on the page
};

return (
<div className="vote-activity-graph">
<ResponsiveLine
data={chart_data}
data={chart_data as Serie[]}

Check warning on line 107 in src/views/User/VoteActivityGraph.tsx

View workflow job for this annotation

GitHub Actions / build

Unknown word (Serie)
animate
curve="monotoneX"
enablePoints={false}
enablePoints={true}
colors={({ id }) => line_colors[id as keyof typeof line_colors]}
enableSlices="x"
axisBottom={{
format: "%d %b %g",
Expand Down
Loading