Skip to content

Commit

Permalink
Merge pull request #121 from BuidlerDAO/NIG-706
Browse files Browse the repository at this point in the history
feat: voting function Local
  • Loading branch information
hujie123456 authored Apr 16, 2024
2 parents 8b70d5d + 11813c0 commit 8fe7d36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/components/twitterAdded/feedsPage/voteIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dayjs from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween';

import { useTweetBatchUserInfo, useTweetVote } from '../../../service/tweet';
import useGlobalStore from '../../../store/useGlobalStore';
import useTweetStore from '../../../store/useTweetStore';
import * as toaster from '../../Toaster';

Expand All @@ -17,7 +18,8 @@ interface VoteTwitterProps {
}

export const VoteTwitter: FC<VoteTwitterProps> = ({ twitterId, userName, time }) => {
const [voted, setVoted] = useState(false);
// const [voted, setVoted] = useState(false);
const { userVote } = useGlobalStore((state) => ({ ...state }));
const [userInfo, setUserInfo] = useState<any>(null);
const ref = useRef<HTMLDivElement | null>(null);
const { run: batchUserInfo } = useTweetBatchUserInfo(
Expand All @@ -31,11 +33,22 @@ export const VoteTwitter: FC<VoteTwitterProps> = ({ twitterId, userName, time })
twitterId,
userName,
() => {
setVoted(true);
// setVoted(true);
useGlobalStore.setState({
userVote: {
...userVote,
[twitterId]: true,
},
});
toaster.success(toaster.ToastMessage.VOTE_SUCCESS);
},
() => {
setVoted(false);
useGlobalStore.setState({
userVote: {
...userVote,
[twitterId]: false,
},
});
toaster.success(toaster.ToastMessage.VOTE_FAILED);
}
);
Expand All @@ -61,7 +74,7 @@ export const VoteTwitter: FC<VoteTwitterProps> = ({ twitterId, userName, time })
e.stopPropagation();
}}
>
{voted || isHover ? <VoidedIcon /> : <VoidIcon />}
{userVote?.[twitterId] || isHover ? <VoidedIcon /> : <VoidIcon />}
</div>
) : null}
</>
Expand Down
2 changes: 2 additions & 0 deletions src/store/useGlobalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface GlobalStoreProps {
userInfo: UserInfo | null;
goPage(page: PageType): void;
logout(): void;
userVote: Record<string, boolean> | null;
}

const useGlobalStore = create<GlobalStoreProps>()(
Expand All @@ -47,6 +48,7 @@ const useGlobalStore = create<GlobalStoreProps>()(
page: PageType.Login,
});
},
userVote: null,
}),
{
name: 'xfans-user-config',
Expand Down

0 comments on commit 8fe7d36

Please sign in to comment.