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

added fluid lab

This commit is contained in:
Fedor Katurov 2021-06-30 14:43:45 +07:00
parent 7ce8939dce
commit 5bdfeb6ce4
7 changed files with 107 additions and 18 deletions

View file

@ -25,6 +25,7 @@
"ramda": "^0.26.1", "ramda": "^0.26.1",
"react": "^17.0.1", "react": "^17.0.1",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"react-masonry-css": "^1.0.16",
"react-popper": "^2.2.3", "react-popper": "^2.2.3",
"react-redux": "^7.2.2", "react-redux": "^7.2.2",
"react-router": "^5.1.2", "react-router": "^5.1.2",

View file

@ -9,6 +9,7 @@ import { Icon } from '~/components/input/Icon';
import { Group } from '~/components/containers/Group'; import { Group } from '~/components/containers/Group';
import { Toggle } from '~/components/input/Toggle'; import { Toggle } from '~/components/input/Toggle';
import classNames from 'classnames'; import classNames from 'classnames';
import { Superpower } from '~/components/boris/Superpower';
interface IProps { interface IProps {
recent: IFlowState['recent']; recent: IFlowState['recent'];
@ -93,12 +94,14 @@ const FlowStamp: FC<IProps> = ({
)} )}
</div> </div>
<Superpower>
<div className={styles.toggles}> <div className={styles.toggles}>
<Group horizontal onClick={toggleLayout} className={styles.fluid_toggle}> <Group horizontal onClick={toggleLayout} className={styles.fluid_toggle}>
<Toggle value={isFluid} /> <Toggle value={isFluid} />
<div className={styles.toggles__label}>Жидкое течение</div> <div className={styles.toggles__label}>Жидкое течение</div>
</Group> </Group>
</div> </div>
</Superpower>
</div> </div>
); );
}; };

View file

@ -1,4 +1,5 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import Masonry from 'react-masonry-css';
import { useShallowSelect } from '~/utils/hooks/useShallowSelect'; import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { LabNode } from '~/components/lab/LabNode'; import { LabNode } from '~/components/lab/LabNode';
@ -6,7 +7,15 @@ import { selectLabList, selectLabListNodes } from '~/redux/lab/selectors';
import { EMPTY_NODE, NODE_TYPES } from '~/redux/node/constants'; import { EMPTY_NODE, NODE_TYPES } from '~/redux/node/constants';
import { values } from 'ramda'; import { values } from 'ramda';
interface IProps {} interface IProps {
isFluid: boolean;
}
const breakpointColumnsObj = {
default: 3,
1100: 2,
700: 1,
};
const getRandomNodeType = () => const getRandomNodeType = () =>
values(NODE_TYPES)[Math.floor(Math.random() * values(NODE_TYPES).length)]; values(NODE_TYPES)[Math.floor(Math.random() * values(NODE_TYPES).length)];
@ -20,7 +29,7 @@ const LoadingNode = () => (
/> />
); );
const LabGrid: FC<IProps> = () => { const LabGrid: FC<IProps> = ({ isFluid }) => {
const nodes = useShallowSelect(selectLabListNodes); const nodes = useShallowSelect(selectLabListNodes);
const { is_loading } = useShallowSelect(selectLabList); const { is_loading } = useShallowSelect(selectLabList);
@ -36,7 +45,11 @@ const LabGrid: FC<IProps> = () => {
} }
return ( return (
<div className={styles.wrap}> <Masonry
className={styles.wrap}
breakpointCols={isFluid ? breakpointColumnsObj : 1}
columnClassName={styles.column}
>
{nodes.map(node => ( {nodes.map(node => (
<LabNode <LabNode
node={node.node} node={node.node}
@ -45,7 +58,7 @@ const LabGrid: FC<IProps> = () => {
commentCount={node.comment_count} commentCount={node.comment_count}
/> />
))} ))}
</div> </Masonry>
); );
}; };

View file

@ -1,8 +1,21 @@
@import "~/styles/variables.scss"; @import "~/styles/variables.scss";
$gutter: $gap * 2;
.wrap { .wrap {
display: grid; display: -webkit-box; /* Not needed if autoprefixing */
grid-auto-flow: row; display: -ms-flexbox; /* Not needed if autoprefixing */
grid-auto-rows: auto; display: flex;
grid-row-gap: $gap * 2; width: 100%;
position: relative;
left: -$gutter;
}
.column {
padding-left: $gutter; /* gutter size */
background-clip: padding-box;
& > div {
margin-bottom: $gutter;
}
} }

View file

@ -1,4 +1,4 @@
import React, { FC, useEffect } from 'react'; import React, { FC, useCallback, useEffect } from 'react';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { Sticky } from '~/components/containers/Sticky'; import { Sticky } from '~/components/containers/Sticky';
import { Container } from '~/containers/main/Container'; import { Container } from '~/containers/main/Container';
@ -11,12 +11,27 @@ import { LabStats } from '~/containers/lab/LabStats';
import { useShallowSelect } from '~/utils/hooks/useShallowSelect'; import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
import { selectLabList } from '~/redux/lab/selectors'; import { selectLabList } from '~/redux/lab/selectors';
import { SidebarRouter } from '~/containers/main/SidebarRouter'; import { SidebarRouter } from '~/containers/main/SidebarRouter';
import { Superpower } from '~/components/boris/Superpower';
import { Toggle } from '~/components/input/Toggle';
import { usePersistedState } from '~/utils/hooks/usePersistedState';
import classNames from 'classnames';
interface IProps {} interface IProps {}
enum Layout {
Fluid = 'fluid',
Default = 'default',
}
const LabLayout: FC<IProps> = () => { const LabLayout: FC<IProps> = () => {
const { is_loading } = useShallowSelect(selectLabList); const { is_loading } = useShallowSelect(selectLabList);
const dispatch = useDispatch(); const dispatch = useDispatch();
const [layout, setLayout] = usePersistedState('lab_layout', Layout.Default);
const isFluid = layout === Layout.Fluid;
const toggleLayout = useCallback(() => {
setLayout(isFluid ? Layout.Default : Layout.Fluid);
}, [setLayout, isFluid]);
useEffect(() => { useEffect(() => {
dispatch(labGetList()); dispatch(labGetList());
@ -25,20 +40,29 @@ const LabLayout: FC<IProps> = () => {
return ( return (
<div> <div>
<Container> <div className={classNames(styles.container, { [styles.fluid]: isFluid })}>
<div className={styles.wrap}> <div className={styles.wrap}>
<Group className={styles.content}> <Group className={styles.content}>
<LabHead isLoading={is_loading} /> <LabHead isLoading={is_loading} />
<LabGrid /> <LabGrid isFluid={isFluid} />
</Group> </Group>
<div className={styles.panel}> <div className={styles.panel}>
<Sticky> <Sticky>
<LabStats /> <LabStats />
<Superpower>
<div className={styles.toggles}>
<Group horizontal onClick={toggleLayout} className={styles.fluid_toggle}>
<Toggle value={isFluid} />
<div className={styles.toggles__label}>Жидкая лаборатория</div>
</Group>
</div>
</Superpower>
</Sticky> </Sticky>
</div> </div>
</div> </div>
</Container> </div>
<SidebarRouter prefix="/lab" isLab /> <SidebarRouter prefix="/lab" isLab />
</div> </div>

View file

@ -1,5 +1,13 @@
@import "~/styles/variables.scss"; @import "~/styles/variables.scss";
@mixin fluid {
@media(min-width: $content_width) {
.fluid & {
@content
}
}
}
.wrap { .wrap {
display: grid; display: grid;
grid-template-columns: 3fr 1fr; grid-template-columns: 3fr 1fr;
@ -10,6 +18,11 @@
grid-auto-flow: row; grid-auto-flow: row;
padding: 0 $gap / 2; padding: 0 $gap / 2;
} }
@include fluid {
grid-template-columns: 3fr $cell;
padding: 0 $gap;
}
} }
.panel { .panel {
@ -24,3 +37,20 @@
margin: 0 $gap $gap 0; margin: 0 $gap $gap 0;
} }
} }
.toggles {
padding: $gap;
}
.container {
width: 100%;
max-width: $content_width;
&.fluid {
max-width: 100vw;
}
}
.content {
min-width: 0;
}

View file

@ -9386,6 +9386,11 @@ react-is@^17.0.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339"
integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA== integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA==
react-masonry-css@^1.0.16:
version "1.0.16"
resolved "https://registry.yarnpkg.com/react-masonry-css/-/react-masonry-css-1.0.16.tgz#72b28b4ae3484e250534700860597553a10f1a2c"
integrity sha512-KSW0hR2VQmltt/qAa3eXOctQDyOu7+ZBevtKgpNDSzT7k5LA/0XntNa9z9HKCdz3QlxmJHglTZ18e4sX4V8zZQ==
react-popper@^2.2.3: react-popper@^2.2.3:
version "2.2.4" version "2.2.4"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-2.2.4.tgz#d2ad3d2474ac9f1abf93df3099d408e5aa6a2e22" resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-2.2.4.tgz#d2ad3d2474ac9f1abf93df3099d408e5aa6a2e22"