mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
added lab sorting
This commit is contained in:
parent
566e1192cd
commit
948f3a7e04
7 changed files with 63 additions and 15 deletions
|
@ -1,6 +1,8 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
import { LabHeadItem } from '~/components/lab/LabHeadItem';
|
import { LabHeadItem } from '~/components/lab/LabHeadItem';
|
||||||
|
import { LabNodesSort } from '~/types/lab';
|
||||||
|
import { useLabContext } from '~/utils/context/LabContextProvider';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
@ -9,20 +11,28 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const LabHead: FC<IProps> = ({ isLoading }) => {
|
const LabHead: FC<IProps> = ({ isLoading }) => {
|
||||||
|
const { sort, setSort } = useLabContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
<div className={styles.group}>
|
<div className={styles.group}>
|
||||||
<LabHeadItem icon="recent" active isLoading={isLoading}>
|
<LabHeadItem
|
||||||
|
icon="recent"
|
||||||
|
active={sort === LabNodesSort.New}
|
||||||
|
isLoading={isLoading}
|
||||||
|
onClick={() => setSort(LabNodesSort.New)}
|
||||||
|
>
|
||||||
Свежие
|
Свежие
|
||||||
</LabHeadItem>
|
</LabHeadItem>
|
||||||
|
|
||||||
<LabHeadItem icon="hot" isLoading={isLoading}>
|
<LabHeadItem
|
||||||
|
icon="hot"
|
||||||
|
active={sort === LabNodesSort.Hot}
|
||||||
|
isLoading={isLoading}
|
||||||
|
onClick={() => setSort(LabNodesSort.Hot)}
|
||||||
|
>
|
||||||
Популярные
|
Популярные
|
||||||
</LabHeadItem>
|
</LabHeadItem>
|
||||||
|
|
||||||
<LabHeadItem icon="star_full" isLoading={isLoading}>
|
|
||||||
Важные
|
|
||||||
</LabHeadItem>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -12,12 +12,13 @@ interface IProps {
|
||||||
icon: string;
|
icon: string;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LabHeadItem: FC<IProps> = ({ icon, children, isLoading, active }) => {
|
const LabHeadItem: FC<IProps> = ({ icon, children, isLoading, active, onClick }) => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Group horizontal className={styles.item}>
|
<Group horizontal className={styles.item} key="loading">
|
||||||
<Placeholder width="32px" height={32} />
|
<Placeholder width="32px" height={32} />
|
||||||
<Placeholder width="96px" height={18} />
|
<Placeholder width="96px" height={18} />
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -25,7 +26,11 @@ const LabHeadItem: FC<IProps> = ({ icon, children, isLoading, active }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group horizontal className={classNames(styles.item, { [styles.active]: active })}>
|
<Group
|
||||||
|
horizontal
|
||||||
|
className={classNames(styles.item, { [styles.active]: active })}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
<Icon icon={icon} size={24} />
|
<Icon icon={icon} size={24} />
|
||||||
<span className={styles.text}>{children}</span>
|
<span className={styles.text}>{children}</span>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
@ -1,9 +1,25 @@
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { useGetLabNodes } from '~/hooks/lab/useGetLabNodes';
|
import { useGetLabNodes } from '~/hooks/lab/useGetLabNodes';
|
||||||
import { useGetLabStats } from '~/hooks/lab/useGetLabStats';
|
import { useGetLabStats } from '~/hooks/lab/useGetLabStats';
|
||||||
|
import { LabNodesSort } from '~/types/lab';
|
||||||
|
|
||||||
export const useLab = () => {
|
export const useLab = () => {
|
||||||
const { nodes, isLoading, loadMore, hasMore } = useGetLabNodes();
|
const [sort, setSort] = useState<LabNodesSort>(LabNodesSort.New);
|
||||||
|
|
||||||
|
const { nodes, isLoading, loadMore, hasMore } = useGetLabNodes(sort);
|
||||||
const { tags, heroes, updates, isLoading: isLoadingStats } = useGetLabStats();
|
const { tags, heroes, updates, isLoading: isLoadingStats } = useGetLabStats();
|
||||||
|
|
||||||
return { isLoading, nodes, hasMore, loadMore, tags, heroes, isLoadingStats, updates };
|
return {
|
||||||
|
isLoading,
|
||||||
|
nodes,
|
||||||
|
hasMore,
|
||||||
|
loadMore,
|
||||||
|
tags,
|
||||||
|
heroes,
|
||||||
|
isLoadingStats,
|
||||||
|
updates,
|
||||||
|
sort,
|
||||||
|
setSort,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
|
import { Superpower } from '~/components/boris/Superpower';
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { Sticky } from '~/components/containers/Sticky';
|
import { Sticky } from '~/components/containers/Sticky';
|
||||||
import { LabHead } from '~/components/lab/LabHead';
|
import { LabHead } from '~/components/lab/LabHead';
|
||||||
|
|
|
@ -49,6 +49,5 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.head {
|
.head {
|
||||||
padding: 0 $gap * 0.5;
|
padding: 0 $gap * 0.5 $gap * 0.5;
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { createContext, FC, useContext } from 'react';
|
import React, { createContext, FC, useContext } from 'react';
|
||||||
|
|
||||||
import { IFlowNode, ITag } from '~/types';
|
import { IFlowNode, ITag } from '~/types';
|
||||||
import { ILabNode } from '~/types/lab';
|
import { ILabNode, LabNodesSort } from '~/types/lab';
|
||||||
|
|
||||||
export interface LabContextProps {
|
export interface LabContextProps {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
@ -13,6 +13,8 @@ export interface LabContextProps {
|
||||||
heroes: IFlowNode[];
|
heroes: IFlowNode[];
|
||||||
isLoadingStats: boolean;
|
isLoadingStats: boolean;
|
||||||
updates: IFlowNode[];
|
updates: IFlowNode[];
|
||||||
|
sort: LabNodesSort;
|
||||||
|
setSort: (sort: LabNodesSort) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultValues: LabContextProps = {
|
const defaultValues: LabContextProps = {
|
||||||
|
@ -24,6 +26,8 @@ const defaultValues: LabContextProps = {
|
||||||
heroes: [],
|
heroes: [],
|
||||||
isLoadingStats: false,
|
isLoadingStats: false,
|
||||||
updates: [],
|
updates: [],
|
||||||
|
sort: LabNodesSort.New,
|
||||||
|
setSort: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const LabContext = createContext<LabContextProps>(defaultValues);
|
const LabContext = createContext<LabContextProps>(defaultValues);
|
||||||
|
|
|
@ -6,7 +6,18 @@ import { LabContextProvider } from '~/utils/context/LabContextProvider';
|
||||||
interface LabProviderProps {}
|
interface LabProviderProps {}
|
||||||
|
|
||||||
const LabProvider: FC<LabProviderProps> = ({ children }) => {
|
const LabProvider: FC<LabProviderProps> = ({ children }) => {
|
||||||
const { isLoading, nodes, loadMore, hasMore, tags, heroes, isLoadingStats, updates } = useLab();
|
const {
|
||||||
|
isLoading,
|
||||||
|
nodes,
|
||||||
|
loadMore,
|
||||||
|
hasMore,
|
||||||
|
tags,
|
||||||
|
heroes,
|
||||||
|
isLoadingStats,
|
||||||
|
updates,
|
||||||
|
sort,
|
||||||
|
setSort,
|
||||||
|
} = useLab();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LabContextProvider
|
<LabContextProvider
|
||||||
|
@ -18,6 +29,8 @@ const LabProvider: FC<LabProviderProps> = ({ children }) => {
|
||||||
heroes={heroes}
|
heroes={heroes}
|
||||||
isLoadingStats={isLoadingStats}
|
isLoadingStats={isLoadingStats}
|
||||||
updates={updates}
|
updates={updates}
|
||||||
|
sort={sort}
|
||||||
|
setSort={setSort}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</LabContextProvider>
|
</LabContextProvider>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue