From 769164a345e7d5bce57108b217bdc223cbf85552 Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Tue, 10 Sep 2024 18:26:47 +0530 Subject: [PATCH] fix: improve box viewing. --- src/lib/components/backupRestoreBox.svelte | 151 ++++++++++----------- 1 file changed, 69 insertions(+), 82 deletions(-) diff --git a/src/lib/components/backupRestoreBox.svelte b/src/lib/components/backupRestoreBox.svelte index 3e6e5290e..d897d1022 100644 --- a/src/lib/components/backupRestoreBox.svelte +++ b/src/lib/components/backupRestoreBox.svelte @@ -3,9 +3,6 @@ import { type Models, Query } from '@appwrite.io/console'; import { onMount } from 'svelte'; - let showBackupBox = false; - let showRestoreBox = false; - let backupRestoreItems: { archives: Map; restorations: Map; @@ -14,6 +11,9 @@ restorations: new Map() }; + $: showBackupRestoreBox = + backupRestoreItems.archives.size > 0 || backupRestoreItems.restorations.size > 0; + const fetchBackupRestores = async () => { try { const query = [Query.notEqual('status', ['completed', 'failed'])]; @@ -26,15 +26,14 @@ backupRestoreItems.archives = new Map( archivesResponse.archives.map((item) => [item.$id, item]) ); + + // this is a one time op. backupRestoreItems.restorations = new Map( restorationsResponse.restorations.map((item) => [item.$id, item]) ); } catch (e) { // ignore? } - - showBackupBox = backupRestoreItems.archives.size > 0; - showRestoreBox = backupRestoreItems.restorations.size > 0; }; // fresh fetch. @@ -53,10 +52,6 @@ } backupRestoreItems[$collection] = collectionMap; - - showBackupBox = $collection === 'archives' && backupRestoreItems.archives.size > 0; - showRestoreBox = - $collection === 'restorations' && backupRestoreItems.restorations.size > 0; } }; @@ -76,15 +71,20 @@ } }; - const handleClose = (which: 'archives' | 'restorations') => { + const handleClose = (which: string) => { backupRestoreItems[which] = new Map(); - showBackupBox = backupRestoreItems.archives.size > 0; - showRestoreBox = backupRestoreItems.restorations.size > 0; }; const reversed = (backupItem: Map) => [...backupItem.values()].reverse(); + // TODO: `startedAt` is probably not correct here. need more info. + const backupName = (item: Models.BackupArchive | Models.BackupRestoration, key: string) => { + const attribute = key === 'archives' ? '$createdAt' : 'startedAt'; + const date = new Date(item[attribute]); + return `${date.toDateString().slice(4, 10)}, ${date.toTimeString().slice(0, 5)}`; + }; + onMount(() => { sdk.forConsole.client.subscribe('console', (response) => { if ( @@ -97,79 +97,56 @@ }); -{#if showBackupBox} +{#if showBackupRestoreBox}
-
-
-

- Creating Backup -

- -
+ {#each Object.keys(backupRestoreItems) as key} + {@const isBackup = key === 'archives'} + {@const items = reversed(backupRestoreItems[key])} + {@const titleText = isBackup ? 'Creating Backup' : 'Creating Restoration'} + {@const shouldInsetRestorations = + key === 'restorations' && backupRestoreItems.archives.size > 0} -
- - {#each reversed(backupRestoreItems.archives) as item, index (item.$id)} -
-
- Preparing database server for backup -
-
-
- {/each} -
-
-
-{/if} + {#if items.length > 0} +
+
+

+ {titleText} +

+ +
-{#if showRestoreBox} -
-
-
-

- Creating Restoration -

- -
+
+ {#each items as item, index (item.$id)} +
+
+ + Preparing database server... + -
- - {#each reversed(backupRestoreItems.restorations) as item, index (item.$id)} -
-
- Preparing database server restore -
- {#key item.status} -
- {/key} -
- {/each} -
-
+ + {backupName(item, key)} + +
+
+
+ {/each} +
+
+ {/if} + {/each} {/if} @@ -179,4 +156,14 @@ min-width: 400px; max-width: 100vw; } + + .backup-name { + font-size: 12px; + font-weight: 400; + line-height: 130%; + font-style: normal; + letter-spacing: -0.12px; + color: var(--mid-neutrals-50, #818186); + font-family: var(--font-family-sansSerif, Inter); + }