diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 679beb2257833b27429501ce7055851db69cba6d..8ed08ecdec65f3bb4c94595dc6e18a290a426f15 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -6,7 +6,7 @@ import { file, getFile, getPreview, - fetchData, + syncData, localFiles, } from 'services/fileService'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; @@ -17,16 +17,16 @@ import PhotoSwipe from 'components/PhotoSwipe/PhotoSwipe'; import { Options } from 'photoswipe'; import AutoSizer from 'react-virtualized-auto-sizer'; import { VariableSizeList as List } from 'react-window'; -import LoadingBar from 'react-top-loading-bar' +import LoadingBar from 'react-top-loading-bar'; import Collections from './components/Collections'; import Upload from './components/Upload'; import { collection, - getLatestCollections, + syncCollections, collectionLatestFile, getCollectionLatestFile, getFavItemIds, - getLocalCollections + getLocalCollections, } from 'services/collectionService'; import constants from 'utils/strings/constants'; @@ -37,7 +37,7 @@ enum ITEM_TYPE { export enum FILE_TYPE { IMAGE, VIDEO, - OTHERS + OTHERS, } interface TimeStampListItem { @@ -75,9 +75,9 @@ const DeadCenter = styled.div` flex-direction: column; `; -const ListContainer = styled.div<{columns: number}>` +const ListContainer = styled.div<{ columns: number }>` display: grid; - grid-template-columns: repeat(${props => props.columns}, 1fr); + grid-template-columns: repeat(${(props) => props.columns}, 1fr); grid-column-gap: 8px; padding: 0 8px; max-width: 100%; @@ -117,7 +117,7 @@ export default function Gallery(props) { const fetching: { [k: number]: boolean } = {}; const [sinceTime, setSinceTime] = useState(0); - const [progress, setProgress] = useState(0) + const [progress, setProgress] = useState(0); useEffect(() => { const key = getKey(SESSION_KEYS.ENCRYPTION_KEY); @@ -142,19 +142,22 @@ export default function Gallery(props) { const syncWithRemote = async () => { const token = getToken(); const encryptionKey = await getActualKey(); - const {isUpdated, collections} = await getLatestCollections(token, encryptionKey); - const data = await fetchData(token, collections); - const collectionLatestFile = await getCollectionLatestFile(collections, data); + const collections = await syncCollections(token, encryptionKey); + const { data, isUpdated } = await syncData(token, collections); + const collectionLatestFile = await getCollectionLatestFile( + collections, + data + ); const favItemIds = await getFavItemIds(data); + setCollections(collections); if (isUpdated) { - setCollections(collections); setData(data); } setCollectionLatestFile(collectionLatestFile); setFavItemIds(favItemIds); - setSinceTime((new Date()).getTime()); + setSinceTime(new Date().getTime()); props.setUploadButtonView(true); - } + }; const updateUrl = (index: number) => (url: string) => { data[index] = { @@ -163,7 +166,10 @@ export default function Gallery(props) { w: window.innerWidth, h: window.innerHeight, }; - if (data[index].metadata.fileType === FILE_TYPE.VIDEO && !data[index].html) { + if ( + data[index].metadata.fileType === FILE_TYPE.VIDEO && + !data[index].html + ) { data[index].html = `