From 3395266aab8b7f998ea13d2e6eb98000feb395c1 Mon Sep 17 00:00:00 2001 From: Dendi Date: Mon, 8 Apr 2024 20:51:31 +0800 Subject: [PATCH 1/6] fix: init go follow status --- src/content/drawer/index.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/content/drawer/index.tsx b/src/content/drawer/index.tsx index 519b5f3..b39c114 100644 --- a/src/content/drawer/index.tsx +++ b/src/content/drawer/index.tsx @@ -5,7 +5,11 @@ import Divider from '@mui/material/Divider'; import Drawer from '@mui/material/Drawer'; import IconButton from '@mui/material/IconButton'; import { styled } from '@mui/material/styles'; - +import { + XFANS_TWITTER_GO_FOLLOW, + XFANS_TWITTER_GO_FOLLOW_VERIFY, + LOCALSTORAGE_FALSE, +} from '../../constants'; import * as toaster from '../../components/Toaster'; import { XFANS_CONTENT_WIDTH, @@ -223,7 +227,15 @@ export default function PersistentDrawerRight() { {pageState === 'login' && ( - clickLogin()} /> + { + // reset follow status + localStorage.setItem(XFANS_TWITTER_GO_FOLLOW, LOCALSTORAGE_FALSE); + localStorage.setItem(XFANS_TWITTER_GO_FOLLOW_VERIFY, LOCALSTORAGE_FALSE); + clickLogin(); + }} + /> )} {pageState === 'invite' && ( clickRegisterInviteCode(inviteCode)} /> From 742721b27b8d28d404fbae07c8dd8190ada606fe Mon Sep 17 00:00:00 2001 From: Dendi Date: Mon, 8 Apr 2024 20:58:45 +0800 Subject: [PATCH 2/6] fix: fix invite time format --- src/welcome/Wallet/InviteFriends.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/welcome/Wallet/InviteFriends.tsx b/src/welcome/Wallet/InviteFriends.tsx index 72dc9ad..2f6cbd3 100644 --- a/src/welcome/Wallet/InviteFriends.tsx +++ b/src/welcome/Wallet/InviteFriends.tsx @@ -8,6 +8,7 @@ import TableContainer from '@mui/material/TableContainer'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import { useToggle } from 'ahooks'; +import dayjs from 'dayjs'; import { BasicButton } from '../../components/Button'; import TableEmptyWidget from '../../components/Empty'; @@ -136,7 +137,7 @@ const InviteFriends = () => { {inviteInfo.items.map((row, i) => ( - {row.invitedAt} + {dayjs(row.invitedAt).format('YYYY/MM/DD HH:mm')} {row.invitedUsername} {row.points} From 4e8211629d1351c4dbbbc3c1769a81ef5207ae82 Mon Sep 17 00:00:00 2001 From: Dendi Date: Tue, 9 Apr 2024 18:18:04 +0800 Subject: [PATCH 3/6] fix: fix drawer width on resize --- src/content/drawer/index.tsx | 44 ++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/content/drawer/index.tsx b/src/content/drawer/index.tsx index b39c114..7013c07 100644 --- a/src/content/drawer/index.tsx +++ b/src/content/drawer/index.tsx @@ -34,22 +34,17 @@ import LogoButton from './logoButton'; import '../../tailwind.css'; -const drawerWidth = Math.max( - (window.innerWidth - XFANS_TWITTER_CONTENT_WIDTH) / 2 + XFANS_TWITTER_OFFSET, - XFANS_MIN_WIDTH -); -const backWidth = drawerWidth - XFANS_CONTENT_WIDTH; - const Main = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })<{ open?: boolean; -}>(({ theme, open }) => ({ + drawerWidth?: number; // 添加 width 参数 +}>(({ theme, open, drawerWidth }) => ({ // flexGrow: 1, // padding: theme.spacing(3), transition: theme.transitions.create('margin', { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen, }), - marginRight: -drawerWidth, + marginRight: -(drawerWidth || 0), ...(open && { transition: theme.transitions.create('margin', { easing: theme.transitions.easing.easeOut, @@ -83,8 +78,39 @@ export default function PersistentDrawerRight() { }); }; + const caculateDrawerWidth = () => { + return Math.max( + (window.innerWidth - XFANS_TWITTER_CONTENT_WIDTH) / 2 + XFANS_TWITTER_OFFSET, + XFANS_MIN_WIDTH + ); + }; + + const caculateBackWidth = () => { + return caculateDrawerWidth() - XFANS_CONTENT_WIDTH; + }; + const [pageState, setPageState] = React.useState('login'); + const [drawerWidth, setDrawerWidth] = React.useState(caculateDrawerWidth()); + + const [backWidth, setBackWidth] = React.useState(caculateBackWidth()); + + React.useEffect(() => { + function handleResize() { + // 当窗口大小变化时,更新 width 的值 + setBackWidth(caculateBackWidth()); + setDrawerWidth(caculateDrawerWidth()); + } + + // 添加窗口大小变化时的事件监听器 + window.addEventListener('resize', handleResize); + + // 在组件卸载时移除事件监听器 + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); + React.useEffect(() => { // 先检查是否需要展开 const loginState = localStorage.getItem('xfans-login-state'); @@ -200,7 +226,7 @@ export default function PersistentDrawerRight() { {/* */} -
+
Date: Tue, 9 Apr 2024 19:24:56 +0800 Subject: [PATCH 4/6] fix: update persist --- src/constants.ts | 6 -- src/content/drawer/index.tsx | 13 ++-- src/content/loginPage/congratulationPage.tsx | 72 +++++++++----------- src/store/useGlobalStore.ts | 8 +++ 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 32a22ab..6355196 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,12 +1,6 @@ export const XFANS_TWITTER_HOMEPAGE = 'https://twitter.com/BuidlerDAO'; export const XFANS_TWITTES = 'https://twitter.com/BuidlerDAO/status/1744712912537788860?xfans_check_retweet=1'; -export const LOCALSTORAGE_TRUE = 'true'; -export const LOCALSTORAGE_FALSE = 'false'; -export const XFANS_TWITTER_GO_FOLLOW = 'xfans-go-follow'; -export const XFANS_TWITTER_GO_FOLLOW_VERIFY = 'xfans-go-follow-verify'; -export const XFANS_TWITTER_GO_RETWEETS = 'xfans-go-retweets'; -export const XFANS_TWITTER_GO_RETWEETS_VERIFY = 'xfans-go-retweets-verify'; export const XFANS_CHECK_RETWEET = 'xfans_check_retweet'; export const XFANS_DONE = 'Done'; export const XFANS_VERIFY = 'Verify'; diff --git a/src/content/drawer/index.tsx b/src/content/drawer/index.tsx index a775bf6..42f0ed1 100644 --- a/src/content/drawer/index.tsx +++ b/src/content/drawer/index.tsx @@ -5,11 +5,6 @@ import Divider from '@mui/material/Divider'; import Drawer from '@mui/material/Drawer'; import IconButton from '@mui/material/IconButton'; import { styled } from '@mui/material/styles'; -import { - XFANS_TWITTER_GO_FOLLOW, - XFANS_TWITTER_GO_FOLLOW_VERIFY, - LOCALSTORAGE_FALSE, -} from '../../constants'; import * as toaster from '../../components/Toaster'; import { XFANS_CONTENT_WIDTH, @@ -87,8 +82,6 @@ export default function PersistentDrawerRight() { return caculateDrawerWidth() - XFANS_CONTENT_WIDTH; }; - const [pageState, setPageState] = React.useState('login'); - const [drawerWidth, setDrawerWidth] = React.useState(caculateDrawerWidth()); const [backWidth, setBackWidth] = React.useState(caculateBackWidth()); @@ -235,8 +228,10 @@ export default function PersistentDrawerRight() { showLoading={loginLoading} handleButtonClick={() => { // reset follow status - localStorage.setItem(XFANS_TWITTER_GO_FOLLOW, LOCALSTORAGE_FALSE); - localStorage.setItem(XFANS_TWITTER_GO_FOLLOW_VERIFY, LOCALSTORAGE_FALSE); + useGlobalStore.setState({ + isGoFollow: false, + isGoFollowVerify: false, + }); clickLogin(); }} /> diff --git a/src/content/loginPage/congratulationPage.tsx b/src/content/loginPage/congratulationPage.tsx index 77b8727..c5e54ca 100644 --- a/src/content/loginPage/congratulationPage.tsx +++ b/src/content/loginPage/congratulationPage.tsx @@ -3,20 +3,15 @@ import React, { FC, useEffect } from 'react'; import { NextButton, VerifyButton } from '../../components/buttons/loginButton'; import * as toaster from '../../components/Toaster'; import { - LOCALSTORAGE_FALSE, - LOCALSTORAGE_TRUE, XFANS_CHECK_RETWEET, XFANS_DONE, XFANS_GO, - XFANS_TWITTER_GO_FOLLOW, - XFANS_TWITTER_GO_FOLLOW_VERIFY, - XFANS_TWITTER_GO_RETWEETS, - XFANS_TWITTER_GO_RETWEETS_VERIFY, XFANS_TWITTER_HOMEPAGE, XFANS_TWITTES, XFANS_VERIFY, } from '../../constants'; import http, { ResultData } from '../../service/request'; +import useGlobalStore from '../../store/useGlobalStore'; import '../../tailwind.css'; interface CongratulationPageProps { @@ -24,32 +19,19 @@ interface CongratulationPageProps { } const CongratulationPage: FC = ({ goProfile }) => { - const [goFollow, setGoFollow] = React.useState( - localStorage.getItem(XFANS_TWITTER_GO_FOLLOW) ?? LOCALSTORAGE_FALSE - ); + const [goFollow, setGoFollow] = React.useState(useGlobalStore.getState().isGoFollow); const [goFollowVerify, setGoFollowVerify] = React.useState( - localStorage.getItem(XFANS_TWITTER_GO_FOLLOW_VERIFY ?? LOCALSTORAGE_FALSE) - ); - - const [goRetwittes, setGoRetwittes] = React.useState( - localStorage.getItem(XFANS_TWITTER_GO_RETWEETS) ?? LOCALSTORAGE_FALSE + useGlobalStore.getState().isGoFollowVerify ); + const [goRetwittes, setGoRetwittes] = React.useState(useGlobalStore.getState().isGoRetwittes); const [goRetwittesVerify, setGoRetwittesVerify] = React.useState( - localStorage.getItem(XFANS_TWITTER_GO_RETWEETS_VERIFY ?? LOCALSTORAGE_FALSE) + useGlobalStore.getState().isGoRetwittesVerify ); const followStatus = - goFollow === LOCALSTORAGE_TRUE - ? goFollowVerify === LOCALSTORAGE_TRUE - ? XFANS_DONE - : XFANS_VERIFY - : XFANS_GO; + goFollow === true ? (goFollowVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; const retweetStatus = - goRetwittes === LOCALSTORAGE_TRUE - ? goRetwittesVerify === LOCALSTORAGE_TRUE - ? XFANS_DONE - : XFANS_VERIFY - : XFANS_GO; + goRetwittes === true ? (goRetwittesVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; const startStatus = followStatus === XFANS_DONE && retweetStatus === XFANS_DONE; // 打开一个新的标签页并访问指定网页 @@ -58,14 +40,18 @@ const CongratulationPage: FC = ({ goProfile }) => { newTab?.focus(); }; - const _setGoRetwittesVerify = (r: string) => { + const _setGoRetwittesVerify = (r: boolean) => { setGoRetwittesVerify(r); - localStorage.setItem(XFANS_TWITTER_GO_RETWEETS_VERIFY, r); + useGlobalStore.setState({ + isGoRetwittesVerify: r, + }); }; - const _setGoRetwittes = (r: string) => { + const _setGoRetwittes = (r: boolean) => { setGoRetwittes(r); - localStorage.setItem(XFANS_TWITTER_GO_RETWEETS, r); + useGlobalStore.setState({ + isGoRetwittes: r, + }); }; // 再获取url中的token 作为第一优先级 @@ -76,22 +62,22 @@ const CongratulationPage: FC = ({ goProfile }) => { try { const activateData = (await http.post2(`api/user/activate/check-task`, false)) as ResultData; if (activateData.code === 0 && activateData.data.finished === true) { - _setGoRetwittesVerify(LOCALSTORAGE_TRUE); + _setGoRetwittesVerify(true); } else { if (!xfansCheckRetweet) { - _setGoRetwittes(LOCALSTORAGE_FALSE); + _setGoRetwittes(false); } else { - _setGoRetwittes(LOCALSTORAGE_TRUE); + _setGoRetwittes(true); } - _setGoRetwittesVerify(LOCALSTORAGE_FALSE); + _setGoRetwittesVerify(false); } } catch (error) { if (!xfansCheckRetweet) { - _setGoRetwittes(LOCALSTORAGE_FALSE); + _setGoRetwittes(false); } else { - _setGoRetwittes(LOCALSTORAGE_TRUE); + _setGoRetwittes(true); } - _setGoRetwittesVerify(LOCALSTORAGE_FALSE); + _setGoRetwittesVerify(false); } }; @@ -135,14 +121,18 @@ const CongratulationPage: FC = ({ goProfile }) => { switch (followStatus) { case XFANS_GO: openNewTab(XFANS_TWITTER_HOMEPAGE); - setGoFollow(LOCALSTORAGE_TRUE); - localStorage.setItem(XFANS_TWITTER_GO_FOLLOW, LOCALSTORAGE_TRUE); + setGoFollow(true); + useGlobalStore.setState({ + isGoFollow: true, + }); break; case XFANS_VERIFY: setTimeout(() => { - setGoFollowVerify(LOCALSTORAGE_TRUE); - localStorage.setItem(XFANS_TWITTER_GO_FOLLOW_VERIFY, LOCALSTORAGE_TRUE); + setGoFollowVerify(true); + useGlobalStore.setState({ + isGoFollowVerify: true, + }); }, 1000); break; @@ -178,7 +168,7 @@ const CongratulationPage: FC = ({ goProfile }) => { onClick={() => { switch (retweetStatus) { case XFANS_GO: - _setGoRetwittes(LOCALSTORAGE_TRUE); + _setGoRetwittes(true); openNewTab(XFANS_TWITTES); break; diff --git a/src/store/useGlobalStore.ts b/src/store/useGlobalStore.ts index aa27cbf..9d90b13 100644 --- a/src/store/useGlobalStore.ts +++ b/src/store/useGlobalStore.ts @@ -17,6 +17,10 @@ export interface GlobalStoreProps { token: string; isShowPrice: boolean; isShowDrawer: boolean; + isGoFollow: boolean; + isGoFollowVerify: boolean; + isGoRetwittes: boolean; + isGoRetwittesVerify: boolean; userInfo: UserInfo | null; goPage(page: PageType): void; logout(): void; @@ -30,6 +34,10 @@ const useGlobalStore = create()( isShowPrice: false, isShowDrawer: false, userInfo: null, + isGoFollow: false, + isGoFollowVerify: false, + isGoRetwittes: false, + isGoRetwittesVerify: false, goPage(page: PageType) { set({ page }); }, From 31283cc013ab3d537a12ddb388a4addb10fa8bea Mon Sep 17 00:00:00 2001 From: Dendi Date: Tue, 9 Apr 2024 19:26:53 +0800 Subject: [PATCH 5/6] fix: update text --- src/welcome/Profile/Reward.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/welcome/Profile/Reward.tsx b/src/welcome/Profile/Reward.tsx index 8a81887..113f7e2 100644 --- a/src/welcome/Profile/Reward.tsx +++ b/src/welcome/Profile/Reward.tsx @@ -188,9 +188,7 @@ const Reward = () => { ) : tweetList == null || tweetList.length === 0 ? (
-

- You haven't bought any shares yet. -

+

No records found.

) : (
    @@ -255,9 +253,7 @@ const Reward = () => { ) : tweetYourRank == null || tweetYourRank.length === 0 ? (
    -

    - No records found. Vote to join weekly rankings. -

    +

    No records found.

    ) : (
      From 41472be8d6f0e61448d43acb5884b8e9d818906a Mon Sep 17 00:00:00 2001 From: Dendi Date: Tue, 9 Apr 2024 19:42:38 +0800 Subject: [PATCH 6/6] fix: update status --- src/content/loginPage/congratulationPage.tsx | 63 ++++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/content/loginPage/congratulationPage.tsx b/src/content/loginPage/congratulationPage.tsx index c5e54ca..48bf679 100644 --- a/src/content/loginPage/congratulationPage.tsx +++ b/src/content/loginPage/congratulationPage.tsx @@ -19,19 +19,16 @@ interface CongratulationPageProps { } const CongratulationPage: FC = ({ goProfile }) => { - const [goFollow, setGoFollow] = React.useState(useGlobalStore.getState().isGoFollow); - const [goFollowVerify, setGoFollowVerify] = React.useState( - useGlobalStore.getState().isGoFollowVerify - ); - const [goRetwittes, setGoRetwittes] = React.useState(useGlobalStore.getState().isGoRetwittes); - const [goRetwittesVerify, setGoRetwittesVerify] = React.useState( - useGlobalStore.getState().isGoRetwittesVerify + const { isGoFollow, isGoFollowVerify, isGoRetwittes, isGoRetwittesVerify } = useGlobalStore( + (state) => ({ + ...state, + }) ); const followStatus = - goFollow === true ? (goFollowVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; + isGoFollow === true ? (isGoFollowVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; const retweetStatus = - goRetwittes === true ? (goRetwittesVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; + isGoRetwittes === true ? (isGoRetwittesVerify === true ? XFANS_DONE : XFANS_VERIFY) : XFANS_GO; const startStatus = followStatus === XFANS_DONE && retweetStatus === XFANS_DONE; // 打开一个新的标签页并访问指定网页 @@ -40,20 +37,6 @@ const CongratulationPage: FC = ({ goProfile }) => { newTab?.focus(); }; - const _setGoRetwittesVerify = (r: boolean) => { - setGoRetwittesVerify(r); - useGlobalStore.setState({ - isGoRetwittesVerify: r, - }); - }; - - const _setGoRetwittes = (r: boolean) => { - setGoRetwittes(r); - useGlobalStore.setState({ - isGoRetwittes: r, - }); - }; - // 再获取url中的token 作为第一优先级 const urlParams = new URLSearchParams(window.location.search); const xfansCheckRetweet = urlParams.get(XFANS_CHECK_RETWEET); @@ -62,22 +45,36 @@ const CongratulationPage: FC = ({ goProfile }) => { try { const activateData = (await http.post2(`api/user/activate/check-task`, false)) as ResultData; if (activateData.code === 0 && activateData.data.finished === true) { - _setGoRetwittesVerify(true); + useGlobalStore.setState({ + isGoRetwittesVerify: true, + }); } else { if (!xfansCheckRetweet) { - _setGoRetwittes(false); + useGlobalStore.setState({ + isGoRetwittes: false, + }); } else { - _setGoRetwittes(true); + useGlobalStore.setState({ + isGoRetwittes: true, + }); } - _setGoRetwittesVerify(false); + useGlobalStore.setState({ + isGoRetwittesVerify: false, + }); } } catch (error) { if (!xfansCheckRetweet) { - _setGoRetwittes(false); + useGlobalStore.setState({ + isGoRetwittes: false, + }); } else { - _setGoRetwittes(true); + useGlobalStore.setState({ + isGoRetwittes: true, + }); } - _setGoRetwittesVerify(false); + useGlobalStore.setState({ + isGoRetwittesVerify: false, + }); } }; @@ -121,7 +118,6 @@ const CongratulationPage: FC = ({ goProfile }) => { switch (followStatus) { case XFANS_GO: openNewTab(XFANS_TWITTER_HOMEPAGE); - setGoFollow(true); useGlobalStore.setState({ isGoFollow: true, }); @@ -129,7 +125,6 @@ const CongratulationPage: FC = ({ goProfile }) => { case XFANS_VERIFY: setTimeout(() => { - setGoFollowVerify(true); useGlobalStore.setState({ isGoFollowVerify: true, }); @@ -168,7 +163,9 @@ const CongratulationPage: FC = ({ goProfile }) => { onClick={() => { switch (retweetStatus) { case XFANS_GO: - _setGoRetwittes(true); + useGlobalStore.setState({ + isGoRetwittes: true, + }); openNewTab(XFANS_TWITTES); break;