wip: migrate to desktop2

This commit is contained in:
2024-02-12 20:04:45 +07:00
parent 1950cb59a2
commit ed52105c02
18 changed files with 172 additions and 177 deletions

View File

@@ -54,7 +54,7 @@ export class Ark {
const event = JSON.parse(cmd) as Event;
return event;
} catch (e) {
console.error(String(e));
return null;
}
}
@@ -66,7 +66,7 @@ export class Ark {
const cmd: Event[] = await invoke("get_text_events", { limit, until });
return cmd;
} catch (e) {
console.error(String(e));
return [];
}
}
@@ -120,7 +120,7 @@ export class Ark {
const cmd: Event[] = await invoke("get_event_thread", { id });
return cmd;
} catch (e) {
console.error(String(e));
return [];
}
}
@@ -165,8 +165,8 @@ export class Ark {
try {
const cmd: Metadata = await invoke("get_profile", { id });
return cmd;
} catch (e) {
console.error(String(e));
} catch {
return null;
}
}

View File

@@ -7,19 +7,14 @@ export function UserCover({ className }: { className?: string }) {
if (!user) {
return (
<div
className={cn(
"animate-pulse bg-neutral-300 dark:bg-neutral-700",
className,
)}
className={cn("animate-pulse bg-gray-3 dark:bg-gray-7", className)}
/>
);
}
if (user && !user.profile.banner) {
return (
<div
className={cn("bg-gradient-to-b from-sky-400 to-sky-200", className)}
/>
<div className={cn("bg-gradient-to-b from-sky-4 to-blue-2", className)} />
);
}

View File

@@ -2,11 +2,14 @@ import { LoaderIcon } from "@lume/icons";
import { cn } from "@lume/utils";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useArk } from "../../provider";
export function UserFollowButton({
target,
className,
}: { target: string; className?: string }) {
const ark = useArk();
const [t] = useTranslation();
const [loading, setLoading] = useState(false);
const [followed, setFollowed] = useState(false);

View File

@@ -37,7 +37,7 @@ export function UserNip05({ className }: { className?: string }) {
: user?.profile.nip05}
</p>
{!isLoading && verified ? (
<VerifiedIcon className="size-4 text-teal-500" />
<VerifiedIcon className="size-4 text-green-10" />
) : null}
</div>
);

View File

@@ -1,90 +0,0 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useArk } from "../provider";
export function useRelaylist() {
const ark = useArk();
const queryClient = useQueryClient();
const connectRelay = useMutation({
mutationFn: async (
relay: WebSocket["url"],
purpose?: "read" | "write" | undefined,
) => {
// Cancel any outgoing refetches
await queryClient.cancelQueries({
queryKey: ["relay-personal"],
});
const relayUrl = normalizeRelayUrl(relay);
// Snapshot the previous value
const prevRelays: NDKTag[] = queryClient.getQueryData(["relay-personal"]);
// create new relay list if not exist
if (!prevRelays) {
await ark.createEvent({
kind: NDKKind.RelayList,
tags: [["r", relay, purpose ?? ""]],
});
}
// add relay to exist list
const index = prevRelays.findIndex((el) => el[1] === relay);
if (index > -1) return;
await ark.createEvent({
kind: NDKKind.RelayList,
tags: [...prevRelays, ["r", relayUrl, purpose ?? ""]],
});
// Optimistically update to the new value
queryClient.setQueryData(["relay-personal"], (prev: NDKTag[]) => [
...prev,
["r", relayUrl, purpose ?? ""],
]);
// Return a context object with the snapshotted value
return { prevRelays };
},
onSettled: () => {
queryClient.invalidateQueries({
queryKey: ["relay-personal"],
});
},
});
const removeRelay = useMutation({
mutationFn: async (relay: WebSocket["url"]) => {
// Cancel any outgoing refetches
await queryClient.cancelQueries({
queryKey: ["relay-personal"],
});
// Snapshot the previous value
const prevRelays: NDKTag[] = queryClient.getQueryData(["relay-personal"]);
if (!prevRelays) return;
const index = prevRelays.findIndex((el) => el[1] === relay);
if (index > -1) prevRelays.splice(index, 1);
await ark.createEvent({
kind: NDKKind.RelayList,
tags: prevRelays,
});
// Optimistically update to the new value
queryClient.setQueryData(["relay-personal"], prevRelays);
// Return a context object with the snapshotted value
return { prevRelays };
},
onSettled: () => {
queryClient.invalidateQueries({
queryKey: ["relay-personal"],
});
},
});
return { connectRelay, removeRelay };
}