Merge branch 'collection-ops' into file-loading-single-update
This commit is contained in:
commit
053568980e
2 changed files with 23 additions and 19 deletions
|
@ -129,20 +129,20 @@ export default function Gallery(props) {
|
|||
setCollections(collections);
|
||||
setLoading(false);
|
||||
setProgress(80);
|
||||
await loadData();
|
||||
await syncWithRemote();
|
||||
setProgress(100);
|
||||
};
|
||||
main();
|
||||
props.setUploadButtonView(true);
|
||||
}, []);
|
||||
|
||||
const loadData = async () => {
|
||||
const syncWithRemote = async () => {
|
||||
const token = getToken();
|
||||
const encryptionKey = await getActualKey();
|
||||
const updatedCollections = await fetchUpdatedCollections(token, encryptionKey);
|
||||
const data = await fetchData(token, updatedCollections);
|
||||
const collections = await getLocalCollections();
|
||||
const collectionLatestFile = await getCollectionLatestFile(collections, token);
|
||||
const collectionLatestFile = await getCollectionLatestFile(collections, data);
|
||||
const favItemIds = await getFavItemIds(data);
|
||||
if (updatedCollections.length > 0) {
|
||||
setCollections(collections);
|
||||
|
@ -150,7 +150,7 @@ export default function Gallery(props) {
|
|||
}
|
||||
setCollectionLatestFile(collectionLatestFile);
|
||||
setFavItemIds(favItemIds);
|
||||
|
||||
|
||||
props.setUploadButtonView(true);
|
||||
}
|
||||
if (!data || loading) {
|
||||
|
@ -206,7 +206,7 @@ export default function Gallery(props) {
|
|||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
// setReload(Math.random());
|
||||
// syncWithRemote();
|
||||
};
|
||||
|
||||
const onThumbnailClick = (index: number) => () => {
|
||||
|
@ -322,7 +322,7 @@ export default function Gallery(props) {
|
|||
closeUploadModal={props.closeUploadModal}
|
||||
showUploadModal={props.showUploadModal}
|
||||
collectionLatestFile={collectionLatestFile}
|
||||
refetchData={loadData}
|
||||
refetchData={syncWithRemote}
|
||||
|
||||
/>
|
||||
{filteredData.length ? (
|
||||
|
|
|
@ -128,21 +128,25 @@ export const fetchUpdatedCollections = async (token: string, key: string) => {
|
|||
return updatedCollections;
|
||||
};
|
||||
|
||||
export const getCollectionLatestFile = async (
|
||||
export const getCollectionLatestFile = (
|
||||
collections: collection[],
|
||||
token
|
||||
): Promise<collectionLatestFile[]> => {
|
||||
return Promise.all(
|
||||
collections.map(async collection => {
|
||||
const sinceTime: string = (Number(await localForage.getItem<string>(`${collection.id}-time`)) - 1).toString();
|
||||
const files: file[] = await getFiles([collection], sinceTime, "1", token) || [];
|
||||
files: file[]
|
||||
): collectionLatestFile[] => {
|
||||
const latestFile = new Map<number, file>();
|
||||
const collectionMap = new Map<number, collection>();
|
||||
|
||||
return {
|
||||
file: files[0],
|
||||
collection,
|
||||
}
|
||||
}))
|
||||
};
|
||||
collections.forEach(collection => collectionMap.set(Number(collection.id), collection));
|
||||
files.forEach(file => {
|
||||
if (!latestFile.has(file.collectionID)) {
|
||||
latestFile.set(file.collectionID, file)
|
||||
}
|
||||
});
|
||||
let allCollectionLatestFile: collectionLatestFile[] = [];
|
||||
for (const [collectionID, file] of latestFile) {
|
||||
allCollectionLatestFile.push({ collection: collectionMap.get(collectionID), file });
|
||||
}
|
||||
return allCollectionLatestFile;
|
||||
}
|
||||
|
||||
export const getFavItemIds = async (files: file[]): Promise<Set<number>> => {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue