+
+
+
+
+
{login ? (
) : (
diff --git a/src/page/relays.tsx b/src/page/relays.tsx
new file mode 100644
index 0000000..f469542
--- /dev/null
+++ b/src/page/relays.tsx
@@ -0,0 +1,47 @@
+import { useState } from "react";
+import { Button } from "../element/button";
+import { useRelays } from "../relays";
+import { sanitizeRelayUrl } from "@snort/shared";
+
+export function RelaysPage() {
+ const relays = useRelays();
+ const [newRelay, setNewRelay] = useState("");
+ return (
+ <>
+
Relays
+
+
+ {relays.relays.map((a) => (
+
+ {a}
+
+
+ ))}
+
+
+
+ setNewRelay(e.target.value)}
+ className="px-4 py-2 rounded-xl bg-neutral-800 focus-visible:outline-none"
+ placeholder="wss://myrelay.com"
+ />
+
+
+ >
+ );
+}
diff --git a/src/relays.tsx b/src/relays.tsx
new file mode 100644
index 0000000..d07dfec
--- /dev/null
+++ b/src/relays.tsx
@@ -0,0 +1,58 @@
+import { ExternalStore, appendDedupe, sanitizeRelayUrl } from "@snort/shared";
+import { useSyncExternalStore } from "react";
+
+const storageKey = "relays";
+class RelaysStore extends ExternalStore
> {
+ #relays: Array = [];
+
+ constructor() {
+ super();
+ const loaded = localStorage.getItem(storageKey);
+ if (loaded) {
+ this.#relays = JSON.parse(loaded);
+ } else {
+ this.#relays = ["wss://nos.lol/", "wss://relay.damus.io/", "wss://relay.nostr.band/"];
+ this.#save();
+ }
+ }
+
+ add(u: string) {
+ const url = sanitizeRelayUrl(u);
+ if (url) {
+ this.#relays = appendDedupe(this.#relays, [url]);
+ this.#save();
+ }
+ }
+
+ remove(u: string) {
+ const url = sanitizeRelayUrl(u);
+ if (url) {
+ this.#relays = this.#relays.filter((a) => a !== url);
+ this.#save();
+ }
+ }
+
+ #save() {
+ localStorage.setItem(storageKey, JSON.stringify(this.#relays));
+ this.notifyChange();
+ }
+
+ takeSnapshot(): string[] {
+ return [...this.#relays];
+ }
+}
+
+const relayStore = new RelaysStore();
+
+export function useRelays() {
+ const relays = useSyncExternalStore(
+ (s) => relayStore.hook(s),
+ () => relayStore.snapshot(),
+ );
+
+ return {
+ relays,
+ add: (a: string) => relayStore.add(a),
+ remove: (a: string) => relayStore.remove(a),
+ };
+}
diff --git a/src/system.ts b/src/system.ts
index 6dc3a8b..48ec60e 100644
--- a/src/system.ts
+++ b/src/system.ts
@@ -62,8 +62,5 @@ export async function initSystem() {
System.Init(),
];
- for (const r of ["wss://nos.lol", "wss://relay.damus.io", "wss://relay.nostr.band"]) {
- System.ConnectToRelay(r, { read: true, write: true });
- }
await Promise.all(tasks);
}