Merge pull request #955 from ente-io/fix-empty-trash-not-working

fix empty trash not working
This commit is contained in:
Abhinav Kumar 2023-02-24 12:43:58 +05:30 committed by GitHub
commit b52583998f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -352,8 +352,8 @@ export default function Gallery() {
!silent && startLoading(); !silent && startLoading();
const collections = await syncCollections(); const collections = await syncCollections();
setCollections(collections); setCollections(collections);
await syncFiles(collections, setFiles); const files = await syncFiles(collections, setFiles);
await syncTrash(collections, setFiles); await syncTrash(collections, files, setFiles);
} catch (e) { } catch (e) {
logError(e, 'syncWithRemote failed'); logError(e, 'syncWithRemote failed');
switch (e.message) { switch (e.message) {
@ -372,7 +372,7 @@ export default function Gallery() {
syncInProgress.current = false; syncInProgress.current = false;
if (resync.current) { if (resync.current) {
resync.current = false; resync.current = false;
syncWithRemote(); setTimeout(() => syncWithRemote(), 0);
} }
}; };

View file

@ -9,6 +9,7 @@ import { getCollection } from './collectionService';
import HTTPService from './HTTPService'; import HTTPService from './HTTPService';
import { EncryptedTrashItem, Trash } from 'types/trash'; import { EncryptedTrashItem, Trash } from 'types/trash';
import { EnteFile } from 'types/file';
const TRASH = 'file-trash'; const TRASH = 'file-trash';
const TRASH_TIME = 'trash-time'; const TRASH_TIME = 'trash-time';
@ -49,6 +50,7 @@ async function getLastSyncTime() {
} }
export async function syncTrash( export async function syncTrash(
collections: Collection[], collections: Collection[],
files: EnteFile[],
setFiles: SetFiles setFiles: SetFiles
): Promise<void> { ): Promise<void> {
const trash = await getLocalTrash(); const trash = await getLocalTrash();
@ -64,6 +66,7 @@ export async function syncTrash(
const updatedTrash = await updateTrash( const updatedTrash = await updateTrash(
collectionMap, collectionMap,
lastSyncTime, lastSyncTime,
files,
setFiles, setFiles,
trash trash
); );
@ -73,6 +76,7 @@ export async function syncTrash(
export const updateTrash = async ( export const updateTrash = async (
collections: Map<number, Collection>, collections: Map<number, Collection>,
sinceTime: number, sinceTime: number,
files: EnteFile[],
setFiles: SetFiles, setFiles: SetFiles,
currentTrash: Trash currentTrash: Trash
): Promise<Trash> => { ): Promise<Trash> => {
@ -123,7 +127,7 @@ export const updateTrash = async (
time = resp.data.diff.slice(-1)[0].updatedAt; time = resp.data.diff.slice(-1)[0].updatedAt;
} }
setFiles((files) => setFiles(
sortFiles([...(files ?? []), ...getTrashedFiles(updatedTrash)]) sortFiles([...(files ?? []), ...getTrashedFiles(updatedTrash)])
); );
await localForage.setItem(TRASH, updatedTrash); await localForage.setItem(TRASH, updatedTrash);