From 985fa2f7c99832cdf3c3351d2273c8fd05402b78 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 17 Sep 2025 21:45:18 +0700 Subject: basic comms working --- front/src/pages/Settings.tsx | 257 +++++++++++++++++++++++++++++++------------ 1 file changed, 187 insertions(+), 70 deletions(-) (limited to 'front/src/pages/Settings.tsx') diff --git a/front/src/pages/Settings.tsx b/front/src/pages/Settings.tsx index e0f1da9..6b6f7bd 100644 --- a/front/src/pages/Settings.tsx +++ b/front/src/pages/Settings.tsx @@ -1,89 +1,206 @@ import useLocalState from "@/state/state"; -import type { UserProfile } from "@/types/nostril"; import { useState } from "react"; +import toast from "react-hot-toast"; +import { ThemeSwitcher } from "@/styles/ThemeSwitcher"; +import Icon from "@/components/Icon"; +import "@/styles/Settings.css"; function Settings() { - const { UISettings, keys, profiles, relays, api } = useLocalState(); + const { key, relays, api } = useLocalState((s) => ({ + key: s.key, + relays: s.relays, + api: s.api, + })); const [newRelay, setNewRelay] = useState(""); - async function saveSetting( - bucket: string, - key: string, - value: string | boolean | number | string[], - ) { - const json = { - "put-entry": { - desk: "trill", - "bucket-key": bucket, - "entry-key": key, - value, - }, - }; - // const res = await poke("settings", "settings-event", json); - // if (res) refetchSettings(); - } + const [isAddingRelay, setIsAddingRelay] = useState(false); + const [isCyclingKey, setIsCyclingKey] = useState(false); + async function removeRelay(url: string) { - console.log({ url }); + try { + await api?.deleteRelay(url); + toast.success("Relay removed"); + } catch (error) { + toast.error("Failed to remove relay"); + console.error("Remove relay error:", error); + } } + async function addNewRelay() { - // - // await addnr(newRelay); - } - async function removeProfile(pubkey: string) { - api!.removeKey(pubkey); + if (!newRelay.trim()) { + toast.error("Please enter a relay URL"); + return; + } + + setIsAddingRelay(true); + try { + const valid = ["wss:", "ws:"]; + const url = new URL(newRelay); + if (!valid.includes(url.protocol)) { + toast.error("Invalid Relay URL - must use wss:// or ws://"); + return; + } + + await api?.addRelay(newRelay); + toast.success("Relay added"); + setNewRelay(""); + } catch (error) { + toast.error("Invalid relay URL or failed to add relay"); + console.error("Add relay error:", error); + } finally { + setIsAddingRelay(false); + } } - async function createProfile() { - // - api!.createKey(); + + async function cycleKey() { + setIsCyclingKey(true); + try { + await api?.cycleKeys(); + toast.success("Key cycled successfully"); + } catch (error) { + toast.error("Failed to cycle key"); + console.error("Cycle key error:", error); + } finally { + setIsCyclingKey(false); + } } + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + addNewRelay(); + } + }; + return ( -
-

Settings

-
- - {keys.map((k) => { - const profile = profiles.get(k); - const profileDiv = !profile ? ( -
-
Pubkey: {k}
-

No profile set

) -
- ) : ( -
- {profile.picture && } -
Name: {profile.name}
-
Pubkey: {k}
-
About: {profile.about}
- +
+
+

Settings

+

Manage your Nostrill configuration and preferences

+
+ +
+ {/* Appearance Section */} +
+
+ +

Appearance

+
+
+
+
+ +

Choose your preferred color theme

+
+
+ +
- ); - return ( -
- {profileDiv} +
+
+ + {/* Identity Section */} +
+
+ +

Identity

+
+
+
+
+ +

Your unique identifier on the Nostr network

+
+
+
+ {key || "No key generated"} + +
+
- ); - })} -
- +
-
-
- - {Object.keys(relays).map((r) => ( - // TODO: add connect button to connect and disc to relay one by one -
-
{r}
- + + {/* Nostr Relays Section */} +
+
+ +

Nostr Relays

+
+
+
+
+ +

Manage your Nostr relay connections

+
+
+
+ {Object.keys(relays).length === 0 ? ( +
+ +

No relays configured

+
+ ) : ( + Object.keys(relays).map((url) => ( +
+
+ {url} + Connected +
+ +
+ )) + )} + +
+
+ setNewRelay(e.target.value)} + onKeyPress={handleKeyPress} + placeholder="wss://relay.example.com" + className="relay-input" + /> + +
+
+
+
+
- ))} -
- - setNewRelay(e.target.value)} - /> -
-- cgit v1.2.3