1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

removed boris reducer

This commit is contained in:
Fedor Katurov 2022-01-02 21:28:31 +07:00
parent 77af1ab05a
commit 120bf8954c
72 changed files with 225 additions and 298 deletions

View file

@ -2,13 +2,12 @@ import { useDispatch } from 'react-redux';
import { useCallback, useEffect } from 'react';
import isBefore from 'date-fns/isBefore';
import { authSetState, authSetUser } from '~/redux/auth/actions';
import { borisLoadStats } from '~/redux/boris/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 { selectBorisStats } from '~/redux/boris/selectors';
import { useRandomPhrase } from '~/constants/phrases';
import { useBorisStats } from '~/hooks/boris/useBorisStats';
export const useBoris = (comments: IComment[]) => {
const dispatch = useDispatch();
@ -29,9 +28,7 @@ export const useBoris = (comments: IComment[]) => {
dispatch(authSetUser({ last_seen_boris: last_comment.created_at }));
}, [user.last_seen_boris, dispatch, comments]);
useEffect(() => {
dispatch(borisLoadStats());
}, [dispatch]);
const { stats, isLoading: isLoadingStats } = useBorisStats();
const setIsBetaTester = useCallback(
(is_tester: boolean) => {
@ -41,8 +38,7 @@ export const useBoris = (comments: IComment[]) => {
);
const isTester = useShallowSelect(selectAuthIsTester);
const stats = useShallowSelect(selectBorisStats);
const title = useRandomPhrase('BORIS_TITLE');
return { setIsBetaTester, isTester, stats, title };
return { setIsBetaTester, isTester, stats, title, isLoadingStats };
};

View file

@ -0,0 +1,25 @@
import useSWR from 'swr';
import { API } from '~/constants/api';
import { getBorisBackendStats, getGithubIssues } from '~/api/boris';
import { BorisUsageStats } from '~/types/boris';
import { initialBackendStats } from '~/constants/boris/constants';
export const useBorisStats = () => {
const { data: backend = initialBackendStats, isValidating: isValidatingBackend } = useSWR(
API.BORIS.GET_BACKEND_STATS,
() => getBorisBackendStats()
);
const { data: issues = [], isValidating: isValidatingGit } = useSWR(API.BORIS.GITHUB_ISSUES, () =>
getGithubIssues()
);
const stats: BorisUsageStats = {
backend,
issues,
};
const isLoading = !backend && isValidatingBackend;
return { stats, isLoading };
};

View file

@ -3,8 +3,8 @@ import { IComment } from '~/redux/types';
import { API } from '~/constants/api';
import { flatten, isNil } from 'ramda';
import useSWRInfinite from 'swr/infinite';
import { apiGetNodeComments } from '~/redux/node/api';
import { COMMENTS_DISPLAY } from '~/redux/node/constants';
import { apiGetNodeComments } from '~/api/node';
import { COMMENTS_DISPLAY } from '~/constants/node';
import { useCallback } from 'react';
const getKey: (nodeId: number) => KeyLoader<IComment[]> = (nodeId: number) => (

View file

@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { IComment } from '~/redux/types';
import { useGetComments } from '~/hooks/comments/useGetComments';
import { apiLockComment, apiPostComment } from '~/redux/node/api';
import { apiLockComment, apiPostComment } from '~/api/node';
import { showErrorToast } from '~/utils/errors/showToast';
export const useNodeComments = (nodeId: number) => {

View file

@ -1,6 +1,6 @@
import { useCallback } from 'react';
import { INode } from '~/redux/types';
import { apiPostNode } from '~/redux/node/api';
import { apiPostNode } from '~/api/node';
import { selectFlowNodes } from '~/redux/flow/selectors';
import { flowSetNodes } from '~/redux/flow/actions';
import { selectLabListNodes } from '~/redux/lab/selectors';

View file

@ -1,9 +1,9 @@
import { INode } from '~/redux/types';
import useSWR from 'swr';
import { ApiGetNodeRelatedResult } from '~/redux/node/types';
import { ApiGetNodeRelatedResult } from '~/types/node';
import { API } from '~/constants/api';
import { useCallback } from 'react';
import { apiGetNodeRelated } from '~/redux/node/api';
import { apiGetNodeRelated } from '~/api/node';
export const useGetNodeRelated = (id?: INode['id']) => {
const { data, isValidating, mutate } = useSWR<ApiGetNodeRelatedResult>(API.NODE.RELATED(id), () =>

View file

@ -1,11 +1,11 @@
import useSWR from 'swr';
import { ApiGetNodeResponse } from '~/redux/node/types';
import { ApiGetNodeResponse } from '~/types/node';
import { API } from '~/constants/api';
import { useOnNodeSeen } from '~/hooks/node/useOnNodeSeen';
import { apiGetNode } from '~/redux/node/api';
import { apiGetNode } from '~/api/node';
import { useCallback } from 'react';
import { INode } from '~/redux/types';
import { EMPTY_NODE } from '~/redux/node/constants';
import { EMPTY_NODE } from '~/constants/node';
export const useLoadNode = (id: number) => {
const { data, isValidating, mutate } = useSWR<ApiGetNodeResponse>(API.NODE.GET_NODE(id), () =>

View file

@ -3,7 +3,7 @@ import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { modalShowDialog } from '~/redux/modal/actions';
import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs';
import { apiLockNode, apiPostNodeHeroic, apiPostNodeLike } from '~/redux/node/api';
import { apiLockNode, apiPostNodeHeroic, apiPostNodeLike } from '~/api/node';
import { showErrorToast } from '~/utils/errors/showToast';
export const useNodeActions = (node: INode, update: (node: Partial<INode>) => Promise<unknown>) => {

View file

@ -1,13 +1,7 @@
import { INode } from '~/redux/types';
import { createElement, FC, useCallback, useMemo } from 'react';
import { isNil, prop } from 'ramda';
import {
INodeComponentProps,
LAB_PREVIEW_LAYOUT,
NODE_COMPONENTS,
NODE_HEADS,
NODE_INLINES,
} from '~/redux/node/constants';
import { INodeComponentProps, LAB_PREVIEW_LAYOUT, NODE_COMPONENTS, NODE_HEADS, NODE_INLINES, } from '~/constants/node';
// useNodeBlocks returns head, block and inline blocks of node
export const useNodeBlocks = (node: INode, isLoading: boolean) => {

View file

@ -3,7 +3,7 @@ import { useCallback } from 'react';
import { ITag } from '~/redux/types';
import { URLS } from '~/constants/urls';
import { useLoadNode } from '~/hooks/node/useLoadNode';
import { apiDeleteNodeTag, apiPostNodeTags } from '~/redux/node/api';
import { apiDeleteNodeTag, apiPostNodeTags } from '~/api/node';
export const useNodeTags = (id: number) => {
const { update } = useLoadNode(id);

View file

@ -1,7 +1,7 @@
import { useLoadNode } from '~/hooks/node/useLoadNode';
import { useCallback } from 'react';
import { INode } from '~/redux/types';
import { apiPostNode } from '~/redux/node/api';
import { apiPostNode } from '~/api/node';
import { selectFlowNodes } from '~/redux/flow/selectors';
import { flowSetNodes } from '~/redux/flow/actions';
import { selectLabListNodes } from '~/redux/lab/selectors';