mirror of
https://github.com/hoornet/vega.git
synced 2026-05-07 12:49:13 -07:00
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:
@@ -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);
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user