add follow/unfollow function

This commit is contained in:
Ren Amamiya
2023-06-27 16:12:21 +07:00
parent 6abff45678
commit a29ef03198
9 changed files with 85 additions and 69 deletions

View File

@@ -0,0 +1,27 @@
import { useAccount } from "./useAccount";
import { RelayContext } from "@shared/relayProvider";
import { useQuery } from "@tanstack/react-query";
import { nip02ToArray } from "@utils/transform";
import { useContext } from "react";
export function useFollows() {
const ndk = useContext(RelayContext);
const { account } = useAccount();
const { status, data: follows } = useQuery(
["follows", account.pubkey],
async () => {
const res = await ndk.fetchEvents({
kinds: [3],
authors: [account.pubkey],
});
const latest = [...res].slice(-1)[0];
const list = nip02ToArray(latest.tags);
return list;
},
{
enabled: account ? true : false,
},
);
return { status, follows };
}

View File

@@ -1,23 +0,0 @@
// `usePageContext` allows us to access `pageContext` in any React component.
// See https://vite-plugin-ssr.com/pageContext-anywhere
import type { PageContext } from "@renderer/types";
import { createContext, useContext } from "react";
const Context = createContext<PageContext>(undefined as any);
export function PageContextProvider({
pageContext,
children,
}: {
pageContext: PageContext;
children: React.ReactNode;
}) {
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
}
// eslint-disable-next-line react-refresh/only-export-components
export function usePageContext() {
const pageContext = useContext(Context);
return pageContext;
}