feat(core): loading ui for favorite and organize (#7700)

This commit is contained in:
EYHN
2024-08-02 07:17:01 +00:00
parent 94c5effdd5
commit e54be7dc02
15 changed files with 179 additions and 36 deletions

View File

@@ -22,6 +22,25 @@ export {
ReadonlyStorage as ReadonlyDocStorage,
} from './storage';
export interface DocEngineDocState {
/**
* is syncing with the server
*/
syncing: boolean;
/**
* is saving to local storage
*/
saving: boolean;
/**
* is loading from local storage
*/
loading: boolean;
retrying: boolean;
ready: boolean;
errorMessage: string | null;
serverClock: number | null;
}
export class DocEngine {
readonly clientId: string;
localPart: DocEngineLocalPart;
@@ -53,13 +72,14 @@ export class DocEngine {
docState$(docId: string) {
const localState$ = this.localPart.docState$(docId);
const remoteState$ = this.remotePart?.docState$(docId);
return LiveData.computed(get => {
return LiveData.computed<DocEngineDocState>(get => {
const localState = get(localState$);
const remoteState = remoteState$ ? get(remoteState$) : null;
if (remoteState) {
return {
syncing: remoteState.syncing,
saving: localState.syncing,
loading: localState.syncing,
retrying: remoteState.retrying,
ready: localState.ready,
errorMessage: remoteState.errorMessage,
@@ -69,6 +89,7 @@ export class DocEngine {
return {
syncing: localState.syncing,
saving: localState.syncing,
loading: localState.syncing,
ready: localState.ready,
retrying: false,
errorMessage: null,

View File

@@ -40,6 +40,7 @@ export interface LocalEngineState {
export interface LocalDocState {
ready: boolean;
loading: boolean;
syncing: boolean;
}
@@ -81,6 +82,7 @@ export class DocEngineLocalPart {
const next = () => {
subscribe.next({
ready: this.status.readyDocs.has(docId) ?? false,
loading: this.status.connectedDocs.has(docId),
syncing:
(this.status.jobMap.get(docId)?.length ?? 0) > 0 ||
this.status.currentJob?.docId === docId,
@@ -91,7 +93,7 @@ export class DocEngineLocalPart {
if (updatedId === docId) next();
});
}),
{ ready: false, syncing: false }
{ ready: false, loading: false, syncing: false }
);
}