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

made lab use provider and context

This commit is contained in:
Fedor Katurov 2021-11-22 16:24:46 +07:00
parent cb314e9f8d
commit 96f1529f2b
9 changed files with 129 additions and 56 deletions

View file

@ -4,14 +4,10 @@ import styles from './styles.module.scss';
import { LabNode } from '~/components/lab/LabNode';
import { EMPTY_NODE, NODE_TYPES } from '~/redux/node/constants';
import { values } from 'ramda';
import { ILabNode } from '~/redux/lab/types';
import { useLabPagination } from '~/utils/hooks/lab/useLabPagination';
import { useLabContext } from '~/utils/context/LabContextProvider';
interface IProps {
isLoading: boolean;
nodes: ILabNode[];
onLoadMore: () => void;
}
interface IProps {}
const breakpointCols = {
default: 2,
@ -30,7 +26,9 @@ const LoadingNode = () => (
/>
);
const LabGrid: FC<IProps> = ({ isLoading, nodes, onLoadMore }) => {
const LabGrid: FC<IProps> = () => {
const { isLoading, nodes, onLoadMore } = useLabContext();
const columns = useMemo(() => Array.from(document.querySelectorAll(`.${styles.column}`)), []);
useLabPagination(isLoading, columns, onLoadMore);

View file

@ -2,25 +2,16 @@ import React, { FC } from 'react';
import styles from './styles.module.scss';
import { LabBanner } from '~/components/lab/LabBanner';
import { Group } from '~/components/containers/Group';
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
import {
selectLabStatsHeroes,
selectLabStatsLoading,
selectLabStatsTags,
selectLabUpdatesNodes
} from '~/redux/lab/selectors';
import { LabTags } from '~/components/lab/LabTags';
import { LabHeroes } from '~/components/lab/LabHeroes';
import { FlowRecentItem } from '~/components/flow/FlowRecentItem';
import { SubTitle } from '~/components/common/SubTitle';
import { useLabContext } from '~/utils/context/LabContextProvider';
interface IProps {}
const LabStats: FC<IProps> = () => {
const tags = useShallowSelect(selectLabStatsTags);
const heroes = useShallowSelect(selectLabStatsHeroes);
const isLoading = useShallowSelect(selectLabStatsLoading);
const updates = useShallowSelect(selectLabUpdatesNodes);
const { isLoadingStats, tags, heroes, updates } = useLabContext();
return (
<Group>
@ -28,14 +19,14 @@ const LabStats: FC<IProps> = () => {
<div className={styles.card}>
<Group>
{(!!tags.length || isLoading) && (
<SubTitle isLoading={isLoading} className={styles.title}>
{(!!tags.length || isLoadingStats) && (
<SubTitle isLoading={isLoadingStats} className={styles.title}>
Тэги
</SubTitle>
)}
<div className={styles.tags}>
<LabTags tags={tags} isLoading={isLoading} />
<LabTags tags={tags} isLoading={isLoadingStats} />
</div>
<div />
@ -53,14 +44,14 @@ const LabStats: FC<IProps> = () => {
</>
)}
{(!!heroes.length || isLoading) && (
<SubTitle isLoading={isLoading} className={styles.title}>
{(!!heroes.length || isLoadingStats) && (
<SubTitle isLoading={isLoadingStats} className={styles.title}>
Важные
</SubTitle>
)}
<div className={styles.heroes}>
<LabHeroes nodes={heroes} isLoading={isLoading} />
<LabHeroes nodes={heroes} isLoading={isLoadingStats} />
</div>
</Group>
</div>

View file

@ -2,13 +2,13 @@ import React, { FC } from 'react';
import { URLS } from '~/constants/urls';
import { ErrorNotFound } from '~/containers/pages/ErrorNotFound';
import { Redirect, Route, Switch, useLocation } from 'react-router';
import { LabLayout } from '~/layouts/LabLayout';
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
import { selectAuthUser } from '~/redux/auth/selectors';
import { ProfileLayout } from '~/layouts/ProfileLayout';
import FlowPage from '~/pages';
import BorisPage from '~/pages/boris';
import NodePage from '~/pages/node/[id]';
import LabPage from '~/pages/lab';
interface IProps {}
@ -23,7 +23,7 @@ const MainRouter: FC<IProps> = () => {
<Route path={URLS.ERRORS.NOT_FOUND} component={ErrorNotFound} />
<Route path={URLS.PROFILE_PAGE(':username')} component={ProfileLayout} />
{is_user && <Route path={URLS.LAB} component={LabLayout} />}
{is_user && <Route path={URLS.LAB} component={LabPage} />}
<Route path={URLS.BASE} component={FlowPage} />
<Redirect to="/" />