renamed collectionLatestfile to collectionAndItsLatestFile

This commit is contained in:
Abhinav-grd 2021-02-09 11:34:19 +05:30
parent 21297e6e73
commit a4a3ad2e40
6 changed files with 32 additions and 27 deletions

View file

@ -9,7 +9,7 @@ function CollectionDropZone({
closeModal, closeModal,
showModal, showModal,
refetchData, refetchData,
collectionLatestFile, collectionAndItsLatestFile,
setProgressView, setProgressView,
progressBarProps progressBarProps
@ -21,7 +21,7 @@ function CollectionDropZone({
progressBarProps.setPercentComplete(0); progressBarProps.setPercentComplete(0);
setProgressView(true); setProgressView(true);
await UploadService.uploadFiles(acceptedFiles, collectionLatestFile, token, progressBarProps); await UploadService.uploadFiles(acceptedFiles, collectionAndItsLatestFile, token, progressBarProps);
refetchData(); refetchData();
setProgressView(false); setProgressView(false);
} }

View file

@ -10,17 +10,16 @@ function CollectionSelector(props) {
uploadModalView, uploadModalView,
closeUploadModal, closeUploadModal,
showUploadModal, showUploadModal,
collectionLatestFile, collectionAndItsLatestFile,
...rest ...rest
} = props; } = props;
const CollectionIcons = collectionAndItsLatestFile?.map((item) => (
const CollectionIcons = collectionLatestFile?.map((item) => (
<CollectionDropZone key={item.collection.id} <CollectionDropZone key={item.collection.id}
{...rest} {...rest}
closeModal={closeUploadModal} closeModal={closeUploadModal}
showModal={showUploadModal} showModal={showUploadModal}
collectionLatestFile={item} collectionAndItsLatestFile={item}
> >
<Card> <Card>
<PreviewCard data={item.file} updateUrl={() => { }} forcedEnable /> <PreviewCard data={item.file} updateUrl={() => { }} forcedEnable />

View file

@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Button, Form, Modal } from 'react-bootstrap'; import { Button, Form, Modal } from 'react-bootstrap';
import { createAlbum } from 'services/collectionService'; import { createAlbum } from 'services/collectionService';
import UploadService from 'services/uploadService'; import UploadService from 'services/uploadService';
import { collectionLatestFile } from 'services/collectionService' import { CollectionAndItsLatestFile } from 'services/collectionService'
import { getToken } from 'utils/common/key'; import { getToken } from 'utils/common/key';
export default function CreateCollection(props) { export default function CreateCollection(props) {
@ -35,12 +35,12 @@ export default function CreateCollection(props) {
const collection = await createAlbum(albumName); const collection = await createAlbum(albumName);
const collectionLatestFile: collectionLatestFile = { collection, file: null } const collectionAndItsLatestFile: CollectionAndItsLatestFile = { collection, file: null }
progressBarProps.setPercentComplete(0); progressBarProps.setPercentComplete(0);
setProgressView(true); setProgressView(true);
await UploadService.uploadFiles(acceptedFiles, collectionLatestFile, token, progressBarProps); await UploadService.uploadFiles(acceptedFiles, collectionAndItsLatestFile, token, progressBarProps);
refetchData(); refetchData();
setProgressView(false); setProgressView(false);
} }

View file

@ -23,14 +23,14 @@ import Upload from './components/Upload';
import { import {
collection, collection,
syncCollections, syncCollections,
collectionLatestFile, CollectionAndItsLatestFile,
getCollectionLatestFile, getCollectionAndItsLatestFile,
getFavItemIds, getFavItemIds,
getLocalCollections, getLocalCollections,
} from 'services/collectionService'; } from 'services/collectionService';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
const DATE_CONTAINER_HEIGHT = 30; const DATE_CONTAINER_HEIGHT = 45;
const IMAGE_CONTAINER_HEIGHT = 200; const IMAGE_CONTAINER_HEIGHT = 200;
const NO_OF_PAGES = 2; const NO_OF_PAGES = 2;
@ -108,9 +108,10 @@ export default function Gallery(props) {
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [collections, setCollections] = useState<collection[]>([]); const [collections, setCollections] = useState<collection[]>([]);
const [collectionLatestFile, setCollectionLatestFile] = useState< const [
collectionLatestFile[] collectionAndItsLatestFile,
>([]); setCollectionAndItsLatestFile,
] = useState<CollectionAndItsLatestFile[]>([]);
const [data, setData] = useState<file[]>(); const [data, setData] = useState<file[]>();
const [favItemIds, setFavItemIds] = useState<Set<number>>(); const [favItemIds, setFavItemIds] = useState<Set<number>>();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
@ -132,8 +133,13 @@ export default function Gallery(props) {
setLoading(true); setLoading(true);
const data = await localFiles(); const data = await localFiles();
const collections = await getLocalCollections(); const collections = await getLocalCollections();
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
collections,
data
);
setData(data); setData(data);
setCollections(collections); setCollections(collections);
setCollectionAndItsLatestFile(collectionAndItsLatestFile);
setLoading(false); setLoading(false);
setProgress(80); setProgress(80);
await syncWithRemote(); await syncWithRemote();
@ -148,7 +154,7 @@ export default function Gallery(props) {
const encryptionKey = await getActualKey(); const encryptionKey = await getActualKey();
const collections = await syncCollections(token, encryptionKey); const collections = await syncCollections(token, encryptionKey);
const { data, isUpdated } = await syncData(token, collections); const { data, isUpdated } = await syncData(token, collections);
const collectionLatestFile = await getCollectionLatestFile( const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
collections, collections,
data data
); );
@ -157,7 +163,7 @@ export default function Gallery(props) {
if (isUpdated) { if (isUpdated) {
setData(data); setData(data);
} }
setCollectionLatestFile(collectionLatestFile); setCollectionAndItsLatestFile(collectionAndItsLatestFile);
setFavItemIds(favItemIds); setFavItemIds(favItemIds);
setSinceTime(new Date().getTime()); setSinceTime(new Date().getTime());
props.setUploadButtonView(true); props.setUploadButtonView(true);
@ -340,7 +346,7 @@ export default function Gallery(props) {
uploadModalView={props.uploadModalView} uploadModalView={props.uploadModalView}
closeUploadModal={props.closeUploadModal} closeUploadModal={props.closeUploadModal}
showUploadModal={props.showUploadModal} showUploadModal={props.showUploadModal}
collectionLatestFile={collectionLatestFile} collectionAndItsLatestFile={collectionAndItsLatestFile}
refetchData={syncWithRemote} refetchData={syncWithRemote}
/> />
{filteredData.length ? ( {filteredData.length ? (

View file

@ -44,7 +44,7 @@ interface collectionAttributes {
pathDecryptionNonce?: string; pathDecryptionNonce?: string;
} }
export interface collectionLatestFile { export interface CollectionAndItsLatestFile {
collection: collection; collection: collection;
file: file; file: file;
} }
@ -157,10 +157,10 @@ export const syncCollections = async (token: string, key: string) => {
return collections; return collections;
}; };
export const getCollectionLatestFile = ( export const getCollectionAndItsLatestFile = (
collections: collection[], collections: collection[],
files: file[] files: file[]
): collectionLatestFile[] => { ): CollectionAndItsLatestFile[] => {
const latestFile = new Map<number, file>(); const latestFile = new Map<number, file>();
const collectionMap = new Map<number, collection>(); const collectionMap = new Map<number, collection>();
@ -172,14 +172,14 @@ export const getCollectionLatestFile = (
latestFile.set(file.collectionID, file); latestFile.set(file.collectionID, file);
} }
}); });
let allCollectionLatestFile: collectionLatestFile[] = []; let allCollectionAndItsLatestFile: CollectionAndItsLatestFile[] = [];
for (const [collectionID, file] of latestFile) { for (const [collectionID, file] of latestFile) {
allCollectionLatestFile.push({ allCollectionAndItsLatestFile.push({
collection: collectionMap.get(collectionID), collection: collectionMap.get(collectionID),
file, file,
}); });
} }
return allCollectionLatestFile; return allCollectionAndItsLatestFile;
}; };
export const getFavItemIds = async (files: file[]): Promise<Set<number>> => { export const getFavItemIds = async (files: file[]): Promise<Set<number>> => {

View file

@ -3,7 +3,7 @@ import HTTPService from './HTTPService';
import * as Comlink from 'comlink'; import * as Comlink from 'comlink';
import EXIF from "exif-js"; import EXIF from "exif-js";
import { fileAttribute } from './fileService'; import { fileAttribute } from './fileService';
import { collection, collectionLatestFile } from "./collectionService" import { collection, CollectionAndItsLatestFile } from "./collectionService"
import { FILE_TYPE } from 'pages/gallery'; import { FILE_TYPE } from 'pages/gallery';
const CryptoWorker: any = const CryptoWorker: any =
typeof window !== 'undefined' && typeof window !== 'undefined' &&
@ -80,7 +80,7 @@ class UploadService {
private totalFilesCount: number private totalFilesCount: number
private metadataMap: Map<string, Object>; private metadataMap: Map<string, Object>;
public async uploadFiles(recievedFiles: File[], collectionLatestFile: collectionLatestFile, token: string, progressBarProps) { public async uploadFiles(recievedFiles: File[], collectionAndItsLatestFile: CollectionAndItsLatestFile, token: string, progressBarProps) {
try { try {
const worker = await new CryptoWorker(); const worker = await new CryptoWorker();
this.stepsCompleted = 0; this.stepsCompleted = 0;
@ -107,7 +107,7 @@ class UploadService {
while (actualFiles.length > 0) { while (actualFiles.length > 0) {
var promises = []; var promises = [];
for (var i = 0; i < 5 && actualFiles.length > 0; i++) for (var i = 0; i < 5 && actualFiles.length > 0; i++)
promises.push(this.uploadHelper(progressBarProps, actualFiles.pop(), collectionLatestFile.collection, token)); promises.push(this.uploadHelper(progressBarProps, actualFiles.pop(), collectionAndItsLatestFile.collection, token));
uploadFilesWithoutMetaData.push(...await Promise.all(promises)); uploadFilesWithoutMetaData.push(...await Promise.all(promises));
} }