feat: redesign relay screen
This commit is contained in:
@@ -355,11 +355,11 @@ export class Ark {
|
||||
|
||||
public async getAllRelaysFromContacts() {
|
||||
const fetcher = NostrFetcher.withCustomPool(ndkAdapter(this.ndk));
|
||||
const connectedRelays = this.ndk.pool
|
||||
.connectedRelays()
|
||||
.map((item) => item.url);
|
||||
|
||||
try {
|
||||
const LIMIT = 1;
|
||||
const connectedRelays = this.ndk.pool
|
||||
.connectedRelays()
|
||||
.map((item) => item.url);
|
||||
const relayMap = new Map<string, string[]>();
|
||||
const relayEvents = fetcher.fetchLatestEventsPerAuthor(
|
||||
{
|
||||
@@ -367,7 +367,7 @@ export class Ark {
|
||||
relayUrls: connectedRelays,
|
||||
},
|
||||
{ kinds: [NDKKind.RelayList] },
|
||||
LIMIT,
|
||||
1,
|
||||
);
|
||||
|
||||
for await (const { author, events } of relayEvents) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { useStorage } from "@lume/storage";
|
||||
import { NDKKind, NDKRelayUrl, NDKTag } from "@nostr-dev-kit/ndk";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useArk } from "./useArk";
|
||||
|
||||
export function useRelay() {
|
||||
export function useRelaylist() {
|
||||
const ark = useArk();
|
||||
const storage = useStorage();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const connectRelay = useMutation({
|
||||
@@ -15,7 +13,7 @@ export function useRelay() {
|
||||
) => {
|
||||
// Cancel any outgoing refetches
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["relays", ark.account.pubkey],
|
||||
queryKey: ["relay-personal"],
|
||||
});
|
||||
|
||||
// Snapshot the previous value
|
||||
@@ -42,17 +40,17 @@ export function useRelay() {
|
||||
});
|
||||
|
||||
// Optimistically update to the new value
|
||||
queryClient.setQueryData(
|
||||
["relays", ark.account.pubkey],
|
||||
(prev: NDKTag[]) => [...prev, ["r", relay, purpose ?? ""]],
|
||||
);
|
||||
queryClient.setQueryData(["relay-personal"], (prev: NDKTag[]) => [
|
||||
...prev,
|
||||
["r", relay, purpose ?? ""],
|
||||
]);
|
||||
|
||||
// Return a context object with the snapshotted value
|
||||
return { prevRelays };
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["relays", ark.account.pubkey],
|
||||
queryKey: ["relay-personal"],
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -61,7 +59,7 @@ export function useRelay() {
|
||||
mutationFn: async (relay: NDKRelayUrl) => {
|
||||
// Cancel any outgoing refetches
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["relays", ark.account.pubkey],
|
||||
queryKey: ["relay-personal"],
|
||||
});
|
||||
|
||||
// Snapshot the previous value
|
||||
@@ -81,14 +79,14 @@ export function useRelay() {
|
||||
});
|
||||
|
||||
// Optimistically update to the new value
|
||||
queryClient.setQueryData(["relays", ark.account.pubkey], prevRelays);
|
||||
queryClient.setQueryData(["relay-personal"], prevRelays);
|
||||
|
||||
// Return a context object with the snapshotted value
|
||||
return { prevRelays };
|
||||
},
|
||||
onSettled: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["relays", ark.account.pubkey],
|
||||
queryKey: ["relay-personal"],
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -4,7 +4,7 @@ export * from "./provider";
|
||||
export * from "./hooks/useEvent";
|
||||
export * from "./hooks/useArk";
|
||||
export * from "./hooks/useProfile";
|
||||
export * from "./hooks/useRelay";
|
||||
export * from "./hooks/useRelayList";
|
||||
export * from "./components/user";
|
||||
export * from "./components/column";
|
||||
export * from "./components/column/provider";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LoaderIcon } from "@lume/icons";
|
||||
import { NDKCacheAdapterTauri } from "@lume/ndk-cache-tauri";
|
||||
import { useStorage } from "@lume/storage";
|
||||
import { QUOTES, sendNativeNotification } from "@lume/utils";
|
||||
import { FETCH_LIMIT, QUOTES, sendNativeNotification } from "@lume/utils";
|
||||
import NDK, {
|
||||
NDKEvent,
|
||||
NDKKind,
|
||||
@@ -11,6 +11,7 @@ import NDK, {
|
||||
NDKRelayAuthPolicies,
|
||||
NDKUser,
|
||||
} from "@nostr-dev-kit/ndk";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { fetch } from "@tauri-apps/plugin-http";
|
||||
import Linkify from "linkify-react";
|
||||
import { normalizeRelayUrlSet } from "nostr-fetch";
|
||||
@@ -20,6 +21,7 @@ import { LumeContext } from "./context";
|
||||
|
||||
export const LumeProvider = ({ children }: PropsWithChildren<object>) => {
|
||||
const storage = useStorage();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [ark, setArk] = useState<Ark>(undefined);
|
||||
const [ndk, setNDK] = useState<NDK>(undefined);
|
||||
@@ -151,6 +153,56 @@ export const LumeProvider = ({ children }: PropsWithChildren<object>) => {
|
||||
{ closeOnEose: false, groupable: false },
|
||||
);
|
||||
|
||||
// prefetch activty
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ["activity"],
|
||||
initialPageParam: 0,
|
||||
queryFn: async ({
|
||||
signal,
|
||||
pageParam,
|
||||
}: {
|
||||
signal: AbortSignal;
|
||||
pageParam: number;
|
||||
}) => {
|
||||
const events = await ark.getInfiniteEvents({
|
||||
filter: {
|
||||
kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Zap],
|
||||
"#p": [ark.account.pubkey],
|
||||
},
|
||||
limit: FETCH_LIMIT,
|
||||
pageParam,
|
||||
signal,
|
||||
});
|
||||
|
||||
return events;
|
||||
},
|
||||
});
|
||||
|
||||
// prefetch timeline
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ["timeline-9999"],
|
||||
initialPageParam: 0,
|
||||
queryFn: async ({
|
||||
signal,
|
||||
pageParam,
|
||||
}: {
|
||||
signal: AbortSignal;
|
||||
pageParam: number;
|
||||
}) => {
|
||||
const events = await ark.getInfiniteEvents({
|
||||
filter: {
|
||||
kinds: [NDKKind.Text, NDKKind.Repost],
|
||||
authors: ark.account.contacts,
|
||||
},
|
||||
limit: FETCH_LIMIT,
|
||||
pageParam,
|
||||
signal,
|
||||
});
|
||||
|
||||
return events;
|
||||
},
|
||||
});
|
||||
|
||||
sub.addListener("event", async (event: NDKEvent) => {
|
||||
const profile = await ark.getUserProfile(event.pubkey);
|
||||
switch (event.kind) {
|
||||
|
||||
Reference in New Issue
Block a user