Skip to content

Commit 84ae6da

Browse files
fix(analytics): properly show current wk number
1 parent b55d1a2 commit 84ae6da

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

components/analytics/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AnalyticsRes } from 'pages/api/orgs/[id]/analytics';
66

77
import { useOrg } from 'lib/context/org';
88

9-
import { formatRate, sameWeek } from './utils';
9+
import { formatRate } from './utils';
1010
import Graph from './graph';
1111

1212
interface LinkProps {
@@ -47,7 +47,15 @@ function Card<T extends Record<string, number> & { week: number }>({
4747
}: CardProps<T>): JSX.Element {
4848
const num = useMemo(() => {
4949
if (!data || !content) return undefined;
50-
const today = data.find((d) => sameWeek(new Date(d.week), new Date()));
50+
console.log('Finding current week date...', data);
51+
const today = data.find((d) => {
52+
const now = new Date();
53+
const monday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
54+
monday.setDate(monday.getDate() - 7 - monday.getDay() + 1);
55+
return monday.valueOf() === new Date(d.week).valueOf();
56+
});
57+
console.log('Found current week date:', today);
58+
console.log('Accessing data:', content[0].dataKey);
5159
return today ? today[content[0].dataKey] : 0;
5260
}, [data, content]);
5361

@@ -104,7 +112,7 @@ function Card<T extends Record<string, number> & { week: number }>({
104112
}
105113
106114
h2.loading {
107-
width: 100px;
115+
width: 50px;
108116
}
109117
110118
.header h3 {

components/analytics/utils.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// TODO: This starts the week on Mondays (by adding one to the `setDate` call),
2-
// but our calendar and availability select both start the week on Sundays.
3-
export function sameWeek(a: Date, b: Date): boolean {
4-
const awk = new Date(a.getFullYear(), a.getMonth(), a.getDate());
5-
const bwk = new Date(b.getFullYear(), b.getMonth(), b.getDate());
6-
awk.setDate(awk.getDate() - awk.getDay() + 1);
7-
bwk.setDate(bwk.getDate() - bwk.getDay() + 1);
8-
return awk.valueOf() === bwk.valueOf();
9-
}
10-
111
export function toFixed(num: number, fixed: number): string {
122
const regex = new RegExp(`^-?\\d+(?:.\\d{0,${fixed}})?`);
133
const match = regex.exec(num.toString());

0 commit comments

Comments
 (0)