From 4b016c908dda2019f3bf89e5a3d2eae535e5fbd2 Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 18 Sep 2025 00:24:39 +0700 Subject: oioi --- desk/app/nostrill.hoon | 40 ++-- desk/lib/json/nostrill.hoon | 70 +++++-- desk/lib/nostrill/comms.hoon | 41 ++-- desk/lib/nostrill/follows.hoon | 40 ++++ desk/lib/nostrill/mutations.hoon | 4 +- desk/sur/nostrill.hoon | 11 +- desk/sur/nostrill/comms.hoon | 4 +- front/src/Router.tsx | 8 + front/src/components/Avatar.tsx | 26 ++- front/src/components/Icon.tsx | 10 +- front/src/components/ProfileEditor.tsx | 280 ------------------------- front/src/components/modals/UserModal.tsx | 65 ++++++ front/src/components/post/Post.tsx | 1 + front/src/components/profile/Editor.tsx | 262 ++++++++++++++++++++++++ front/src/components/profile/Profile.tsx | 67 ++++++ front/src/logic/api.ts | 2 +- front/src/logic/nostrill.ts | 21 ++ front/src/logic/requests/nostrill.ts | 16 +- front/src/pages/Feed.tsx | 10 +- front/src/pages/User.tsx | 85 ++++++-- front/src/state/state.ts | 14 +- front/src/styles/Profile.css | 325 ++++++++++++++++++++++++++++++ front/src/styles/ProfileEditor.css | 325 ------------------------------ front/src/styles/feed.css | 7 +- front/src/types/nostrill.ts | 1 + 25 files changed, 995 insertions(+), 740 deletions(-) create mode 100644 desk/lib/nostrill/follows.hoon delete mode 100644 front/src/components/ProfileEditor.tsx create mode 100644 front/src/components/modals/UserModal.tsx create mode 100644 front/src/components/profile/Editor.tsx create mode 100644 front/src/components/profile/Profile.tsx create mode 100644 front/src/styles/Profile.css delete mode 100644 front/src/styles/ProfileEditor.css diff --git a/desk/app/nostrill.hoon b/desk/app/nostrill.hoon index 17732e7..cbd1c2f 100644 --- a/desk/app/nostrill.hoon +++ b/desk/app/nostrill.hoon @@ -1,7 +1,7 @@ /- sur=nostrill, nsur=nostr /+ lib=nostrill, nlib=nostr, sr=sortug, shim, dbug, muta=nostrill-mutations, jsonlib=json-nostrill, - trill=trill-post, comms=nostrill-comms + trill=trill-post, comms=nostrill-comms, followlib=follows /= web /web/router |% +$ versioned-state $%(state-0:sur) @@ -17,6 +17,7 @@ mutat ~(. muta [state bowl]) shimm ~(. shim [state bowl]) coms ~(. comms [state bowl]) + fols ~(. followlib [state bowl]) ++ on-init ^- (quip card:agent:gall agent:gall) =/ default (default-state:lib bowl) @@ -31,11 +32,11 @@ ++ on-load |~ old-state=vase ^- (quip card:agent:gall agent:gall) - =/ old-state !<(versioned-state old-state) - ?- -.old-state - %0 `this(state old-state) - == - :: `this(state (default-state:lib bowl)) + :: =/ old-state !<(versioned-state old-state) + :: ?- -.old-state + :: %0 `this(state old-state) + :: == + `this(state (default-state:lib bowl)) :: ++ on-poke |~ [=mark =vase] @@ -97,7 +98,7 @@ =/ sp (build-sp:trill our.bowl our.bowl content.poke) =/ p (build-post:trill now.bowl pub.i.keys sp) =. state (add-to-feed:mutat p) - =/ profile (~(get by profiles) pub.i.keys) + =/ profile (~(get by profiles) [%urbit our.bowl]) =/ pw [p (some pub.i.keys) ~ ~ profile] =/ =fact:ui:sur [%post %add pw] =/ card (update-ui:cards fact) @@ -116,17 +117,21 @@ [cs this] == ++ handle-fols |= poke=fols-poke:ui:sur - ?- -.poke - %add `this - %del `this - == + =^ cs state + ?- -.poke + %add (handle-add:fols +.poke) + + %del (handle-del:fols +.poke) + == + [cs this] + ++ handle-prof |= poke=prof-poke:ui:sur ?- -.poke %add - =. profiles (~(put by profiles) pub.i.keys +.poke) + =. profiles (~(put by profiles) [%urbit our.bowl] +.poke) `this %del - =. profiles (~(del by profiles) pub.i.keys) + =. profiles (~(del by profiles) [%urbit our.bowl]) `this == ++ handle-rela |= poke=relay-poke:ui:sur @@ -243,12 +248,13 @@ |= =(pole knot) ~& on-watch=`path`pole ?+ pole !! + [%follow ~] :_ this (give-feed:coms pole) [%beg %feed ~] - :_ this give-feed:coms + :_ this (give-feed:coms pole) [%beg %thread ids=@t ~] =/ id (slaw:sr %uw ids.pole) ?~ id ~& error-parsing-ted-id=pole `this - :_ this (give-ted:coms u.id) + :_ this (give-ted:coms u.id pole) [%ui ~] ?> .=(our.bowl src.bowl) :_ this @@ -271,8 +277,10 @@ == :: ++ on-agent - |~ [wire sign:agent:gall] + |~ [wire=(pole knot) =sign:agent:gall] ^- (quip card:agent:gall agent:gall) + ~& on-agent=wire + ~& on-agent=sign `this :: ++ on-arvo diff --git a/desk/lib/json/nostrill.hoon b/desk/lib/json/nostrill.hoon index b5a619c..2edf7f4 100644 --- a/desk/lib/json/nostrill.hoon +++ b/desk/lib/json/nostrill.hoon @@ -36,35 +36,42 @@ :: TODO do we even need this :- sub-id (numb received.es) - ++ en-profiles |= m=(map @ux user-meta:nsur) + ++ en-profiles |= m=(map user:sur user-meta:nsur) %- pairs - %+ turn ~(tap by m) |= [key=@ux p=user-meta:nsur] - =/ jkey (hex:en:common key) + %+ turn ~(tap by m) |= [key=user:sur p=user-meta:nsur] + =/ jkey (user key) ?> ?=(%s -.jkey) :- +.jkey (user-meta:en:nostr p) ++ enfollowing - |= m=(map @ux feed:feed) + |= m=(map user:sur feed:feed) ^- json - %- pairs %+ turn ~(tap by m) |= [key=@ux f=feed:feed] - =/ jkey (hex:en:common key) + %- pairs %+ turn ~(tap by m) |= [key=user:sur f=feed:feed] + =/ jkey (user key) ?> ?=(%s -.jkey) :- +.jkey (feed:en:trill f) ++ engraph - |= m=(map @ux (set follow:sur)) + |= m=(map user:sur (set user:sur)) ^- json - %- pairs %+ turn ~(tap by m) |= [key=@ux s=(set follow:sur)] - =/ jkey (hex:en:common key) + %- pairs %+ turn ~(tap by m) |= [key=user:sur s=(set user:sur)] + =/ jkey (user key) ?> ?=(%s -.jkey) :- +.jkey - :- %a %+ turn ~(tap in s) |= f=follow:sur - %- pairs - :~ pubkey+(hex:en:common pubkey.f) - name+s+name.f - :- %relay ?~ relay.f ~ s+u.relay.f - == + :- %a %+ turn ~(tap in s) user + ++ follow + |= f=follow:sur + %- pairs + :~ pubkey+(hex:en:common pubkey.f) + name+s+name.f + :- %relay ?~ relay.f ~ s+u.relay.f + == + ++ user |= u=user:sur ^- json + ?- -.u + %urbit (patp:en:common +.u) + %nostr (hex:en:common +.u) + == :: ui facts ++ fact |= f=fact:ui:sur ^- json %+ frond %fact @@ -105,17 +112,27 @@ %ng [%s msg.res] == ++ resd |= rd=res-data:comms ^- json - %+ frond -.rd ?- -.rd - %feed (feed-with-cursor:en:trill +.rd) + %feed (user-data +.rd) :: TODO wrap it for nostr shit - %thread (full-node:en:trill +.rd) - %prof (user-meta:en:nostr +.rd) + %thread (frond -.rd (full-node:en:trill +.rd)) + == + ++ user-data + |= ud=[=fc:feed profile=(unit user-meta:nsur)] + %: pairs + feed+(feed-with-cursor:en:trill fc.ud) + :- %profile ?~ profile.ud ~ (user-meta:en:nostr u.profile.ud) + ~ == -- ++ de =, dejs-soft:format |% +++ user + %- of :~ + urbit+(se:de:common %p) + nostr+hex:de:common + == :: ui ++ ui %- of :~ @@ -128,8 +145,8 @@ == ++ ui-fols %- of :~ - add+hex:de:common - del+hex:de:common + add+user + del+user == ++ ui-begs %- of :~ @@ -143,9 +160,18 @@ == ++ ui-prof %- of :~ - add+user-meta:de:nostr + add+ui-meta del+ul == +++ ui-meta + %- ot :~ + name+so + about+so + picture+so + other+other-meta + == +++ other-meta |= jon=json + ?. ?=(%o -.jon) ~ (some p.jon) ++ ui-post %- of :~ add+de-post diff --git a/desk/lib/nostrill/comms.hoon b/desk/lib/nostrill/comms.hoon index 833c07d..87a63b2 100644 --- a/desk/lib/nostrill/comms.hoon +++ b/desk/lib/nostrill/comms.hoon @@ -9,7 +9,6 @@ ?- -.req %feed handle-feed %thread (handle-thread +.req) - %prof handle-prof == ++ handle-feed =/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl) @@ -21,49 +20,35 @@ =/ lp latest-page:feedlib =/ lp2 lp(count backlog.feed-perms.state) =/ =fc:feed (lp2 feed.state) - =/ crd (res-poke [%ok %feed fc]) + =/ prof (~(get by profiles.state) [%urbit our.bowl]) + =/ crd (res-poke [%ok %feed fc prof]) :_ state :~(crd) -++ give-feed +++ give-feed + |= pat=path ~& give-feed=src.bowl =/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl) ?. can :: TODO keep track of the requests at the feed-perms struct - (res-fact [%ng 'not allowed']) + (res-fact [%ng 'not allowed'] pat) :: =/ lp latest-page:feedlib =/ lp2 lp(count backlog.feed-perms.state) =/ =fc:feed (lp2 feed.state) - (res-fact [%ok %feed fc]) + =/ prof (~(get by profiles.state) [%urbit our.bowl]) + (res-fact [%ok %feed fc prof] pat) -++ give-ted |= id=@ +++ give-ted |= [id=@ pat=path] =/ ted (get:orm:feed feed.state id) ?~ ted - (res-fact [%ng 'no such thread']) + (res-fact [%ng 'no such thread'] pat) =/ can (can-access:gatelib src.bowl read.u.ted bowl) ?. can - (res-fact [%ng 'not allowed']) + (res-fact [%ng 'not allowed'] pat) :: =/ fn (node-to-full:feedlib u.ted feed.state) - (res-fact [%ok %thread fn]) + (res-fact [%ok %thread fn] pat) :: -++ handle-prof - =/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl) - ?. can - :: TODO keep track of the requests at the feed-perms struct - =/ crd (res-poke [%ng 'not allowed']) - :_ state :~(crd) - :: - :: TODO @p or keys... wat do - :: =/ up (~(get by profiles.state) our.bowl) - =/ up (~(get by profiles.state) pub.i.keys.state) - ?~ up - =/ crd (res-poke [%ng 'dont have one']) - :_ state :~(crd) - - =/ crd (res-poke [%ok %prof u.up]) - :_ state :~(crd) - ++ handle-thread |= id=@da =/ ted (get:orm:feed feed.state id) ?~ ted @@ -85,8 +70,8 @@ =/ =poke:comms [%res res] =/ cage [%noun !>(poke)] [%pass /poke %agent [src.bowl dap.bowl] %poke cage] -++ res-fact |= =res:comms ^- (list card:agent:gall) - =/ paths ~[/beg/feed] +++ res-fact |= [=res:comms pat=path] ^- (list card:agent:gall) + =/ paths ~[pat] =/ =poke:comms [%res res] ~& > giving-res-fact=res =/ jon (beg-res:en:jsonlib res) diff --git a/desk/lib/nostrill/follows.hoon b/desk/lib/nostrill/follows.hoon new file mode 100644 index 0000000..c2eb987 --- /dev/null +++ b/desk/lib/nostrill/follows.hoon @@ -0,0 +1,40 @@ +/- sur=nostrill, nsur=nostr, comms=nostrill-comms, feed=trill-feed +/+ js=json-nostr, sr=sortug, nlib=nostr, constants, gatelib=trill-gate, feedlib=trill-feed, jsonlib=json-nostrill +|_ [=state:sur =bowl:gall] +++ handle-add |= =user:sur + ^- (quip card:agent:gall _state) + ?- -.user + %urbit =/ c (urbit-watch +.user) + :- :~(c) state + %nostr `state + == +++ handle-del |= =user:sur + ^- (quip card:agent:gall _state) + =. following.state (~(del by following.state) user) + =/ graph (~(get by follow-graph.state) [%urbit our.bowl]) + ?~ graph `state + =/ nset (~(del in u.graph) user) + =. follow-graph.state (~(put by follow-graph.state) [%urbit our.bowl] nset) + `state +++ handle-follow-ok |= [=user:sur =feed:feed profile=(unit user-meta:nsur)] + ^- (quip card:agent:gall _state) + =. following (~(put by following) user feed) + =. profiles ?~ profile profiles (~(put by profiles) user u.profile) + `state + + +++ urbit-watch |= sip=@p ^- card:agent:gall + [%pass /watch %agent [sip dap.bowl] %watch /follow] + +:: ++ res-fact |= =res:comms ^- (list card:agent:gall) +:: =/ paths ~[/beg/feed] +:: =/ =poke:comms [%res res] +:: ~& > giving-res-fact=res +:: =/ jon (beg-res:en:jsonlib res) +:: =/ cage [%json !>(jon)] +:: :~ +:: [%give %fact paths cage] +:: [%give %kick paths ~] +:: == + +-- diff --git a/desk/lib/nostrill/mutations.hoon b/desk/lib/nostrill/mutations.hoon index f493bcf..8fca2b2 100644 --- a/desk/lib/nostrill/mutations.hoon +++ b/desk/lib/nostrill/mutations.hoon @@ -181,7 +181,7 @@ ?~ ujon ~& failed-parse-metadata=ujon `state =/ umeta (user-meta:de:njs u.ujon) ?~ umeta ~& >> failed-dejs-metadata=ujon `state - =. profiles.state (~(put by profiles.state) pubkey.event u.umeta) + =. profiles.state (~(put by profiles.state) [%nostr pubkey.event] u.umeta) `state @@ -224,7 +224,7 @@ `state ++ parse-follow ^- (quip card _state) - =/ following (~(get by follow-graph.state) pubkey.event) + =/ following (~(get by follow-graph.state) [%nostr pubkey.event]) =/ follow-set ?~ following *(set follow:sur) u.following |- ?~ tags.event `state =/ t=tag:nsur i.tags.event diff --git a/desk/sur/nostrill.hoon b/desk/sur/nostrill.hoon index 70ce480..a091dd0 100644 --- a/desk/sur/nostrill.hoon +++ b/desk/sur/nostrill.hoon @@ -12,9 +12,9 @@ :: nostr feed from relays =nostr-feed :: profiles - profiles=(map @ux user-meta:nostr) - following=(map @ux =feed:trill) - follow-graph=(map @ux (set follow)) + profiles=(map user user-meta:nostr) + following=(map user =feed:trill) + follow-graph=(map user (set user)) :: TODO global feed somehow? == @@ -29,6 +29,7 @@ $: pub=(unit @ux) relay=(unit @t) pr=(unit user-meta:nostr) == ++$ user $%([%urbit p=@p] [%nostr p=@ux]) +$ follow [pubkey=@ux name=@t relay=(unit @t)] ++ ui @@ -52,8 +53,8 @@ $: pub=(unit @ux) [%del pubkey=@ux] == +$ fols-poke - $% [%add pubkey=@ux] - [%del pubkey=@ux] + $% [%add =user] + [%del =user] == +$ prof-poke $% [%add meta=user-meta:nostr] diff --git a/desk/sur/nostrill/comms.hoon b/desk/sur/nostrill/comms.hoon index d3dc8e1..4930235 100644 --- a/desk/sur/nostrill/comms.hoon +++ b/desk/sur/nostrill/comms.hoon @@ -8,15 +8,13 @@ +$ req $% [%feed ~] [%thread id=@da] - [%prof ~] == +$ res $% [%ok p=res-data] [%ng msg=@t] == +$ res-data - $% [%feed =fc:feed] + $% [%feed =fc:feed profile=(unit user-meta:nsur)] [%thread p=full-node:post] - [%prof p=user-meta:nsur] == -- diff --git a/front/src/Router.tsx b/front/src/Router.tsx index 83d212f..1293709 100644 --- a/front/src/Router.tsx +++ b/front/src/Router.tsx @@ -27,3 +27,11 @@ function toGlobal() { export function P404() { return

404

; } +export function ErrorPage({ msg }: { msg: string }) { + return ( +
+ +

{msg}

+
+ ); +} diff --git a/front/src/components/Avatar.tsx b/front/src/components/Avatar.tsx index 0f3dc90..a071655 100644 --- a/front/src/components/Avatar.tsx +++ b/front/src/components/Avatar.tsx @@ -1,20 +1,21 @@ import useLocalState from "@/state/state"; -import type { Ship } from "@/types/urbit"; import Sigil from "./Sigil"; -import ShipModal from "./modals/ShipModal"; import { isValidPatp } from "urbit-ob"; -import type { UserProfile } from "@/types/nostrill"; +import type { UserProfile, UserType } from "@/types/nostrill"; import Icon from "@/components/Icon"; +import UserModal from "./modals/UserModal"; export default function ({ - p, + user, + userString, size, color, noClickOnName, profile, picOnly = false, }: { - p: Ship; + user: UserType; + userString: string; size: number; color?: string; noClickOnName?: boolean; @@ -23,10 +24,11 @@ export default function ({ }) { const { setModal } = useLocalState((s) => ({ setModal: s.setModal })); // TODO revisit this when %whom updates + console.log({ profile }); const avatarInner = profile ? ( - - ) : isValidPatp(p) ? ( - + + ) : "urbit" in user && isValidPatp(user.urbit) ? ( + ) : ( ); @@ -41,14 +43,18 @@ export default function ({ function openModal(e: React.MouseEvent) { if (noClickOnName) return; e.stopPropagation(); - setModal(); + setModal(); } const name = (
{profile ? (

{profile.name}

+ ) : "urbit" in user ? ( +

+ {user.urbit.length > 28 ? "Anon" : user.urbit} +

) : ( -

{p.length > 28 ? "Anon" : p}

+

{user.nostr}

)}
); diff --git a/front/src/components/Icon.tsx b/front/src/components/Icon.tsx index a316e08..797a87b 100644 --- a/front/src/components/Icon.tsx +++ b/front/src/components/Icon.tsx @@ -65,7 +65,7 @@ interface IconProps { size?: number; className?: string; title?: string; - onClick?: (e?: React.MouseEvent) => void; + onClick?: (e: React.MouseEvent) => any; color?: "primary" | "text" | "textSecondary" | "textMuted" | "custom"; customColor?: string; } @@ -84,7 +84,11 @@ const Icon: React.FC = ({ // Simple filter based on theme - icons should match text const getFilter = () => { // For dark themes, invert the black SVGs to white - if (theme.name === "dark" || theme.name === "noir" || theme.name === "gruvbox") { + if ( + theme.name === "dark" || + theme.name === "noir" || + theme.name === "gruvbox" + ) { return "invert(1)"; } // For light themes with dark text, keep as is @@ -130,4 +134,4 @@ const Icon: React.FC = ({ ); }; -export default Icon; \ No newline at end of file +export default Icon; diff --git a/front/src/components/ProfileEditor.tsx b/front/src/components/ProfileEditor.tsx deleted file mode 100644 index 9a7493f..0000000 --- a/front/src/components/ProfileEditor.tsx +++ /dev/null @@ -1,280 +0,0 @@ -import { useState, useEffect } from "react"; -import type { UserProfile } from "@/types/nostrill"; -import useLocalState from "@/state/state"; -import Icon from "@/components/Icon"; -import toast from "react-hot-toast"; -import Avatar from "./Avatar"; - -interface ProfileEditorProps { - ship: string; - onSave?: () => void; -} - -const ProfileEditor: React.FC = ({ ship, onSave }) => { - const { api, profiles } = useLocalState((s) => ({ - api: s.api, - profiles: s.profiles, - })); - const isOwnProfile = ship === api?.airlock.our; - - // Initialize state with existing profile or defaults - const existingProfile = profiles.get(ship); - const [name, setName] = useState(existingProfile?.name || ""); - const [picture, setPicture] = useState(existingProfile?.picture || ""); - const [about, setAbout] = useState(existingProfile?.about || ""); - const [customFields, setCustomFields] = useState< - Array<{ key: string; value: string }> - >( - Object.entries(existingProfile?.other || {}).map(([key, value]) => ({ - key, - value, - })), - ); - const [isEditing, setIsEditing] = useState(false); - const [isSaving, setIsSaving] = useState(false); - - useEffect(() => { - const profile = profiles.get(ship); - if (profile) { - setName(profile.name || ""); - setPicture(profile.picture || ""); - setAbout(profile.about || ""); - setCustomFields( - Object.entries(profile.other || {}).map(([key, value]) => ({ - key, - value, - })), - ); - } - }, [ship, profiles]); - - const handleAddCustomField = () => { - setCustomFields([...customFields, { key: "", value: "" }]); - }; - - const handleUpdateCustomField = ( - index: number, - field: "key" | "value", - newValue: string, - ) => { - const updated = [...customFields]; - updated[index][field] = newValue; - setCustomFields(updated); - }; - - const handleRemoveCustomField = (index: number) => { - setCustomFields(customFields.filter((_, i) => i !== index)); - }; - - const handleSave = async () => { - setIsSaving(true); - try { - // Convert custom fields array to object - const other: Record = {}; - customFields.forEach(({ key, value }) => { - if (key.trim()) { - other[key.trim()] = value; - } - }); - - const profile: UserProfile = { - name, - picture, - about, - other, - }; - - // Call API to save profile - if (api && typeof api.createProfile === "function") { - await api.createProfile(profile); - } else { - throw new Error("Profile update API not available"); - } - - toast.success("Profile updated successfully"); - setIsEditing(false); - onSave?.(); - } catch (error) { - toast.error("Failed to update profile"); - console.error("Failed to save profile:", error); - } finally { - setIsSaving(false); - } - }; - - const handleCancel = () => { - // Reset to original values - const profile = profiles.get(ship); - if (profile) { - setName(profile.name || ""); - setPicture(profile.picture || ""); - setAbout(profile.about || ""); - setCustomFields( - Object.entries(profile.other || {}).map(([key, value]) => ({ - key, - value, - })), - ); - } - setIsEditing(false); - }; - - if (!isOwnProfile) { - // View-only mode for other users' profiles - no editing allowed - return ( -
-
- -
-
-

{name || ship}

- {about &&

{about}

} - - {customFields.length > 0 && ( -
-

Additional Info

- {customFields.map(({ key, value }, index) => ( -
- {key}: - {value} -
- ))} -
- )} -
-
- ); - } - - return ( -
-
-

Edit Profile

- {isOwnProfile && !isEditing && ( - - )} -
- - {isEditing ? ( -
-
- - setName(e.target.value)} - placeholder="Your display name" - /> -
- -
- - setPicture(e.target.value)} - placeholder="https://example.com/avatar.jpg" - /> -
- -
-
- -
- -