-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
frontend/src/routes/(authenticated)/project/[project_code]/CrdtSyncButton.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts"> | ||
import {Button} from '$lib/forms'; | ||
import {Icon} from '$lib/icons'; | ||
import {useNotifications} from '$lib/notify'; | ||
export let projectId: string; | ||
const {notifySuccess, notifyWarning} = useNotifications(); | ||
let syncing = false; | ||
async function triggerSync(): Promise<void> { | ||
syncing = true; | ||
try { | ||
const response = await fetch(`/api/crdt/crdt-sync/${projectId}`, { | ||
method: 'POST', | ||
}); | ||
if (response.ok) { | ||
const { crdtChanges, fwdataChanges } = await response.json(); | ||
notifySuccess(`Synced successfully (${fwdataChanges} FwData changes. ${crdtChanges} CRDT changes)`); | ||
} else { | ||
const error = `Failed to sync: ${response.statusText} (${response.status})`; | ||
notifyWarning(error); | ||
console.error(error, await response.text()); | ||
} | ||
} finally { | ||
syncing = false; | ||
} | ||
} | ||
</script> | ||
|
||
<Button | ||
variant="btn-primary" | ||
class="gap-1" | ||
on:click={triggerSync} | ||
loading={syncing} | ||
customLoader | ||
> | ||
FwData | ||
<Icon icon="i-mdi-sync" spin={syncing} spinReverse /> | ||
CRDT | ||
</Button> |