mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-05-05 01:27:46 +07:00
removed redux completely
This commit is contained in:
parent
26e6d8d41b
commit
a4bb07e9cf
323 changed files with 2464 additions and 3348 deletions
|
@ -3,9 +3,9 @@ import { GetLabNodesRequest, ILabNode } from '~/types/lab';
|
|||
import { getLabNodes } from '~/api/lab';
|
||||
import { flatten, last, uniqBy } from 'ramda';
|
||||
import { useLabStore } from '~/store/lab/useLabStore';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { INode } from '~/redux/types';
|
||||
import { useUser } from '~/hooks/user/userUser';
|
||||
import { useCallback } from 'react';
|
||||
import { INode } from '~/types';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
|
||||
const getKey: (isUser: boolean) => SWRInfiniteKeyLoader = isUser => (index, prev: ILabNode[]) => {
|
||||
if (!isUser) return null;
|
||||
|
@ -33,10 +33,10 @@ const parseKey = (key: string): GetLabNodesRequest => {
|
|||
|
||||
export const useGetLabNodes = () => {
|
||||
const labStore = useLabStore();
|
||||
const { is_user } = useUser();
|
||||
const { isUser } = useAuth();
|
||||
|
||||
const { data, isValidating, size, setSize, mutate } = useSWRInfinite(
|
||||
getKey(is_user),
|
||||
getKey(isUser),
|
||||
async (key: string) => {
|
||||
const result = await getLabNodes(parseKey(key));
|
||||
return result.nodes;
|
||||
|
@ -71,14 +71,5 @@ export const useGetLabNodes = () => {
|
|||
[data, mutate]
|
||||
);
|
||||
|
||||
/** purge cache on exit */
|
||||
useEffect(() => {
|
||||
if (is_user) {
|
||||
return;
|
||||
}
|
||||
|
||||
labStore.setNodes([]);
|
||||
}, [is_user, labStore]);
|
||||
|
||||
return { nodes, isLoading: !data && isValidating, hasMore, loadMore, unshift, updateNode };
|
||||
};
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue