From ce669f203cfcee135e972d05c81ec9d96fce223f Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Tue, 30 Apr 2024 12:42:44 +0800 Subject: [PATCH] Basic sync backfill dialog (#2405) * basic sync backfill dialog * only call enableSync once * rename sync enable to backfill * disallow closing dialog --- core/src/api/sync.rs | 2 +- interface/app/$libraryId/debug/sync.tsx | 49 ++++++++++++++++++++----- packages/client/src/core.ts | 2 +- packages/ui/src/Dialog.tsx | 49 +++++++++++++------------ 4 files changed, 67 insertions(+), 35 deletions(-) diff --git a/core/src/api/sync.rs b/core/src/api/sync.rs index b54e3fb8dfb8..44b61d586289 100644 --- a/core/src/api/sync.rs +++ b/core/src/api/sync.rs @@ -34,7 +34,7 @@ pub(crate) fn mount() -> AlphaRouter { .await?) }) }) - .procedure("enable", { + .procedure("backfill", { R.with2(library()) .mutation(|(node, library), _: ()| async move { if library diff --git a/interface/app/$libraryId/debug/sync.tsx b/interface/app/$libraryId/debug/sync.tsx index e0d495790f68..d7807e27173f 100644 --- a/interface/app/$libraryId/debug/sync.tsx +++ b/interface/app/$libraryId/debug/sync.tsx @@ -1,12 +1,13 @@ -import { useMemo } from 'react'; +import { useEffect, useMemo } from 'react'; import { CRDTOperation, CRDTOperationData, useLibraryMutation, useLibraryQuery, - useLibrarySubscription + useLibrarySubscription, + useZodForm } from '@sd/client'; -import { Button } from '@sd/ui'; +import { Button, Dialog, dialogManager, useDialog, UseDialogProps, z } from '@sd/ui'; import { useRouteTitle } from '~/hooks/useRouteTitle'; type MessageGroup = { @@ -21,7 +22,7 @@ export const Component = () => { const syncEnabled = useLibraryQuery(['sync.enabled']); const messages = useLibraryQuery(['sync.messages']); - const enableSync = useLibraryMutation(['sync.enable'], { + const backfillSync = useLibraryMutation(['sync.backfill'], { onSuccess: async () => { await syncEnabled.refetch(); await messages.refetch(); @@ -32,18 +33,17 @@ export const Component = () => { onData: () => messages.refetch() }); - const groups = useMemo( - () => (messages.data && calculateGroups(messages.data)) || [], - [messages] - ); + const groups = useMemo(() => (messages.data && calculateGroups(messages.data)) || [], [messages]); return (