From 494c36ecfc75be46fba30c0090e7add5978b986b Mon Sep 17 00:00:00 2001 From: Rushikesh Tote Date: Sun, 3 Apr 2022 13:03:42 +0530 Subject: [PATCH] refactor empty screen --- src/components/EmptyScreen.tsx | 54 ++++++++++++++++++++++++++++ src/components/PhotoFrame.tsx | 47 ++---------------------- src/pages/gallery/index.tsx | 2 +- src/services/deduplicationService.ts | 2 +- 4 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 src/components/EmptyScreen.tsx diff --git a/src/components/EmptyScreen.tsx b/src/components/EmptyScreen.tsx new file mode 100644 index 000000000..bc39642f5 --- /dev/null +++ b/src/components/EmptyScreen.tsx @@ -0,0 +1,54 @@ +import React, { useContext } from 'react'; +import { Button } from 'react-bootstrap'; +import styled from 'styled-components'; +import constants from 'utils/strings/constants'; +import { GalleryContext } from 'pages/gallery'; + +const Wrapper = styled.div` + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + flex: 1; + color: #51cd7c; + + & > svg { + filter: drop-shadow(3px 3px 5px rgba(45, 194, 98, 0.5)); + } +`; + +export default function EmptyScreen({ openFileUploader }) { + const galleryContext = useContext(GalleryContext); + return ( + + {galleryContext.isDeduplicating ? ( + + {constants.NO_DUPLICATES_FOUND} + + ) : ( + <> + +
+ {constants.UPLOAD_FIRST_PHOTO_DESCRIPTION} +
+ + + )} +
+ ); +} diff --git a/src/components/PhotoFrame.tsx b/src/components/PhotoFrame.tsx index cbebbc66f..effc3eb7f 100644 --- a/src/components/PhotoFrame.tsx +++ b/src/components/PhotoFrame.tsx @@ -1,7 +1,6 @@ import { GalleryContext } from 'pages/gallery'; import PreviewCard from './pages/gallery/PreviewCard'; import React, { useContext, useEffect, useRef, useState } from 'react'; -import { Button } from 'react-bootstrap'; import { EnteFile } from 'types/file'; import styled from 'styled-components'; import DownloadManager from 'services/downloadManager'; @@ -23,6 +22,7 @@ import { FILE_TYPE } from 'constants/file'; import PublicCollectionDownloadManager from 'services/publicCollectionDownloadManager'; import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery'; import { useRouter } from 'next/router'; +import EmptyScreen from './EmptyScreen'; const Container = styled.div` display: block; @@ -37,19 +37,6 @@ const Container = styled.div` } `; -const EmptyScreen = styled.div` - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - flex: 1; - color: #51cd7c; - - & > svg { - filter: drop-shadow(3px 3px 5px rgba(45, 194, 98, 0.5)); - } -`; - const PHOTOSWIPE_HASH_SUFFIX = '&opened'; interface Props { @@ -547,37 +534,7 @@ const PhotoFrame = ({ return ( <> {!isFirstLoad && files.length === 0 && !isInSearchMode ? ( - - {galleryContext.isDeduplicating ? ( - - {constants.NO_DUPLICATES_FOUND} - - ) : ( - <> - -
- {constants.UPLOAD_FIRST_PHOTO_DESCRIPTION} -
- - - )} -
+ ) : ( diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 1e9706cec..acfe0a3d6 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -261,7 +261,7 @@ export default function Gallery() { startLoading(); let duplicates = await getDuplicateFiles(); if (clubSameTimeFilesOnly) { - duplicates = await clubDuplicatesByTime(duplicates); + duplicates = clubDuplicatesByTime(duplicates); } const currFileSizeMap = new Map(); diff --git a/src/services/deduplicationService.ts b/src/services/deduplicationService.ts index e13aaac28..f539c1e69 100644 --- a/src/services/deduplicationService.ts +++ b/src/services/deduplicationService.ts @@ -53,7 +53,7 @@ export async function getDuplicateFiles() { } } -export async function clubDuplicatesByTime(dupes: DuplicateFiles[]) { +export function clubDuplicatesByTime(dupes: DuplicateFiles[]) { const result: DuplicateFiles[] = []; for (const dupe of dupes) { let files: EnteFile[] = [];