From 3a34d3169768275f33eaa29f4d27157e13b77249 Mon Sep 17 00:00:00 2001 From: Ticruz Date: Tue, 26 Nov 2024 13:00:19 +0100 Subject: [PATCH] multiple select button --- src/app/views/Publishes.svelte | 6 +-- src/app/views/PublishesConnections.svelte | 46 ++++++++++++----------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/app/views/Publishes.svelte b/src/app/views/Publishes.svelte index 33d7e686..35e62808 100644 --- a/src/app/views/Publishes.svelte +++ b/src/app/views/Publishes.svelte @@ -15,7 +15,7 @@ const tabs = ["events", "connections", "notices"] let activeTab = "events" - let selectedUrl: string + let selected: string const hasStatus = (thunk: Thunk, statuses: PublishStatus[]) => Object.values(get(thunk.status)).some(s => statuses.includes(s.status)) @@ -79,7 +79,7 @@ {/each} {:else if activeTab === "connections"} - + {:else if activeTab === "notices"} - + {/if} diff --git a/src/app/views/PublishesConnections.svelte b/src/app/views/PublishesConnections.svelte index 3819bc0f..dc20a7df 100644 --- a/src/app/views/PublishesConnections.svelte +++ b/src/app/views/PublishesConnections.svelte @@ -11,7 +11,8 @@ export let selected: string export let activeTab: string - const connectionsStatus: {[key: string]: Map} = {} + let selectedOptions: string[] = [] + let connectionsStatus: {[key: string]: Map} = {} const options = [ "Connected", @@ -32,44 +33,49 @@ const failureStatuses = [AuthStatus.DeniedSignature, AuthStatus.Forbidden] $: connections = Array.from(ctx.net.pool.data.entries()) - .filter(([url, cxn]) => (selected ? connectionsStatus[selected]?.has(url) : true)) + .filter(([url, cxn]) => + selectedOptions.length ? selectedOptions.some(s => connectionsStatus[s]?.has(url)) : true, + ) .map(([url, cxn]) => cxn) onMount(() => { const interval = setInterval(() => { + // make a copy of the connections + const newConnectionStatus: {[key: string]: Map} = {} for (const [url, cxn] of ctx.net.pool.data.entries()) { if (pendingStatuses.includes(cxn.auth.status)) { - connectionsStatus["Logging in"] = (connectionsStatus["Logging in"] || new Map()).set( + newConnectionStatus["Logging in"] = (newConnectionStatus["Logging in"] || new Map()).set( url, cxn, ) } else if (failureStatuses.includes(cxn.auth.status)) { - connectionsStatus["Failed to log in"] = ( - connectionsStatus["Failed to log in"] || new Map() + newConnectionStatus["Failed to log in"] = ( + newConnectionStatus["Failed to log in"] || new Map() ).set(url, cxn) } else if (cxn.socket.status === SocketStatus.Error) { - connectionsStatus["Failed to connect"] = ( - connectionsStatus["Failed to connect"] || new Map() + newConnectionStatus["Failed to connect"] = ( + newConnectionStatus["Failed to connect"] || new Map() ).set(url, cxn) } else if (cxn.socket.status === SocketStatus.Closed) { - connectionsStatus["Waiting to reconnect"] = ( - connectionsStatus["Waiting to reconnect"] || new Map() + newConnectionStatus["Waiting to reconnect"] = ( + newConnectionStatus["Waiting to reconnect"] || new Map() ).set(url, cxn) } else if (cxn.socket.status === SocketStatus.New) { - connectionsStatus["Not connected"] = ( - connectionsStatus["Not connected"] || new Map() + newConnectionStatus["Not connected"] = ( + newConnectionStatus["Not connected"] || new Map() ).set(url, cxn) } else if (getRelayQuality(cxn.url) < 0.5) { - connectionsStatus["Unstable connection"] = ( - connectionsStatus["Unstable connection"] || new Map() + newConnectionStatus["Unstable connection"] = ( + newConnectionStatus["Unstable connection"] || new Map() ).set(url, cxn) } else { - connectionsStatus["Connected"] = (connectionsStatus["Connected"] || new Map()).set( + newConnectionStatus["Connected"] = (newConnectionStatus["Connected"] || new Map()).set( url, cxn, ) } } + connectionsStatus = newConnectionStatus }, 800) return () => { @@ -78,12 +84,10 @@ }) - -
-
- {Array.from(connectionsStatus[option]?.values() || []).length || 0} - {option} -
+ +
+ {Array.from(connectionsStatus[option]?.values() || []).length || 0} + {option}
{#each connections as cxn (cxn.url)} @@ -123,7 +127,7 @@
{#each options as opt} {#if connectionsStatus[opt]?.has(cxn.url)} -