This commit is contained in:
2024-10-27 09:57:56 +07:00
parent 1e95a2fd95
commit eb6e3e52df
8 changed files with 113 additions and 209 deletions

View File

@@ -200,9 +200,9 @@ async getGroup(id: string) : Promise<Result<string, string>> {
else return { status: "error", error: e as any };
}
},
async getAllGroups() : Promise<Result<RichEvent[], string>> {
async getAllGroups(id: string) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_groups") };
return { status: "ok", data: await TAURI_INVOKE("get_all_groups", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
@@ -224,9 +224,9 @@ async getInterest(id: string) : Promise<Result<string, string>> {
else return { status: "error", error: e as any };
}
},
async getAllInterests() : Promise<Result<RichEvent[], string>> {
async getAllInterests(id: string) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_interests") };
return { status: "ok", data: await TAURI_INVOKE("get_all_interests", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };

View File

@@ -1,7 +1,11 @@
import type { RichEvent } from "@/commands.gen";
import { Spinner } from "@/components";
import type { QueryClient } from "@tanstack/react-query";
import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";
import { listen } from "@tauri-apps/api/event";
import type { OsType } from "@tauri-apps/plugin-os";
import { nip19 } from "nostr-tools";
import { useEffect } from "react";
interface RouterContext {
queryClient: QueryClient;
@@ -15,6 +19,25 @@ export const Route = createRootRouteWithContext<RouterContext>()({
});
function Screen() {
const { queryClient } = Route.useRouteContext();
useEffect(() => {
const unlisten = listen<RichEvent>("event", async (data) => {
const event = JSON.parse(data.payload.raw);
if (event.kind === 0) {
const npub = nip19.npubEncode(event.pubkey);
await queryClient.invalidateQueries({
queryKey: ["profile", npub, event.pubkey],
});
}
});
return () => {
unlisten.then((f) => f());
};
}, []);
return <Outlet />;
}

View File

@@ -4,35 +4,19 @@ import { Spinner, User } from "@/components";
import { LumeWindow } from "@/system";
import type { LumeColumn, NostrEvent } from "@/types";
import { ArrowClockwise, Plus } from "@phosphor-icons/react";
import * as Progress from "@radix-ui/react-progress";
import * as ScrollArea from "@radix-ui/react-scroll-area";
import { useQuery } from "@tanstack/react-query";
import { createLazyFileRoute } from "@tanstack/react-router";
import { Channel } from "@tauri-apps/api/core";
import { resolveResource } from "@tauri-apps/api/path";
import { readTextFile } from "@tauri-apps/plugin-fs";
import { nanoid } from "nanoid";
import { useCallback, useEffect, useState } from "react";
import { useCallback } from "react";
export const Route = createLazyFileRoute("/columns/_layout/launchpad/$id")({
component: Screen,
});
function Screen() {
const { id } = Route.useParams();
const { isLoading, data: isSync } = useQuery({
queryKey: ["is-sync", id],
queryFn: async () => {
const res = await commands.isAccountSync(id);
if (res.status === "ok") {
return res.data;
} else {
return false;
}
},
});
return (
<ScrollArea.Root
type={"scroll"}
@@ -40,17 +24,9 @@ function Screen() {
className="overflow-hidden size-full"
>
<ScrollArea.Viewport className="relative h-full px-3 pb-3">
{isLoading ? (
<Spinner className="size-4" />
) : !isSync ? (
<SyncProgress />
) : (
<>
<Groups />
<Interests />
<Core />
</>
)}
<Groups />
<Interests />
<Core />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
className="flex select-none touch-none p-0.5 duration-[160ms] ease-out data-[orientation=vertical]:w-2"
@@ -63,6 +39,7 @@ function Screen() {
);
}
/*
function SyncProgress() {
const { id } = Route.useParams();
const { queryClient } = Route.useRouteContext();
@@ -128,12 +105,14 @@ function SyncProgress() {
</div>
);
}
*/
function Groups() {
const { id } = Route.useParams();
const { isLoading, isError, error, data, refetch, isRefetching } = useQuery({
queryKey: ["others", "groups"],
queryKey: ["others", "groups", id],
queryFn: async () => {
const res = await commands.getAllGroups();
const res = await commands.getAllGroups(id);
if (res.status === "ok") {
const data = toLumeEvents(res.data);
@@ -254,10 +233,11 @@ function Groups() {
}
function Interests() {
const { id } = Route.useParams();
const { isLoading, isError, error, data, refetch, isRefetching } = useQuery({
queryKey: ["others", "interests"],
queryKey: ["others", "interests", id],
queryFn: async () => {
const res = await commands.getAllInterests();
const res = await commands.getAllInterests(id);
if (res.status === "ok") {
const data = toLumeEvents(res.data);