mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
removed redux completely
This commit is contained in:
parent
26e6d8d41b
commit
a4bb07e9cf
323 changed files with 2464 additions and 3348 deletions
|
@ -1,17 +1,16 @@
|
|||
import { useDispatch } from 'react-redux';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import isBefore from 'date-fns/isBefore';
|
||||
import { authSetState, authSetUser } from '~/redux/auth/actions';
|
||||
import { useUser } from '~/hooks/user/userUser';
|
||||
import { IComment } from '~/redux/types';
|
||||
import { useShallowSelect } from '~/hooks/data/useShallowSelect';
|
||||
import { selectAuthIsTester } from '~/redux/auth/selectors';
|
||||
import { IComment } from '~/types';
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
import { useBorisStats } from '~/hooks/boris/useBorisStats';
|
||||
import { useLastSeenBoris } from '~/hooks/auth/useLastSeenBoris';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
|
||||
export const useBoris = (comments: IComment[]) => {
|
||||
const dispatch = useDispatch();
|
||||
const user = useUser();
|
||||
const title = useRandomPhrase('BORIS_TITLE');
|
||||
|
||||
const { lastSeen, setLastSeen } = useLastSeenBoris();
|
||||
const { isTester, setIsTester } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
const last_comment = comments[0];
|
||||
|
@ -19,26 +18,24 @@ export const useBoris = (comments: IComment[]) => {
|
|||
if (!last_comment) return;
|
||||
|
||||
if (
|
||||
user.last_seen_boris &&
|
||||
last_comment.created_at &&
|
||||
!isBefore(new Date(user.last_seen_boris), new Date(last_comment.created_at))
|
||||
)
|
||||
!last_comment.created_at ||
|
||||
!lastSeen ||
|
||||
isBefore(new Date(lastSeen), new Date(last_comment.created_at))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(authSetUser({ last_seen_boris: last_comment.created_at }));
|
||||
}, [user.last_seen_boris, dispatch, comments]);
|
||||
void setLastSeen(last_comment.created_at);
|
||||
}, [lastSeen, setLastSeen, comments]);
|
||||
|
||||
const { stats, isLoading: isLoadingStats } = useBorisStats();
|
||||
|
||||
const setIsBetaTester = useCallback(
|
||||
(is_tester: boolean) => {
|
||||
dispatch(authSetState({ is_tester }));
|
||||
(isTester: boolean) => {
|
||||
setIsTester(isTester);
|
||||
},
|
||||
[dispatch]
|
||||
[setIsTester]
|
||||
);
|
||||
|
||||
const isTester = useShallowSelect(selectAuthIsTester);
|
||||
const title = useRandomPhrase('BORIS_TITLE');
|
||||
|
||||
return { setIsBetaTester, isTester, stats, title, isLoadingStats };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue