chore: clean up
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { appSettings, cn } from "@/commons";
|
||||
import { LumeWindow } from "@/system";
|
||||
import { Lightning } from "@phosphor-icons/react";
|
||||
import { useSearch } from "@tanstack/react-router";
|
||||
import { useStore } from "@tanstack/react-store";
|
||||
import { useNoteContext } from "../provider";
|
||||
|
||||
export function NoteZap({ large = false }: { large?: boolean }) {
|
||||
const search = useSearch({ strict: false });
|
||||
const visible = useStore(appSettings, (state) => state.display_zap_button);
|
||||
const event = useNoteContext();
|
||||
|
||||
@@ -13,7 +15,7 @@ export function NoteZap({ large = false }: { large?: boolean }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => LumeWindow.openZap(event.id)}
|
||||
onClick={() => LumeWindow.openZap(event.id, search.account)}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center text-neutral-800 dark:text-neutral-200",
|
||||
large
|
||||
|
||||
@@ -2,8 +2,7 @@ import { cn } from "@/commons";
|
||||
import { Spinner } from "@/components";
|
||||
import { Note } from "@/components/note";
|
||||
import { User } from "@/components/user";
|
||||
import { type LumeEvent, NostrQuery } from "@/system";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { type LumeEvent, useEvent } from "@/system";
|
||||
import { memo } from "react";
|
||||
|
||||
export const RepostNote = memo(function RepostNote({
|
||||
@@ -13,22 +12,7 @@ export const RepostNote = memo(function RepostNote({
|
||||
event: LumeEvent;
|
||||
className?: string;
|
||||
}) {
|
||||
const { isLoading, isError, data } = useQuery({
|
||||
queryKey: ["event", event.repostId],
|
||||
queryFn: async () => {
|
||||
try {
|
||||
const data = await NostrQuery.getRepostEvent(event);
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnReconnect: false,
|
||||
staleTime: Number.POSITIVE_INFINITY,
|
||||
retry: 2,
|
||||
});
|
||||
const { isLoading, isError, data } = useEvent(event.repostId);
|
||||
|
||||
return (
|
||||
<Note.Root
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
import { commands } from "@/commands.gen";
|
||||
import { cn } from "@/commons";
|
||||
import { Spinner } from "@/components";
|
||||
import { NostrAccount } from "@/system";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
import { message } from "@tauri-apps/plugin-dialog";
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { useTransition } from "react";
|
||||
import { useUserContext } from "./provider";
|
||||
|
||||
export function UserFollowButton({
|
||||
simple = false,
|
||||
className,
|
||||
}: {
|
||||
simple?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
export function UserFollowButton({ className }: { className?: string }) {
|
||||
const user = useUserContext();
|
||||
|
||||
const [followed, setFollowed] = useState(false);
|
||||
const { queryClient } = useRouteContext({ strict: false });
|
||||
const {
|
||||
isLoading,
|
||||
isError,
|
||||
data: isFollow,
|
||||
} = useQuery({
|
||||
queryKey: ["status", user.pubkey],
|
||||
queryFn: async () => {
|
||||
const res = await commands.checkContact(user.pubkey);
|
||||
|
||||
if (res.status === "ok") {
|
||||
return res.data;
|
||||
} else {
|
||||
throw new Error(res.error);
|
||||
}
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const toggleFollow = () => {
|
||||
@@ -23,7 +36,17 @@ export function UserFollowButton({
|
||||
const res = await commands.toggleContact(user.pubkey, null);
|
||||
|
||||
if (res.status === "ok") {
|
||||
setFollowed((prev) => !prev);
|
||||
queryClient.setQueryData(
|
||||
["status", user.pubkey],
|
||||
(prev: boolean) => !prev,
|
||||
);
|
||||
|
||||
// invalidate cache
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ["status", user.pubkey],
|
||||
});
|
||||
|
||||
return;
|
||||
} else {
|
||||
await message(res.error, { kind: "error" });
|
||||
return;
|
||||
@@ -31,18 +54,6 @@ export function UserFollowButton({
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
NostrAccount.checkContact(user.pubkey).then((status) => {
|
||||
if (mounted) setFollowed(status);
|
||||
});
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
@@ -50,15 +61,9 @@ export function UserFollowButton({
|
||||
onClick={() => toggleFollow()}
|
||||
className={cn("w-max", className)}
|
||||
>
|
||||
{isPending ? (
|
||||
<Spinner className="size-4" />
|
||||
) : followed ? (
|
||||
!simple ? (
|
||||
"Unfollow"
|
||||
) : null
|
||||
) : (
|
||||
"Follow"
|
||||
)}
|
||||
{isError ? "Error" : null}
|
||||
{isPending || isLoading ? <Spinner className="size-4" /> : null}
|
||||
{isFollow ? "Unfollow" : "Follow"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { commands } from "@/commands.gen";
|
||||
import { displayLongHandle, displayNpub } from "@/commons";
|
||||
import { NostrQuery } from "@/system";
|
||||
import { SealCheck } from "@phosphor-icons/react";
|
||||
import * as Tooltip from "@radix-ui/react-tooltip";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
@@ -10,14 +10,13 @@ export function UserNip05() {
|
||||
const { isLoading, data: verified } = useQuery({
|
||||
queryKey: ["nip05", user?.pubkey],
|
||||
queryFn: async () => {
|
||||
if (!user.profile?.nip05?.length) return false;
|
||||
const res = await commands.verifyNip05(user.pubkey, user.profile?.nip05);
|
||||
|
||||
const verify = await NostrQuery.verifyNip05(
|
||||
user.pubkey,
|
||||
user.profile?.nip05,
|
||||
);
|
||||
|
||||
return verify;
|
||||
if (res.status === "ok") {
|
||||
return res.data;
|
||||
} else {
|
||||
throw new Error(res.error);
|
||||
}
|
||||
},
|
||||
enabled: !!user.profile?.nip05?.length,
|
||||
refetchOnMount: false,
|
||||
|
||||
Reference in New Issue
Block a user