mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added dynamic routes
This commit is contained in:
parent
8c17c02b3e
commit
0a1d2cbf99
16 changed files with 143 additions and 89 deletions
|
@ -79,10 +79,10 @@
|
||||||
"@next/bundle-analyzer": "^12.0.8",
|
"@next/bundle-analyzer": "^12.0.8",
|
||||||
"@next/eslint-plugin-next": "^12.0.8",
|
"@next/eslint-plugin-next": "^12.0.8",
|
||||||
"@types/marked": "^4.0.1",
|
"@types/marked": "^4.0.1",
|
||||||
"@types/react-router-dom": "^5.1.7",
|
|
||||||
"@types/react": "^17.0.2",
|
|
||||||
"@types/node": "^11.13.22",
|
"@types/node": "^11.13.22",
|
||||||
"@types/ramda": "^0.26.33",
|
"@types/ramda": "^0.26.33",
|
||||||
|
"@types/react": "^17.0.2",
|
||||||
|
"@types/react-router-dom": "^5.1.7",
|
||||||
"@types/throttle-debounce": "^2.1.0",
|
"@types/throttle-debounce": "^2.1.0",
|
||||||
"@types/yup": "^0.29.11",
|
"@types/yup": "^0.29.11",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
||||||
|
|
|
@ -8,12 +8,11 @@ import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
export interface SubmitBarProps {
|
||||||
interface Props {
|
|
||||||
isLab?: boolean;
|
isLab?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SubmitBar: FC<Props> = ({ isLab }) => {
|
const SubmitBar: FC<SubmitBarProps> = ({ isLab }) => {
|
||||||
const showModal = useShowModal(Dialog.CreateNode);
|
const showModal = useShowModal(Dialog.CreateNode);
|
||||||
const [focused, setFocused] = useState(false);
|
const [focused, setFocused] = useState(false);
|
||||||
|
|
||||||
|
|
7
src/components/bars/SubmitBar/ssr.ts
Normal file
7
src/components/bars/SubmitBar/ssr.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
|
import type { SubmitBarProps } from './index';
|
||||||
|
|
||||||
|
export const SubmitBarSSR = dynamic<SubmitBarProps>(
|
||||||
|
() => import('./index').then(it => it.SubmitBar),
|
||||||
|
{ ssr: false });
|
|
@ -5,7 +5,7 @@ import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
||||||
import { IComment } from '~/types';
|
import { IComment } from '~/types';
|
||||||
import { IUser } from '~/types/auth';
|
import { IUser } from '~/types/auth';
|
||||||
|
|
||||||
interface NodeCommentFormProps {
|
export interface NodeCommentFormProps {
|
||||||
user: IUser;
|
user: IUser;
|
||||||
nodeId?: number;
|
nodeId?: number;
|
||||||
saveComment: (comment: IComment) => Promise<unknown>;
|
saveComment: (comment: IComment) => Promise<unknown>;
|
||||||
|
|
8
src/components/node/NodeCommentForm/ssr.ts
Normal file
8
src/components/node/NodeCommentForm/ssr.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
|
import type { NodeCommentFormProps } from './index';
|
||||||
|
|
||||||
|
export const NodeCommentFormSSR = dynamic<NodeCommentFormProps>(
|
||||||
|
() => import('./index').then(it => it.NodeCommentForm),
|
||||||
|
{ ssr: false }
|
||||||
|
);
|
|
@ -2,7 +2,7 @@ import React, { FC } from 'react';
|
||||||
|
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { Footer } from '~/components/main/Footer';
|
import { Footer } from '~/components/main/Footer';
|
||||||
import { NodeCommentForm } from '~/components/node/NodeCommentForm';
|
import { NodeCommentFormSSR } from '~/components/node/NodeCommentForm/ssr';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { isSSR } from '~/constants/ssr';
|
import { isSSR } from '~/constants/ssr';
|
||||||
import { NodeComments } from '~/containers/node/NodeComments';
|
import { NodeComments } from '~/containers/node/NodeComments';
|
||||||
|
@ -40,7 +40,7 @@ const BorisComments: FC<IProps> = () => {
|
||||||
>
|
>
|
||||||
<Group>
|
<Group>
|
||||||
{(isUser || isSSR) && (
|
{(isUser || isSSR) && (
|
||||||
<NodeCommentForm user={user} nodeId={node.id} saveComment={onSaveComment} />
|
<NodeCommentFormSSR user={user} nodeId={node.id} saveComment={onSaveComment} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isLoading || !comments?.length ? (
|
{isLoading || !comments?.length ? (
|
||||||
|
|
|
@ -10,9 +10,7 @@ import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
interface BorisSuperpowersProps { }
|
export interface BorisSuperpowersProps {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const BorisSuperpowers: FC<BorisSuperpowersProps> = () => {
|
const BorisSuperpowers: FC<BorisSuperpowersProps> = () => {
|
||||||
const openProfileSidebar = useShowModal(Dialog.ProfileSidebar);
|
const openProfileSidebar = useShowModal(Dialog.ProfileSidebar);
|
||||||
|
@ -23,14 +21,18 @@ const BorisSuperpowers: FC<BorisSuperpowersProps> = () => {
|
||||||
<h2>Штучи, находящиеся в разработке</h2>
|
<h2>Штучи, находящиеся в разработке</h2>
|
||||||
|
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
<Button size="mini" onClick={() => openProfileSidebar({})}>Открыть</Button>
|
<Button size="mini" onClick={() => openProfileSidebar({})}>
|
||||||
|
Открыть
|
||||||
|
</Button>
|
||||||
<div className={styles.label}>Профиль в сайдбаре</div>
|
<div className={styles.label}>Профиль в сайдбаре</div>
|
||||||
|
|
||||||
<Button size="mini" onClick={() => push(URLS.SETTINGS.BASE)}>Открыть</Button>
|
<Button size="mini" onClick={() => push(URLS.SETTINGS.BASE)}>
|
||||||
|
Открыть
|
||||||
|
</Button>
|
||||||
<div className={styles.label}>Профиль на отдельной странице</div>
|
<div className={styles.label}>Профиль на отдельной странице</div>
|
||||||
</div>
|
</div>
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default BorisSuperpowers;
|
export { BorisSuperpowers };
|
||||||
|
|
12
src/containers/boris/BorisSuperpowers/ssr.tsx
Normal file
12
src/containers/boris/BorisSuperpowers/ssr.tsx
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
|
import type { BorisSuperpowersProps } from './index';
|
||||||
|
|
||||||
|
export const BorisSuperPowersSSR = dynamic<BorisSuperpowersProps>(
|
||||||
|
() => import('~/containers/boris/BorisSuperpowers/index')
|
||||||
|
.then(it => it.BorisSuperpowers),
|
||||||
|
{
|
||||||
|
ssr: false,
|
||||||
|
loading: () => <div />,
|
||||||
|
}
|
||||||
|
);
|
|
@ -21,7 +21,7 @@ import { useUpdates } from '~/hooks/updates/useUpdates';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
type HeaderProps = {};
|
export interface HeaderProps {}
|
||||||
|
|
||||||
const Header: FC<HeaderProps> = observer(() => {
|
const Header: FC<HeaderProps> = observer(() => {
|
||||||
const labStats = useGetLabStats();
|
const labStats = useGetLabStats();
|
||||||
|
|
12
src/containers/main/Header/ssr.tsx
Normal file
12
src/containers/main/Header/ssr.tsx
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
|
import type { HeaderProps } from '~/containers/main/Header/index';
|
||||||
|
|
||||||
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
export const HeaderSSR = dynamic<HeaderProps>(() => import('./index').then(it => it.Header), {
|
||||||
|
ssr: false,
|
||||||
|
loading: () => <div className={styles.wrap} />,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const HeaderSSRPlaceholder = () => <div className={styles.wrap} />;
|
|
@ -1,5 +1,16 @@
|
||||||
@import "../../../styles/variables";
|
@import "../../../styles/variables";
|
||||||
|
|
||||||
|
@keyframes appear {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translate(0, -$header_height);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translate(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.wrap {
|
.wrap {
|
||||||
height: $header_height;
|
height: $header_height;
|
||||||
z-index: 25;
|
z-index: 25;
|
||||||
|
@ -10,7 +21,8 @@
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
transition: background-color 0.5s;
|
transition: background-color 0.75s;
|
||||||
|
animation: appear 500ms forwards;
|
||||||
|
|
||||||
@include desktop {
|
@include desktop {
|
||||||
height: 64px;
|
height: 64px;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
import { SubmitBar } from '~/components/bars/SubmitBar';
|
import { SubmitBarSSR } from '~/components/bars/SubmitBar/ssr';
|
||||||
import { Authorized } from '~/components/containers/Authorized';
|
import { Authorized } from '~/components/containers/Authorized';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
|
@ -10,7 +10,7 @@ interface IProps {
|
||||||
|
|
||||||
const SidebarRouter: FC<IProps> = ({ isLab }) => (
|
const SidebarRouter: FC<IProps> = ({ isLab }) => (
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<SubmitBar isLab={isLab} />
|
<SubmitBarSSR isLab={isLab} />
|
||||||
</Authorized>
|
</Authorized>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Group } from '~/components/containers/Group';
|
||||||
import { Padder } from '~/components/containers/Padder';
|
import { Padder } from '~/components/containers/Padder';
|
||||||
import { Sticky } from '~/components/containers/Sticky';
|
import { Sticky } from '~/components/containers/Sticky';
|
||||||
import { NodeAuthorBlock } from '~/components/node/NodeAuthorBlock';
|
import { NodeAuthorBlock } from '~/components/node/NodeAuthorBlock';
|
||||||
import { NodeCommentForm } from '~/components/node/NodeCommentForm';
|
import { NodeCommentFormSSR } from '~/components/node/NodeCommentForm/ssr';
|
||||||
import { NodeDeletedBadge } from '~/components/node/NodeDeletedBadge';
|
import { NodeDeletedBadge } from '~/components/node/NodeDeletedBadge';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
||||||
|
@ -51,7 +51,7 @@ const NodeBottomBlock: FC<IProps> = ({ commentsOrder }) => {
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
{isUser && !isLoading && (
|
{isUser && !isLoading && (
|
||||||
<NodeCommentForm nodeId={node.id} saveComment={onSaveComment} user={user} />
|
<NodeCommentFormSSR nodeId={node.id} saveComment={onSaveComment} user={user} />
|
||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { FC, Suspense, useMemo } from 'react';
|
import { FC, useMemo } from 'react';
|
||||||
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import dynamic from 'next/dynamic';
|
|
||||||
|
|
||||||
import { BorisGraphicStats } from '~/components/boris/BorisGraphicStats';
|
import { BorisGraphicStats } from '~/components/boris/BorisGraphicStats';
|
||||||
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
||||||
|
@ -10,6 +9,7 @@ import { Card } from '~/components/containers/Card';
|
||||||
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 { BorisComments } from '~/containers/boris/BorisComments';
|
import { BorisComments } from '~/containers/boris/BorisComments';
|
||||||
|
import { BorisSuperPowersSSR } from '~/containers/boris/BorisSuperpowers/ssr';
|
||||||
import { Container } from '~/containers/main/Container';
|
import { Container } from '~/containers/main/Container';
|
||||||
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
||||||
import { BorisUsageStats } from '~/types/boris';
|
import { BorisUsageStats } from '~/types/boris';
|
||||||
|
@ -25,14 +25,15 @@ type IProps = {
|
||||||
isLoadingStats: boolean;
|
isLoadingStats: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BorisSuperPowers = dynamic(() => import('~/containers/boris/BorisSuperpowers/index'), {
|
const BorisLayout: FC<IProps> = observer(
|
||||||
ssr: false,
|
({ title, setIsBetaTester, isTester, stats, isLoadingStats }) => {
|
||||||
})
|
|
||||||
|
|
||||||
const BorisLayout: FC<IProps> = observer(({ title, setIsBetaTester, isTester, stats, isLoadingStats }) => {
|
|
||||||
const { isUser } = useAuthProvider();
|
const { isUser } = useAuthProvider();
|
||||||
const commentsByMonth = useMemo(() => stats.backend.comments.by_month?.slice(0, -1), [stats.backend.comments.by_month]);
|
const commentsByMonth = useMemo(() => stats.backend.comments.by_month?.slice(0, -1), [
|
||||||
const nodesByMonth = useMemo(() => stats.backend.nodes.by_month?.slice(0, -1), [stats.backend.comments.by_month]);
|
stats.backend.comments.by_month,
|
||||||
|
]);
|
||||||
|
const nodesByMonth = useMemo(() => stats.backend.nodes.by_month?.slice(0, -1), [
|
||||||
|
stats.backend.comments.by_month,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -51,9 +52,7 @@ const BorisLayout: FC<IProps> = observer(({ title, setIsBetaTester, isTester, st
|
||||||
<Card className={styles.content}>
|
<Card className={styles.content}>
|
||||||
<Group>
|
<Group>
|
||||||
<Superpower>
|
<Superpower>
|
||||||
<Suspense fallback={<div />}>
|
<BorisSuperPowersSSR />
|
||||||
<BorisSuperPowers />
|
|
||||||
</Suspense>
|
|
||||||
</Superpower>
|
</Superpower>
|
||||||
|
|
||||||
<BorisGraphicStats
|
<BorisGraphicStats
|
||||||
|
@ -84,6 +83,7 @@ const BorisLayout: FC<IProps> = observer(({ title, setIsBetaTester, isTester, st
|
||||||
<SidebarRouter prefix="/" />
|
<SidebarRouter prefix="/" />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export { BorisLayout };
|
export { BorisLayout };
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { LoadingProgress } from '~/components/common/LoadingProgress';
|
import { LoadingProgress } from '~/components/common/LoadingProgress';
|
||||||
import { Header } from '~/containers/main/Header';
|
import { HeaderSSR } from '~/containers/main/Header/ssr';
|
||||||
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
@ -9,8 +9,10 @@ import styles from './styles.module.scss';
|
||||||
export const MainLayout = ({ children }) => (
|
export const MainLayout = ({ children }) => (
|
||||||
<div className={styles.wrapper}>
|
<div className={styles.wrapper}>
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<Header />
|
<HeaderSSR />
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
|
|
||||||
<LoadingProgress />
|
<LoadingProgress />
|
||||||
<SidebarRouter />
|
<SidebarRouter />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -742,9 +742,9 @@ callsites@^3.0.0:
|
||||||
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
|
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
|
||||||
|
|
||||||
caniuse-lite@^1.0.30001283:
|
caniuse-lite@^1.0.30001283:
|
||||||
version "1.0.30001303"
|
version "1.0.30001367"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001303.tgz#9b168e4f43ccfc372b86f4bc5a551d9b909c95c9"
|
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001367.tgz"
|
||||||
integrity sha512-/Mqc1oESndUNszJP0kx0UaQU9kEv9nNtJ7Kn8AdA0mNnH8eR1cj0kG+NbNuC1Wq/b21eA8prhKRA3bbkjONegQ==
|
integrity sha512-XDgbeOHfifWV3GEES2B8rtsrADx4Jf+juKX2SICJcaUhjYBO3bR96kvEIHa15VU6ohtOhBZuPGGYGbXMRn0NCw==
|
||||||
|
|
||||||
chalk@^2.0.0:
|
chalk@^2.0.0:
|
||||||
version "2.4.2"
|
version "2.4.2"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue