mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
(nextjs) added SSR Loader
This commit is contained in:
parent
d7def635e3
commit
41b26e7d69
5 changed files with 79 additions and 1 deletions
22
src/components/common/LoadingProgress/index.tsx
Normal file
22
src/components/common/LoadingProgress/index.tsx
Normal file
|
@ -0,0 +1,22 @@
|
|||
import React, { Fragment, VFC } from 'react';
|
||||
|
||||
import { useSSRLoadingIndicator } from '~/hooks/dom/useSSRLoadingIndicator';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
interface LoadingProgressProps {}
|
||||
|
||||
const LoadingProgress: VFC<LoadingProgressProps> = () => {
|
||||
const shown = useSSRLoadingIndicator();
|
||||
|
||||
return shown ? (
|
||||
<>
|
||||
<div className={styles.loader} />
|
||||
<div className={styles.label}>Секундочку...</div>
|
||||
</>
|
||||
) : (
|
||||
<Fragment />
|
||||
);
|
||||
};
|
||||
|
||||
export { LoadingProgress };
|
38
src/components/common/LoadingProgress/styles.module.scss
Normal file
38
src/components/common/LoadingProgress/styles.module.scss
Normal file
|
@ -0,0 +1,38 @@
|
|||
@import "src/styles/variables";
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
background-position: 0 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: 100vw 0;
|
||||
}
|
||||
}
|
||||
|
||||
.loader {
|
||||
display: flex;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 4px;
|
||||
z-index: 100;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(90deg, $dark_blue, $soft_blue, $dark_blue);
|
||||
animation: spin infinite 1s linear;
|
||||
}
|
||||
|
||||
.label {
|
||||
position: fixed;
|
||||
top: $gap + 4px;
|
||||
left: 50%;
|
||||
font: $font_12_semibold;
|
||||
background: red;
|
||||
z-index: 100;
|
||||
transform: translate(-50%, 0);
|
||||
padding: 2px 10px;
|
||||
border-radius: 10px;
|
||||
background: $cyan_gradient;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import * as React from 'react';
|
||||
|
||||
import { LoadingProgress } from '~/components/common/LoadingProgress';
|
||||
import { Header } from '~/containers/main/Header';
|
||||
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
||||
|
||||
|
@ -10,6 +11,7 @@ export const MainLayout = ({ children }) => (
|
|||
<div className={styles.content}>
|
||||
<Header />
|
||||
{children}
|
||||
<LoadingProgress />
|
||||
<SidebarRouter />
|
||||
</div>
|
||||
</div>
|
||||
|
|
15
src/hooks/dom/useSSRLoadingIndicator.ts
Normal file
15
src/hooks/dom/useSSRLoadingIndicator.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
|
||||
import Router from 'next/router';
|
||||
|
||||
export const useSSRLoadingIndicator = () => {
|
||||
const [shown, setShown] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
Router.events.on('routeChangeStart', () => setShown(true));
|
||||
Router.events.on('routeChangeComplete', () => setShown(false));
|
||||
Router.events.on('routeChangeError', () => setShown(false));
|
||||
}, []);
|
||||
|
||||
return shown;
|
||||
};
|
|
@ -9,6 +9,7 @@ $orange: #ff7549;
|
|||
$grass: #41800d;
|
||||
$wisegreen: #007962;
|
||||
$lightgreen: lighten(adjust_hue($wisegreen, -30deg), 10%);
|
||||
$soft_blue: #3c75ff;
|
||||
|
||||
$primary: $red;
|
||||
$secondary: $wisegreen;
|
||||
|
@ -21,7 +22,7 @@ $green_gradient: linear-gradient(
|
|||
$wisegreen 150%
|
||||
);
|
||||
$purple_gradient: linear-gradient(170deg, $red, $dark_blue);
|
||||
$cyan_gradient: linear-gradient(260deg, #3c75ff -50%, #7b2653 150%);
|
||||
$cyan_gradient: linear-gradient(260deg, $soft_blue -50%, #7b2653 150%);
|
||||
|
||||
$red_gradient_alt: linear-gradient(170deg, #ff4545, #d2004c);
|
||||
$purple_gradient_alt: linear-gradient(90deg, #442294, #ff4545);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue