ente/src/pages/_app.tsx

281 lines
7.1 KiB
TypeScript
Raw Normal View History

import React, { useCallback, useEffect, useState } from 'react';
import styled, { createGlobalStyle } from 'styled-components';
2020-09-09 21:09:51 +00:00
import Navbar from 'components/Navbar';
import constants from 'utils/strings/constants';
2020-09-13 17:01:36 +00:00
import Spinner from 'react-bootstrap/Spinner';
import { clearKeys } from 'utils/storage/sessionStorage';
import { clearData, getData, LS_KEYS } from 'utils/storage/localStorage';
import { useRouter } from 'next/router';
2020-09-13 17:01:36 +00:00
import Container from 'components/Container';
2020-09-14 09:32:01 +00:00
import Head from 'next/head';
2020-09-20 15:18:35 +00:00
import 'bootstrap/dist/css/bootstrap.min.css';
import 'photoswipe/dist/photoswipe.css';
2020-11-20 08:47:20 +00:00
import localForage from 'localforage';
import UploadButton from 'pages/gallery/components/UploadButton';
import FullScreenDropZone from 'components/FullScreenDropZone';
import { useDropzone } from 'react-dropzone';
2020-11-20 08:47:20 +00:00
localForage.config({
2021-01-14 12:34:55 +00:00
driver: localForage.INDEXEDDB,
name: 'ente-files',
version: 1.0,
storeName: 'files',
2020-11-20 08:47:20 +00:00
});
2020-09-09 21:09:51 +00:00
const GlobalStyles = createGlobalStyle`
html, body {
padding: 0;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
height: 100%;
flex: 1;
display: flex;
flex-direction: column;
2021-02-15 12:42:03 +00:00
background-color: #191919;
2020-09-09 21:09:51 +00:00
}
#__next {
flex: 1;
display: flex;
flex-direction: column;
}
.material-icons {
vertical-align: middle;
margin: 8px;
}
2020-11-26 15:57:20 +00:00
.pswp__item video {
width: 100%;
height: 100%;
}
.video-loading {
width: 100%;
height: 100%;
position: relative;
}
.video-loading > img {
object-fit: contain;
width: 100%;
height: 100%;
}
.video-loading > div {
position: relative;
top: -50vh;
left: 50vw;
}
2020-09-09 21:09:51 +00:00
:root {
--primary: #e26f99,
};
2020-09-13 17:01:36 +00:00
svg {
fill: currentColor;
}
2020-10-03 14:21:56 +00:00
.pswp__img {
object-fit: contain;
}
2021-01-14 12:34:55 +00:00
.modal-90w{
width:90vw;
2021-02-15 13:19:59 +00:00
max-width:960px!important;
}
.modal .modal-header, .modal .modal-footer {
border-color: #444 !important;
}
.modal .modal-header .close {
color: #aaa;
text-shadow: none;
}
.modal .card {
2021-02-15 13:19:59 +00:00
background-color: #202020;
border: none;
color: #aaa;
}
.modal .card > div {
border-radius: 30px;
overflow: hidden;
margin: 0 0 5px 0;
2021-01-14 14:07:26 +00:00
}
2021-02-15 10:46:16 +00:00
.modal-content {
2021-02-15 13:19:59 +00:00
background-color:#202020 !important;
color:#aaa;
2021-01-14 12:34:55 +00:00
}
2021-02-15 08:14:33 +00:00
.download-btn{
margin-top:10px;
width: 25px;
height: 25px;
float: right;
background: url('/download_icon.png') no-repeat;
cursor: pointer;
background-size: cover;
border: none;
2021-02-17 09:09:43 +00:00
}
.btn-primary {
2021-02-15 10:46:16 +00:00
background: #2dc262;
2021-02-15 11:34:11 +00:00
border-color: #29a354;
2021-02-15 10:46:16 +00:00
}
.btn-primary:hover {
background-color: #29a354;
2021-02-15 11:34:11 +00:00
border-color: #2dc262;
2021-02-15 10:46:16 +00:00
}
.btn-primary:disabled {
background-color: #69b383;
}
2021-02-15 12:42:03 +00:00
.card {
background-color: #242424;
color: #fff;
border-radius: 12px;
2021-02-15 08:14:33 +00:00
}
2021-03-09 07:41:52 +00:00
.jumbotron{
2021-03-09 10:36:23 +00:00
background-color: #191919;
2021-03-09 07:41:52 +00:00
color: #fff;
2021-03-09 10:36:23 +00:00
text-align: center;
margin-top: 50px;
}
.alert-success {
background-color: #c4ffd6;
}
.alert-primary {
background-color: #c4ffd6;
2021-03-09 07:41:52 +00:00
}
2021-03-11 14:13:36 +00:00
.ente-modal{
2021-03-11 13:36:54 +00:00
width: 500px;
max-width:100%;
}
.bm-burger-button {
position: fixed;
width: 36px;
height: 30px;
left: 36px;
top: 25px;
}
.bm-burger-bars {
background: #fff;
}
.bm-menu {
background: #373a47;
padding: 2.5em 1.5em 0;
font-size: 1.15em;
color:#fff
}
.bm-cross {
background: #fff;
}
2020-09-09 21:09:51 +00:00
`;
const Image = styled.img`
max-height: 28px;
margin-right: 5px;
2020-09-09 21:09:51 +00:00
`;
const FlexContainer = styled.div`
flex: 1;
2021-02-15 09:21:52 +00:00
text-align: center;
margin: 16px;
`;
2020-09-09 21:09:51 +00:00
export default function App({ Component, pageProps }) {
2021-01-14 12:34:55 +00:00
const router = useRouter();
const [user, setUser] = useState();
const [loading, setLoading] = useState(false);
const [uploadButtonView, setUploadButtonView] = useState(false);
const [uploadModalView, setUploadModalView] = useState(false);
2021-02-27 11:01:25 +00:00
function closeUploadModal() {
setUploadModalView(false);
}
function showUploadModal() {
setUploadModalView(true);
}
2021-01-14 12:34:55 +00:00
useEffect(() => {
const user = getData(LS_KEYS.USER);
setUser(user);
console.log(
`%c${constants.CONSOLE_WARNING_STOP}`,
'color: red; font-size: 52px;'
);
console.log(`%c${constants.CONSOLE_WARNING_DESC}`, 'font-size: 20px;');
router.events.on('routeChangeStart', (url: string) => {
if (window.location.pathname !== url.split('?')[0]) {
setLoading(true);
}
});
router.events.on('routeChangeComplete', () => {
const user = getData(LS_KEYS.USER);
setUser(user);
setLoading(false);
});
}, []);
const logout = async () => {
clearKeys();
clearData();
setUploadButtonView(false);
localForage.clear();
const cache = await caches.delete('thumbs');
router.push('/');
};
const onDropAccepted = useCallback(() => {
showUploadModal();
2021-03-11 13:29:55 +00:00
setIsDragActive(false);
}, []);
2021-03-11 13:29:55 +00:00
const { getRootProps, getInputProps, open, acceptedFiles } = useDropzone({
noClick: true,
noKeyboard: true,
onDropAccepted,
});
2021-03-11 13:29:55 +00:00
const [isDragActive, setIsDragActive] = useState(false);
const onDragEnter = () => setIsDragActive(true);
const onDragLeave = () => setIsDragActive(false);
2021-01-14 12:34:55 +00:00
return (
<FullScreenDropZone
getRootProps={getRootProps}
getInputProps={getInputProps}
isDragActive={isDragActive}
2021-03-11 13:29:55 +00:00
onDragEnter={onDragEnter}
onDragLeave={onDragLeave}
logout={logout}
>
2021-01-19 03:41:56 +00:00
<Head>
2021-02-27 11:01:25 +00:00
<title>{constants.TITLE}</title>
<script async src={`https://sa.ente.io/latest.js`} />
2021-01-19 03:41:56 +00:00
</Head>
<GlobalStyles />
<Navbar>
<FlexContainer>
2021-03-09 07:41:52 +00:00
<Image
style={{ height: '24px' }}
alt="logo"
src="/icon.svg"
/>
2021-01-19 03:41:56 +00:00
</FlexContainer>
{uploadButtonView && <UploadButton openFileUploader={open} />}
2021-01-19 03:41:56 +00:00
</Navbar>
{loading ? (
<Container>
<Spinner animation="border" role="status" variant="primary">
<span className="sr-only">Loading...</span>
2021-01-19 03:41:56 +00:00
</Spinner>
</Container>
) : (
<Component
openFileUploader={open}
acceptedFiles={acceptedFiles}
uploadModalView={uploadModalView}
showUploadModal={showUploadModal}
closeUploadModal={closeUploadModal}
setUploadButtonView={setUploadButtonView}
/>
)}
2021-01-19 03:41:56 +00:00
</FullScreenDropZone>
2020-09-09 21:09:51 +00:00
);
}