From 2dceafea6b253a1450388c1e16202a381a18794c Mon Sep 17 00:00:00 2001 From: Sandwich <299465+dskvr@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:32:31 +0700 Subject: [PATCH] cleanup --- .../lib/components/lists/table/Filters.svelte | 11 +- .../components/partials/MonitorActions.svelte | 2 - apps/gui/src/lib/stores/app.ts | 7 +- apps/gui/src/lib/utils/lifecycle.ts | 14 +- apps/gui/src/routes/+layout.svelte | 142 ++++++++++-------- package.json | 3 +- pnpm-lock.yaml | 3 + 7 files changed, 93 insertions(+), 89 deletions(-) diff --git a/apps/gui/src/lib/components/lists/table/Filters.svelte b/apps/gui/src/lib/components/lists/table/Filters.svelte index f5bd909a..b90f509f 100644 --- a/apps/gui/src/lib/components/lists/table/Filters.svelte +++ b/apps/gui/src/lib/components/lists/table/Filters.svelte @@ -122,8 +122,6 @@ // **Build Inverted Index** function buildInvertedIndex(data: RecordData[], filtersInclude: string[]) { - // const begin = new Date().getTime(); - // //console.log('begin buildInvertedIndex'); filtersInclude.forEach(filterKey => { _invertedIndex[filterKey] = {}; data.forEach(record => { @@ -140,7 +138,6 @@ } }); }); - // //console.log('end buildInvertedIndex', new Date().getTime() - begin); } // **Compute Active Record IDs Based on Active Filters** @@ -318,8 +315,6 @@ // **Apply a Filter Value Based on Its Type and Mode** function applyFilter(filterKey: string, value: any) { - // const begin = new Date().getTime(); - // //console.log('begin applyFilter', filterKey, value); const filter = $relayFilters.find(f => f.key === filterKey); if (!filter) return; @@ -338,10 +333,9 @@ } } else if (filter.type === 'string' || filter.type === 'array') { if (mode === 'OR') { - // OR mode allows multiple selections (union) + // union if (Array.isArray(existingFilter)) { if (existingFilter.includes(value)) { - // Deselect the value const newValues = existingFilter.filter(v => v !== value); if (newValues.length === 0) { const { [filterKey]: _, ...rest } = currentFilters; @@ -349,7 +343,6 @@ } return { ...currentFilters, [filterKey]: newValues }; } else { - // Select the value return { ...currentFilters, [filterKey]: [...existingFilter, value] }; } } else { @@ -357,7 +350,7 @@ return { ...currentFilters, [filterKey]: [value] }; } } else if (mode === 'AND') { - // AND mode requires all selected values to be present (intersection) + // intersection if (Array.isArray(existingFilter)) { if (existingFilter.includes(value)) { // Deselect the value diff --git a/apps/gui/src/lib/components/partials/MonitorActions.svelte b/apps/gui/src/lib/components/partials/MonitorActions.svelte index fddc4e70..875bb23d 100644 --- a/apps/gui/src/lib/components/partials/MonitorActions.svelte +++ b/apps/gui/src/lib/components/partials/MonitorActions.svelte @@ -46,8 +46,6 @@ } else { monitor.enable() - // const lastSync = monitor.getLastSyncSince(30166) - const options = { filters: [ monitor.checkFilter ], options: { diff --git a/apps/gui/src/lib/stores/app.ts b/apps/gui/src/lib/stores/app.ts index 583f2abb..378b0ca7 100644 --- a/apps/gui/src/lib/stores/app.ts +++ b/apps/gui/src/lib/stores/app.ts @@ -5,7 +5,11 @@ import { formatSeconds, timeAgo } from "../utils/time"; import { nip66 } from "./nip66"; import { delay } from "@nostrwatch/utils"; +export type AppStateType = 'booting' | 'running' | 'sleeping' | 'shutdown' +export const appState: Writable = writable() +export type TabStateType = 'idle' | 'leader' | 'follower' | 'unsupported'; +export const tabState: Writable = writable('follower'); export const nip66Initialized: Readable = derived( nip66, ($nip66) => $nip66?.initialized? true: false ) export const unsupported: Writable = writable(false) export const isLivesyncing: Writable = writable(false) @@ -32,7 +36,7 @@ export const shouldSync = () => { const threshold = 15*1 const timestamp = get(lastCompleteSync) const now = Math.round(Date.now()/1000) - console.log('should snyc?', threshold<(now-timestamp), formatSeconds(threshold), timeAgo(now*1000), timeAgo(timestamp*1000)) + console.log('should sync?', threshold<(now-timestamp), formatSeconds(threshold), timeAgo(now*1000), timeAgo(timestamp*1000)) if(threshold<(now-timestamp)) return true; return false; @@ -53,3 +57,4 @@ export const doAggregateCache: Writable = writable(false) export const shouldAggregate = (): boolean => { return !get(doAggregateCache) } + diff --git a/apps/gui/src/lib/utils/lifecycle.ts b/apps/gui/src/lib/utils/lifecycle.ts index b7d9408e..e5119f6e 100644 --- a/apps/gui/src/lib/utils/lifecycle.ts +++ b/apps/gui/src/lib/utils/lifecycle.ts @@ -136,7 +136,7 @@ export const bootstrapMonitorData = async () => { if(!$nip66){ $nip66 = await instance(); } - bindBootstrapEmitters($nip66); + bindBootstrapEmitters(); await $nip66?.services?.monitors?.bootstrapMonitors(); } @@ -148,7 +148,6 @@ export const bootstrapMonitorChecks = async () => { await $nip66?.services?.monitors?.syncMonitorsChecks(); } - export const bootstrap = async () => { console.log('bootstrap') if(!$nip66){ @@ -163,7 +162,6 @@ export const bootstrap = async () => { liveSyncBatcher.add(event); } } - if( shouldSync() ){ if( get(isBootstrapping) ) return; isBootstrapping.set(true) @@ -175,11 +173,7 @@ export const bootstrap = async () => { }) } else { - //console.log('skipping full sync') - //TODO: Send ready event from Cache Adapter Worker wait on Adapter ready. - // await $nip66?.adapters?.cache.ready(); - await new Promise( (resolve) => setTimeout(resolve, 1000) ) - // + await new Promise( (resolve) => setTimeout(resolve, 1000) ) seedFromCache().then( () => { if(get(isLivesyncing)) return; beginLiveSync({ onevents }) @@ -187,6 +181,8 @@ export const bootstrap = async () => { } } +type LiveSyncResumer = () => Promise + export const beginLiveSync = async (callbacks?: SubscribeHandlers): Promise => { isLivesyncing.set(true) if(!$nip66){ @@ -203,8 +199,6 @@ export const stopLiveSync = async (): Promise => { $nip66?.services?.monitors?.stopLiveSync() } -type LiveSyncResumer = () => Promise - export const pauseLiveSync = async (): Promise => { console.log('Lifecycle:pauseLiveSync') let wasLiveSyncing = get(isLivesyncing) diff --git a/apps/gui/src/routes/+layout.svelte b/apps/gui/src/routes/+layout.svelte index bc2cbf59..7e4cecab 100755 --- a/apps/gui/src/routes/+layout.svelte +++ b/apps/gui/src/routes/+layout.svelte @@ -1,5 +1,7 @@ + {#if isReady} - {#if isLeaderValue} + {#if $tabState === 'idle'} + +
+
Zzz
+
+ {:else if $tabState === 'leader'} +
- {:else if !isIdleValue} + {:else if $tabState === 'follower'} +
Another Session Detected
Please wait while the existing session is terminated.
- {:else if isIdleValue} -
-
Zzz
-
+ {:else if $tabState === 'unsupported'} + {/if} {/if} diff --git a/package.json b/package.json index cbc2d9ca..1a03d21c 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "author": "dskvr ", "license": "MIT", "dependencies": { - "glob": "^11.0.0" + "glob": "^11.0.0", + "nostr-tools": "^2.10.4" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66b03d0f..38bb34ef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: glob: specifier: ^11.0.0 version: 11.0.0 + nostr-tools: + specifier: ^2.10.4 + version: 2.10.4(typescript@5.7.2) devDependencies: '@changesets/cli': specifier: 2.27.8