Working for non-deletes
This commit is contained in:
parent
ec54d0fdb3
commit
054d109ef8
12 changed files with 574 additions and 603 deletions
15
frontend/sync-client/src/utils/create-promise.ts
Normal file
15
frontend/sync-client/src/utils/create-promise.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export function createPromise<T = void>(): [
|
||||
Promise<T>,
|
||||
(value: T) => void,
|
||||
(error: unknown) => void
|
||||
] {
|
||||
let resolve: undefined | ((resolved: T) => void) = undefined;
|
||||
let reject: undefined | ((error: unknown) => void) = undefined;
|
||||
|
||||
const creationPromise = new Promise<T>(
|
||||
(resolve_, reject_) => ((resolve = resolve_), (reject = reject_))
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return [creationPromise, resolve!, reject!];
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import type { DocumentMetadata, RelativePath } from "../persistence/database";
|
||||
import type { DocumentRecord } from "../persistence/database";
|
||||
import { EMPTY_HASH } from "./hash";
|
||||
|
||||
// TODO: make this smarter so that offline files can be renamed & edited at the same time
|
||||
export function findMatchingFile(
|
||||
contentHash: string,
|
||||
candidates: [RelativePath, DocumentMetadata][]
|
||||
): [RelativePath, DocumentMetadata] | undefined {
|
||||
candidates: DocumentRecord[]
|
||||
): DocumentRecord | undefined {
|
||||
if (contentHash === EMPTY_HASH) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return candidates.find(([_, metadata]) => metadata.hash === contentHash);
|
||||
return candidates.find(({ metadata }) => metadata?.hash === contentHash);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue