Skip to content

Commit

Permalink
🐛 fix: 更新状态优化为每天更新一次
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 13, 2021
1 parent efe48ee commit cc31e25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/contentScripts/activityMap/app/Heatmap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const DemoHeatmap: FC<HeatMapProps> = ({ data }) => {
values: ['日', '一', '二', '三', '四', '五', '六'],
},
week: { type: 'cat' },
commits: { sync: true, alias: '修改次数' },
commits: { sync: true, alias: '修改文档' },
date: { type: 'cat' },
},
limitInPlot: true,
Expand Down
19 changes: 16 additions & 3 deletions src/contentScripts/activityMap/app/useHeatmapData.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { useEffect, useState } from 'react';
import { getActivityData, mapToHeatData, yuqueToken } from '@/utils';
import { useLocalStorageState } from 'ahooks';
import dayjs from 'dayjs';

export const useHeatmapData = () => {
const [loading, setLoading] = useState(false);

const [data, setData] = useLocalStorageState<any[]>('HeatmapRowData', []);
const [data, setData] = useLocalStorageState<any[]>(
'PY_HEATMAP_RAW_DATA',
[],
);
const [date, setDate] = useLocalStorageState<number>(
'PY_HEATMAP_UPDATED_AT',
Date.now(),
);

const [loginPath, setLoginPath] = useLocalStorageState('LOGIN_PATH', '');
const [loginPath, setLoginPath] = useLocalStorageState('PY_LOGIN_PATH', '');

/**
* 获取数据
Expand All @@ -21,11 +29,16 @@ export const useHeatmapData = () => {
const { data: activityData, username } = result;
setLoginPath(username);
setData(activityData!);
setDate(Date.now());
}
};

useEffect(() => {
if ((yuqueToken && !loginPath) || data?.length === 0) {
if (!yuqueToken) return;
const isToday = date && dayjs(date).isSame(dayjs(), 'd');
const isEmpty = data && data.length === 0;

if (!loginPath || isEmpty || !isToday) {
fetchData();
}
}, [data]);
Expand Down
3 changes: 1 addition & 2 deletions src/utils/activityMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ export const mapDataCountToLevel = (count: number) => {
if (count === 0) return 0;
if (count < 2) return 1;
if (count < 5) return 2;
if (count < 10) return 3;
// if (count < 20) return 4;
if (count < 15) return 3;
return 4;
};
/**
Expand Down

0 comments on commit cc31e25

Please sign in to comment.