Skip to content

Commit

Permalink
fix: heatmap ssr user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed Nov 25, 2024
1 parent e990a67 commit 9b5c7f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/shared/src/components/CalendarHeatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const binsAttributes: React.SVGProps<SVGRectElement>[] = [
];

function getRange(count: number): number[] {
if (count <= 0) {
return [];
}

return Array.from(new Array(count), (_, i) => i);
}

Expand Down
21 changes: 13 additions & 8 deletions packages/shared/src/hooks/profile/useActivityTimeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import { useViewSize, ViewSize } from '../useViewSize';
import SettingsContext from '../../contexts/SettingsContext';

const BASE_YEAR = 2018;
const currentYear = new Date().getFullYear();
const dropdownOptions = [
'Last year',
...Array.from(new Array(currentYear - BASE_YEAR + 1), (_, i) =>
(currentYear - i).toString(),
),
];

type UseActivityTimeFilterRet = {
selectedHistoryYear: number;
Expand All @@ -29,6 +22,18 @@ type UseActivityTimeFilterRet = {
};

export function useActivityTimeFilter(): UseActivityTimeFilterRet {
const dropdownOptions = useMemo(() => {
const currentYear = new Date().getFullYear();
const optionsLength = Math.max(currentYear - BASE_YEAR + 1, 0);

return [
'Last year',
...Array.from(new Array(optionsLength), (_, i) =>
(currentYear - i).toString(),
),
];
}, []);

const laptop = useViewSize(ViewSize.Laptop);
const laptopL = useViewSize(ViewSize.LaptopL);
const { sidebarExpanded } = useContext(SettingsContext);
Expand All @@ -47,7 +52,7 @@ export function useActivityTimeFilter(): UseActivityTimeFilterRet {
const startYear = new Date(selected, 0, 1);

return [addDays(endOfYear(startYear), 1), startYear];
}, [fullHistory, selectedHistoryYear]);
}, [fullHistory, selectedHistoryYear, dropdownOptions]);

return {
selectedHistoryYear,
Expand Down

0 comments on commit 9b5c7f0

Please sign in to comment.