From 3cfddf8647eca72d116538895657dc8821e48cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 22 Feb 2024 08:28:27 +0000 Subject: [PATCH] Show seed policy and scope in "online" button --- src/App/Header.svelte | 2 +- src/App/Header/NodeInfo.svelte | 39 ++++++++++++++++++++-- src/components/ScopePolicyExplainer.svelte | 17 ++++++++++ src/lib/httpd.ts | 24 ++++++------- src/views/nodes/View.svelte | 14 ++------ 5 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 src/components/ScopePolicyExplainer.svelte diff --git a/src/App/Header.svelte b/src/App/Header.svelte index 77bab29a6..c9bf5e7ae 100644 --- a/src/App/Header.svelte +++ b/src/App/Header.svelte @@ -76,7 +76,7 @@ {:else} - + {/if} diff --git a/src/App/Header/NodeInfo.svelte b/src/App/Header/NodeInfo.svelte index 71a7b56e3..65ee32ee1 100644 --- a/src/App/Header/NodeInfo.svelte +++ b/src/App/Header/NodeInfo.svelte @@ -1,10 +1,15 @@
- {#if running} + {#if node.state === "running"}
Your node is running and syncing with the network.
+ + {#if node.config?.scope && node.config?.policy} +
+
+ Seeding Policy: + {capitalize(node.config.policy)} + +
+
+ Scope: + + {capitalize(node.config.scope)} + +
+ + +
+ {/if}
Shut down your node if you want to stop sharing and receiving updates.
diff --git a/src/components/ScopePolicyExplainer.svelte b/src/components/ScopePolicyExplainer.svelte new file mode 100644 index 000000000..31bb41a12 --- /dev/null +++ b/src/components/ScopePolicyExplainer.svelte @@ -0,0 +1,17 @@ + + +{#if policy === "allow"} + All discovered repositories will get seeded, +{:else if policy === "block"} + Only repositories marked as such will get seeded, +{/if} +{#if scope === "all"} + and all changes in those repos, made by any peer, will be synced. +{:else if scope === "followed"} + and only changes made by explicitly followed peers will be synced. +{/if} diff --git a/src/lib/httpd.ts b/src/lib/httpd.ts index 388e79e8b..e036ecdb1 100644 --- a/src/lib/httpd.ts +++ b/src/lib/httpd.ts @@ -1,3 +1,5 @@ +import type { Node } from "@httpd-client"; + import { get, writable } from "svelte/store"; import { withTimeout, Mutex, E_CANCELED, E_TIMEOUT } from "async-mutex"; @@ -11,15 +13,13 @@ export interface Session { alias: string; } -type NodeState = { state: "running" | "stopped"; id: string }; - export type HttpdState = | { state: "stopped" } - | { state: "running"; node: NodeState } + | { state: "running"; node: Node } | { state: "authenticated"; session: Session; - node: NodeState; + node: Node; }; const HTTPD_STATE_STORAGE_KEY = "httpdState"; @@ -60,7 +60,7 @@ export async function authenticate(params: { sig: params.signature, pk: params.publicKey, }); - const { id, state } = await api.getNode(); + const node = await api.getNode(); const sess = await api.session.getById(params.id); update({ state: "authenticated", @@ -69,7 +69,7 @@ export async function authenticate(params: { publicKey: params.publicKey, alias: sess.alias, }, - node: { state, id }, + node, }); return true; } catch (error) { @@ -91,10 +91,10 @@ export async function disconnect() { try { await api.session.delete(httpd.session.id); - const { id, state } = await api.getNode(); + const node = await api.getNode(); update({ state: "running", - node: { state, id }, + node, }); } catch (error) { console.error(error); @@ -126,10 +126,10 @@ async function checkState() { await stateMutex .runExclusive(async () => { try { - const { id, state } = await api.getNode(); + const node = await api.getNode(); if (httpdState && httpdState.state !== "stopped") { - httpdState.node = { state, id }; + httpdState.node = node; } if (httpdState && httpdState.state === "authenticated") { @@ -141,7 +141,7 @@ async function checkState() { ) { update({ state: "running", - node: { state, id }, + node, }); } else { update(httpdState); @@ -149,7 +149,7 @@ async function checkState() { } else { update({ state: "running", - node: { state, id }, + node, }); } } catch (error) { diff --git a/src/views/nodes/View.svelte b/src/views/nodes/View.svelte index a20e36b43..473a0982f 100644 --- a/src/views/nodes/View.svelte +++ b/src/views/nodes/View.svelte @@ -12,6 +12,7 @@ import CopyableId from "@app/components/CopyableId.svelte"; import IconSmall from "@app/components/IconSmall.svelte"; import ProjectCard from "@app/components/ProjectCard.svelte"; + import ScopePolicyExplainer from "@app/components/ScopePolicyExplainer.svelte"; import HoverPopover from "@app/components/HoverPopover.svelte"; export let baseUrl: BaseUrl; @@ -178,18 +179,7 @@
- {#if policy === "allow"} - All discovered repositories will get seeded, - {:else if policy === "block"} - Only repositories marked as such will get seeded, - {/if} - {#if scope === "all"} - and all changes in those repos, made by any peer, will be - synced. - {:else if scope === "followed"} - and only changes made by explicitly followed peers will be - synced. - {/if} +