Add follow/unfollow (NIP-02) from profile view

- publishContactList (kind 3) in nostr lib — replaces full follow list on each change
- follow() and unfollow() actions in user store with optimistic UI update
- Follow/Unfollow button in ProfileView header (visible when logged in, not own profile)
- Button shows "unfollow" in muted style with danger hover when already following

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jure
2026-03-09 17:25:34 +01:00
parent b0a477177d
commit 2960e7b279
4 changed files with 60 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import { create } from "zustand";
import { NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { getNDK } from "../lib/nostr";
import { getNDK, publishContactList } from "../lib/nostr";
import { nip19 } from "@nostr-dev-kit/ndk";
interface UserState {
@@ -16,6 +16,8 @@ interface UserState {
logout: () => void;
fetchOwnProfile: () => Promise<void>;
fetchFollows: () => Promise<void>;
follow: (pubkey: string) => Promise<void>;
unfollow: (pubkey: string) => Promise<void>;
}
export const useUserStore = create<UserState>((set, get) => ({
@@ -130,4 +132,19 @@ export const useUserStore = create<UserState>((set, get) => ({
// Non-critical
}
},
follow: async (pubkey: string) => {
const { follows } = get();
if (follows.includes(pubkey)) return;
const updated = [...follows, pubkey];
set({ follows: updated });
await publishContactList(updated);
},
unfollow: async (pubkey: string) => {
const { follows } = get();
const updated = follows.filter((pk) => pk !== pubkey);
set({ follows: updated });
await publishContactList(updated);
},
}));