From 3291b2c005d2e6b32fdd4d429ab09df0ca7e0853 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 28 Jan 2022 13:50:00 +0530 Subject: [PATCH 01/15] fix laoder not working in gallery --- src/pages/gallery/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 1866af49f..7fc0b3552 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -178,7 +178,7 @@ export default function Gallery() { const loadingBar = useRef(null); const [isInSearchMode, setIsInSearchMode] = useState(false); const [searchStats, setSearchStats] = useState(null); - const isLoadingBarRunning = useRef(true); + const isLoadingBarRunning = useRef(false); const syncInProgress = useRef(true); const resync = useRef(false); const [deleted, setDeleted] = useState([]); From 7649ee18946bbcd210f4d627a97ef0577a5b14e1 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 28 Jan 2022 17:34:06 +0530 Subject: [PATCH 02/15] add dedupe logic before saving collection to localStorage --- src/services/publicCollectionService.ts | 56 ++++++++++++++++++------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 520b71e57..3f5b0013b 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -18,7 +18,7 @@ const ENDPOINT = getEndpoint(); const PUBLIC_COLLECTION_FILES_TABLE = 'public-collection-files'; const PUBLIC_COLLECTIONS_TABLE = 'public-collections'; -const getCollectionUID = (collection: Collection) => `${collection.id}`; +const getCollectionUID = (collection: Collection) => `${collection.key}`; export const getLocalPublicFiles = async (collectionUID: string) => { const localSavedPublicCollectionFiles = ( @@ -39,19 +39,21 @@ export const savePublicCollectionFiles = async ( (await localForage.getItem( PUBLIC_COLLECTION_FILES_TABLE )) ?? []; - await localForage.setItem(PUBLIC_COLLECTION_FILES_TABLE, [ - ...publicCollectionFiles, - { collectionUID, files }, - ]); + await localForage.setItem( + PUBLIC_COLLECTION_FILES_TABLE, + dedupeCollectionFiles([ + ...publicCollectionFiles, + { collectionUID, files }, + ]) + ); }; export const getLocalPublicCollection = async (collectionKey: string) => { + const localCollections = + (await localForage.getItem(PUBLIC_COLLECTIONS_TABLE)) ?? + []; const publicCollection = - ( - (await localForage.getItem( - PUBLIC_COLLECTIONS_TABLE - )) ?? [] - ).find( + localCollections.find( (localSavedPublicCollection) => localSavedPublicCollection.key === collectionKey ) || null; @@ -62,10 +64,36 @@ export const savePublicCollection = async (collection: Collection) => { const publicCollections = (await localForage.getItem(PUBLIC_COLLECTIONS_TABLE)) ?? []; - await localForage.setItem(PUBLIC_COLLECTIONS_TABLE, [ - ...publicCollections, - collection, - ]); + await localForage.setItem( + PUBLIC_COLLECTIONS_TABLE, + dedupeCollections([...publicCollections, collection]) + ); +}; + +const dedupeCollections = (collections: Collection[]) => { + const keySet = new Set([]); + return collections.filter((collection) => { + if (!keySet.has(collection.key)) { + keySet.add(collection.key); + return true; + } else { + return false; + } + }); +}; + +const dedupeCollectionFiles = ( + collectionFiles: LocalSavedPublicCollectionFiles[] +) => { + const keySet = new Set([]); + return collectionFiles.filter(({ collectionUID }) => { + if (!keySet.has(collectionUID)) { + keySet.add(collectionUID); + return true; + } else { + return false; + } + }); }; const getPublicCollectionLastSyncTime = async (collectionUID: string) => From 49869766d948b2ce0f35ea5f06752cd38a7f4ed4 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 28 Jan 2022 17:41:48 +0530 Subject: [PATCH 03/15] fix local file fetching --- src/pages/shared-albums/index.tsx | 6 ++---- src/services/publicCollectionService.ts | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pages/shared-albums/index.tsx b/src/pages/shared-albums/index.tsx index b515cd353..f4d5ca399 100644 --- a/src/pages/shared-albums/index.tsx +++ b/src/pages/shared-albums/index.tsx @@ -85,9 +85,7 @@ export default function PublicCollectionGallery() { if (localCollection) { setPublicCollection(localCollection); const localPublicFiles = sortFiles( - mergeMetadata( - await getLocalPublicFiles(`${localCollection.id}`) - ) + mergeMetadata(await getLocalPublicFiles(localCollection)) ); setPublicFiles(localPublicFiles); setLoading(false); @@ -154,7 +152,7 @@ export default function PublicCollectionGallery() { favItemIds={null} setSelected={() => null} selected={{ count: 0, collectionID: null }} - isFirstLoad={false} + isFirstLoad={true} openFileUploader={() => null} isInSearchMode={false} search={{}} diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 3f5b0013b..310fc785e 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -20,14 +20,15 @@ const PUBLIC_COLLECTIONS_TABLE = 'public-collections'; const getCollectionUID = (collection: Collection) => `${collection.key}`; -export const getLocalPublicFiles = async (collectionUID: string) => { +export const getLocalPublicFiles = async (collection: Collection) => { const localSavedPublicCollectionFiles = ( (await localForage.getItem( PUBLIC_COLLECTION_FILES_TABLE )) ?? [] ).find( (localSavedPublicCollectionFiles) => - localSavedPublicCollectionFiles.collectionUID === collectionUID + localSavedPublicCollectionFiles.collectionUID === + getCollectionUID(collection) ) || { collectionKey: null, files: [] as EnteFile[] }; return localSavedPublicCollectionFiles.files; }; @@ -111,9 +112,7 @@ export const syncPublicFiles = async ( ) => { try { let files: EnteFile[] = []; - const localFiles = await getLocalPublicFiles( - getCollectionUID(collection) - ); + const localFiles = await getLocalPublicFiles(collection); files.push(...localFiles); try { if (!token) { From 14516bb25264284484445281b74851e63f1364d1 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 28 Jan 2022 17:45:07 +0530 Subject: [PATCH 04/15] fix get local collection --- src/pages/shared-albums/index.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/shared-albums/index.tsx b/src/pages/shared-albums/index.tsx index f4d5ca399..3006165e8 100644 --- a/src/pages/shared-albums/index.tsx +++ b/src/pages/shared-albums/index.tsx @@ -68,19 +68,19 @@ export default function PublicCollectionGallery() { const main = async () => { const worker = await new CryptoWorker(); url.current = window.location.href; - const urlS = new URL(url.current); - const eToken = urlS.searchParams.get('t'); - const eCollectionKey = urlS.hash.slice(1); - const decodedCollectionKey = await worker.fromHex(eCollectionKey); - if (!eToken || !decodedCollectionKey) { + const currentURL = new URL(url.current); + const t = currentURL.searchParams.get('t'); + const ck = currentURL.hash.slice(1); + const dck = await worker.fromHex(ck); + if (!t || !dck) { setLoading(false); return; } - token.current = eToken; - collectionKey.current = decodedCollectionKey; + token.current = t; + collectionKey.current = dck; url.current = window.location.href; const localCollection = await getLocalPublicCollection( - eCollectionKey + collectionKey.current ); if (localCollection) { setPublicCollection(localCollection); From ac8ef83fcf6edc812b910ea57f074ae4409d90b2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 08:59:47 +0530 Subject: [PATCH 05/15] fix first load loading --- src/pages/shared-albums/index.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pages/shared-albums/index.tsx b/src/pages/shared-albums/index.tsx index 3006165e8..e57db52da 100644 --- a/src/pages/shared-albums/index.tsx +++ b/src/pages/shared-albums/index.tsx @@ -32,7 +32,7 @@ export default function PublicCollectionGallery() { const token = useRef(null); const collectionKey = useRef(null); const url = useRef(null); - const [publicFiles, setPublicFiles] = useState(null); + const [publicFiles, setPublicFiles] = useState([]); const [publicCollection, setPublicCollection] = useState(null); const appContext = useContext(AppContext); const [abuseReportFormView, setAbuseReportFormView] = useState(false); @@ -42,14 +42,23 @@ export default function PublicCollectionGallery() { const openReportForm = () => setAbuseReportFormView(true); const closeReportForm = () => setAbuseReportFormView(false); const loadingBar = useRef(null); + const [isLoadingBarRunning, setIsLoadingBarRunning] = useState(false); const openMessageDialog = () => setMessageDialogView(true); const closeMessageDialog = () => setMessageDialogView(false); - const startLoading = () => loadingBar.current?.continuousStart(); - const finishLoading = () => loadingBar.current?.complete(); + const startLoading = () => { + !isLoadingBarRunning && loadingBar.current?.continuousStart(); + setIsLoadingBarRunning(true); + }; + const finishLoading = () => { + loadingBar.current?.complete(); + setIsLoadingBarRunning(false); + }; useEffect(() => { + appContext.showNavBar(true); + setLoading(false); const currentURL = new URL(window.location.href); if (currentURL.pathname !== PAGES.ROOT) { router.push( @@ -88,10 +97,8 @@ export default function PublicCollectionGallery() { mergeMetadata(await getLocalPublicFiles(localCollection)) ); setPublicFiles(localPublicFiles); - setLoading(false); } syncWithRemote(); - appContext.showNavBar(true); }; main(); }, []); @@ -117,7 +124,6 @@ export default function PublicCollectionGallery() { setPublicFiles(null); } } finally { - setLoading(false); finishLoading(); } }; @@ -130,7 +136,7 @@ export default function PublicCollectionGallery() { ); } - if (!publicFiles) { + if (!isLoadingBarRunning && !publicFiles) { return {constants.NOT_FOUND}; } return ( From ba5431a7239c6bd68b433a3fc56f2a00279423db Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 09:13:07 +0530 Subject: [PATCH 06/15] fix cache errors --- src/services/publicCollectionDownloadManager.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/services/publicCollectionDownloadManager.ts b/src/services/publicCollectionDownloadManager.ts index c641da2d0..757059e73 100644 --- a/src/services/publicCollectionDownloadManager.ts +++ b/src/services/publicCollectionDownloadManager.ts @@ -25,8 +25,16 @@ class PublicCollectionDownloadManager { } if (!this.thumbnailObjectURLPromise.get(file.id)) { const downloadPromise = async () => { - const thumbnailCache = await caches.open('thumbs'); - const cacheResp: Response = await thumbnailCache.match( + const thumbnailCache = await (async () => { + try { + return await caches.open('thumbs'); + } catch (e) { + return null; + // ignore + } + })(); + + const cacheResp: Response = await thumbnailCache?.match( file.id.toString() ); if (cacheResp) { @@ -35,7 +43,7 @@ class PublicCollectionDownloadManager { const thumb = await this.downloadThumb(token, file); const thumbBlob = new Blob([thumb]); try { - await thumbnailCache.put( + await thumbnailCache?.put( file.id.toString(), new Response(thumbBlob) ); From 369887c3469fd5f076aa54daa546c1b97bc6fb7b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 09:32:45 +0530 Subject: [PATCH 07/15] changed ?? to || --- src/services/publicCollectionService.ts | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 310fc785e..0a45a4fd3 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -21,15 +21,20 @@ const PUBLIC_COLLECTIONS_TABLE = 'public-collections'; const getCollectionUID = (collection: Collection) => `${collection.key}`; export const getLocalPublicFiles = async (collection: Collection) => { - const localSavedPublicCollectionFiles = ( - (await localForage.getItem( - PUBLIC_COLLECTION_FILES_TABLE - )) ?? [] - ).find( - (localSavedPublicCollectionFiles) => - localSavedPublicCollectionFiles.collectionUID === - getCollectionUID(collection) - ) || { collectionKey: null, files: [] as EnteFile[] }; + const localSavedPublicCollectionFiles = + ( + (await localForage.getItem( + PUBLIC_COLLECTION_FILES_TABLE + )) || [] + ).find( + (localSavedPublicCollectionFiles) => + localSavedPublicCollectionFiles.collectionUID === + getCollectionUID(collection) + ) || + ({ + collectionUID: null, + files: [] as EnteFile[], + } as LocalSavedPublicCollectionFiles); return localSavedPublicCollectionFiles.files; }; export const savePublicCollectionFiles = async ( @@ -39,7 +44,7 @@ export const savePublicCollectionFiles = async ( const publicCollectionFiles = (await localForage.getItem( PUBLIC_COLLECTION_FILES_TABLE - )) ?? []; + )) || []; await localForage.setItem( PUBLIC_COLLECTION_FILES_TABLE, dedupeCollectionFiles([ @@ -51,7 +56,7 @@ export const savePublicCollectionFiles = async ( export const getLocalPublicCollection = async (collectionKey: string) => { const localCollections = - (await localForage.getItem(PUBLIC_COLLECTIONS_TABLE)) ?? + (await localForage.getItem(PUBLIC_COLLECTIONS_TABLE)) || []; const publicCollection = localCollections.find( From 0940d38f58c800e8af8f1b38e012b2908b6ea9e1 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 09:38:34 +0530 Subject: [PATCH 08/15] init localForage before redirecting --- src/pages/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index e1768b091..71c502fd6 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -137,7 +137,7 @@ export default function LandingPage() { hash: currentURL.hash, } ); - setLoading(false); + await initLocalForage(); }; const handleNormalRedirect = async () => { @@ -145,6 +145,10 @@ export default function LandingPage() { if (user?.email) { await router.push(PAGES.VERIFY); } + await initLocalForage(); + }; + + const initLocalForage = async () => { try { await localForage.ready(); } catch (e) { From ad3dc5d65fa1c65b06204df9f1da4b56635a5d85 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 10:59:45 +0530 Subject: [PATCH 09/15] update placeholder strings to have required star --- .../pages/sharedAlbum/AbuseReportForm.tsx | 4 +++- src/utils/strings/englishConstants.tsx | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/pages/sharedAlbum/AbuseReportForm.tsx b/src/components/pages/sharedAlbum/AbuseReportForm.tsx index c7ed8e749..e06008512 100644 --- a/src/components/pages/sharedAlbum/AbuseReportForm.tsx +++ b/src/components/pages/sharedAlbum/AbuseReportForm.tsx @@ -226,7 +226,9 @@ export function AbuseReportForm({ show, close, url }: Iprops) { ( <> By checking the following boxes, I state{' '} From 30aeef3231e01d64929cab6d2fef445dcc02ea86 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 11:30:47 +0530 Subject: [PATCH 10/15] style changes --- src/components/PhotoList.tsx | 5 +++-- src/components/pages/sharedAlbum/CollectionInfo.tsx | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/PhotoList.tsx b/src/components/PhotoList.tsx index 9ebc1186b..bc9c438bc 100644 --- a/src/components/PhotoList.tsx +++ b/src/components/PhotoList.tsx @@ -97,8 +97,9 @@ const BannerContainer = styled.div<{ span: number }>` `; const ReportAbuseItem = styled.div<{ span: number }>` - flex: 1; - text-align: right; + display: flex; + justify-content: center; + font-size: 14px; grid-column: span ${(props) => props.span}; & > p { margin: 0; diff --git a/src/components/pages/sharedAlbum/CollectionInfo.tsx b/src/components/pages/sharedAlbum/CollectionInfo.tsx index cbd7af195..0502203d5 100644 --- a/src/components/pages/sharedAlbum/CollectionInfo.tsx +++ b/src/components/pages/sharedAlbum/CollectionInfo.tsx @@ -7,9 +7,7 @@ interface Iprops { } const Info = styled.h5` - padding: 5px 24px; margin: 20px; - border-bottom: 2px solid #5a5858; `; export function CollectionInfo(props: Iprops) { From 499a256c49f4891ed8e90dfe8a3a725bbab2f433 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 11:36:10 +0530 Subject: [PATCH 11/15] update button style --- src/components/pages/sharedAlbum/GoToEnte.tsx | 3 ++- src/pages/_app.tsx | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/pages/sharedAlbum/GoToEnte.tsx b/src/components/pages/sharedAlbum/GoToEnte.tsx index f868de627..b83fd88f2 100644 --- a/src/components/pages/sharedAlbum/GoToEnte.tsx +++ b/src/components/pages/sharedAlbum/GoToEnte.tsx @@ -10,6 +10,7 @@ const Wrapper = styled.div` `; const NoStyleAnchor = styled.a` + color: inherit; text-decoration: none !important; &:hover { color: #fff !important; @@ -20,7 +21,7 @@ export const ButtonWithLink = ({ href, children, }: React.PropsWithChildren<{ href: string }>) => ( - ); diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 79f9c6b26..8ba8808a3 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -232,6 +232,17 @@ const GlobalStyles = createGlobalStyle` .btn-outline-danger, .btn-outline-secondary, .btn-outline-primary{ border-width: 2px; } + + #go-to-ente{ + background:none; + border-color: #3dbb69; + color:#51cd7c; + } + #go-to-ente:hover, #go-to-ente:focus, #go-to-ente:active { + color:#fff; + background-color: #44774d; + } + a { color: #fff; } From 08822f9963ca170075433a7d4e921dc8b297f4a5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 11:49:59 +0530 Subject: [PATCH 12/15] fix report item size --- src/components/PhotoList.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/PhotoList.tsx b/src/components/PhotoList.tsx index bc9c438bc..696883da8 100644 --- a/src/components/PhotoList.tsx +++ b/src/components/PhotoList.tsx @@ -99,7 +99,6 @@ const BannerContainer = styled.div<{ span: number }>` const ReportAbuseItem = styled.div<{ span: number }>` display: flex; justify-content: center; - font-size: 14px; grid-column: span ${(props) => props.span}; & > p { margin: 0; @@ -289,7 +288,7 @@ export function PhotoList({ item: ( {constants.ABUSE_REPORT_BUTTON_TEXT} From 674375848c8480a9b58115d3a4b14852b4a0fb50 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 12:19:29 +0530 Subject: [PATCH 13/15] setPublicShareUrl to null if collection url doesnt exist --- src/components/CollectionShare.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/CollectionShare.tsx b/src/components/CollectionShare.tsx index 73a4adceb..1390e7f51 100644 --- a/src/components/CollectionShare.tsx +++ b/src/components/CollectionShare.tsx @@ -52,6 +52,8 @@ function CollectionShare(props: Props) { props.collection.key ); setPublicShareUrl(t); + } else { + setPublicShareUrl(null); } }; main(); From d4264b9c06d4ceb17fa53b5fa3a9b696c294f021 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 12:33:56 +0530 Subject: [PATCH 14/15] get collection sync time UID --- src/services/publicCollectionService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 0a45a4fd3..721fb57ef 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -19,6 +19,8 @@ const PUBLIC_COLLECTION_FILES_TABLE = 'public-collection-files'; const PUBLIC_COLLECTIONS_TABLE = 'public-collections'; const getCollectionUID = (collection: Collection) => `${collection.key}`; +const getCollectionSyncTimeUID = (collectionUID: string) => + `public-${collectionUID}-time`; export const getLocalPublicFiles = async (collection: Collection) => { const localSavedPublicCollectionFiles = @@ -103,12 +105,14 @@ const dedupeCollectionFiles = ( }; const getPublicCollectionLastSyncTime = async (collectionUID: string) => - (await localForage.getItem(`public-${collectionUID}-time`)) ?? 0; + (await localForage.getItem( + getCollectionSyncTimeUID(collectionUID) + )) ?? 0; const setPublicCollectionLastSyncTime = async ( collectionUID: string, time: number -) => await localForage.setItem(collectionUID, time); +) => await localForage.setItem(getCollectionSyncTimeUID(collectionUID), time); export const syncPublicFiles = async ( token: string, From 3f3e65ad0322dcd5fdb0de0fe1be18a4c8943dc6 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 29 Jan 2022 12:42:28 +0530 Subject: [PATCH 15/15] fix dedupe --- src/services/publicCollectionService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 721fb57ef..33164c7bc 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -50,8 +50,8 @@ export const savePublicCollectionFiles = async ( await localForage.setItem( PUBLIC_COLLECTION_FILES_TABLE, dedupeCollectionFiles([ - ...publicCollectionFiles, { collectionUID, files }, + ...publicCollectionFiles, ]) ); }; @@ -74,7 +74,7 @@ export const savePublicCollection = async (collection: Collection) => { []; await localForage.setItem( PUBLIC_COLLECTIONS_TABLE, - dedupeCollections([...publicCollections, collection]) + dedupeCollections([collection, ...publicCollections]) ); };