1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

removed redux completely

This commit is contained in:
Fedor Katurov 2022-01-09 19:03:01 +07:00
parent 26e6d8d41b
commit a4bb07e9cf
323 changed files with 2464 additions and 3348 deletions

View file

@ -2,17 +2,17 @@ import useSWR from 'swr';
import { API } from '~/constants/api';
import { getLabStats, getLabUpdates } from '~/api/lab';
import { useLabStore } from '~/store/lab/useLabStore';
import { useCallback, useEffect } from 'react';
import { useUser } from '~/hooks/user/userUser';
import { useCallback, useMemo } from 'react';
import { useAuth } from '~/hooks/auth/useAuth';
const refreshInterval = 1000 * 60 * 5; // 5 minutes
export const useGetLabStats = () => {
const lab = useLabStore();
const { is_user } = useUser();
const { isUser } = useAuth();
const { data: stats, isValidating: isValidatingStats } = useSWR(
is_user ? API.LAB.STATS : null,
isUser ? API.LAB.STATS : null,
async () => getLabStats(),
{
fallbackData: {
@ -28,7 +28,7 @@ export const useGetLabStats = () => {
);
const { data: updatesData, isValidating: isValidatingUpdates, mutate: mutateUpdates } = useSWR(
is_user ? API.LAB.UPDATES : null,
isUser ? API.LAB.UPDATES : null,
async () => {
const result = await getLabUpdates();
return result.nodes;
@ -42,9 +42,9 @@ export const useGetLabStats = () => {
}
);
const heroes = stats?.heroes || [];
const tags = stats?.tags || [];
const updates = updatesData || [];
const heroes = useMemo(() => stats?.heroes || [], [stats]);
const tags = useMemo(() => stats?.tags || [], [stats]);
const updates = useMemo(() => updatesData || [], [updatesData]);
const isLoading = (!stats || !updates) && (isValidatingStats || isValidatingUpdates);
const seenNode = useCallback(
@ -57,16 +57,5 @@ export const useGetLabStats = () => {
[mutateUpdates, updates]
);
/** purge cache on exit */
useEffect(() => {
if (is_user) {
return;
}
lab.setHeroes([]);
lab.setTags([]);
lab.setUpdates([]);
}, [is_user, lab]);
return { heroes, tags, updates, isLoading, seenNode };
};