updated getCollectionLatestFile to use local files
This commit is contained in:
parent
3d6ee3a004
commit
08c993061c
2 changed files with 19 additions and 15 deletions
|
@ -119,7 +119,7 @@ export default function Gallery(props) {
|
|||
const encryptionKey = await getActualKey();
|
||||
const collections = await fetchCollections(token, encryptionKey);
|
||||
const data = await fetchData(token, collections);
|
||||
const collectionLatestFile = await getCollectionLatestFile(collections, token);
|
||||
const collectionLatestFile = await getCollectionLatestFile(collections, data);
|
||||
const favItemIds = await getFavItemIds(data);
|
||||
setCollections(collections);
|
||||
setData(data);
|
||||
|
@ -296,7 +296,7 @@ export default function Gallery(props) {
|
|||
showUploadModal={props.showUploadModal}
|
||||
collectionLatestFile={collectionLatestFile}
|
||||
refetchData={() => setReload(Math.random())}
|
||||
|
||||
|
||||
/>
|
||||
{filteredData.length ? (
|
||||
<Container>
|
||||
|
|
|
@ -108,21 +108,25 @@ export const fetchCollections = async (token: string, key: string) => {
|
|||
return collections;
|
||||
};
|
||||
|
||||
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