Skip to content

Commit

Permalink
🐛 fix: 修复他人主页出现自己活跃状态的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 13, 2021
1 parent 07e8443 commit 8083cdf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/contentScripts/activityMap/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Button, Col, Row, Skeleton } from 'antd';
import { ReloadOutlined, InfoCircleOutlined } from '@ant-design/icons';

import Heatmap from './Heatmap';
import { useFetchData } from './useFetchData';
import { useHeatmapData } from './useHeatmapData';
import styles from './style.less';
import { yuqueToken } from '@/utils';
import React from 'react';

const App: FC = () => {
const { loading, data, fetchData } = useFetchData();
const { loading, data, fetchData, isHome } = useHeatmapData();

return (
return yuqueToken && !isHome ? null : (
<div className={styles.container}>
<Row justify={'space-between'}>
<Col>
Expand Down
25 changes: 0 additions & 25 deletions src/contentScripts/activityMap/app/useFetchData.ts

This file was deleted.

39 changes: 39 additions & 0 deletions src/contentScripts/activityMap/app/useHeatmapData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react';
import { getActivityData, mapToHeatData, yuqueToken } from '@/utils';
import { useLocalStorageState } from 'ahooks';

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

const [data, setData] = useLocalStorageState<any[]>('HeatmapRowData', []);

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

/**
* 获取数据
*/
const fetchData = async () => {
setLoading(true);
const result = await getActivityData();
setLoading(false);

if (result) {
const { data: activityData, username } = result;
setLoginPath(username);
setData(activityData!);
}
};

useEffect(() => {
if ((yuqueToken && !loginPath) || data?.length === 0) {
fetchData();
}
}, [data]);

return {
data: mapToHeatData(data!),
loading,
fetchData,
isHome: location.pathname.substr(1) === loginPath,
};
};
9 changes: 6 additions & 3 deletions src/utils/activityMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ export const getActivityData = async () => {

const docs: ActivityDoc[] = flattenDeep(tempDocList);

return docs.filter(({ user_id }) => {
return user_id === id;
});
return {
username: login,
data: docs.filter(({ user_id }) => {
return user_id === id;
}),
};
};

/**
Expand Down

0 comments on commit 8083cdf

Please sign in to comment.