This commit is contained in:
2024-10-26 17:24:39 +07:00
parent 470dc1c759
commit 83d24351cd
13 changed files with 191 additions and 496 deletions

View File

@@ -336,14 +336,6 @@ async getReplies(id: string) : Promise<Result<RichEvent[], string>> {
else return { status: "error", error: e as any };
}
},
async subscribeTo(id: string) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("subscribe_to", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getAllEventsByAuthor(publicKey: string, limit: number) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_all_events_by_author", { publicKey, limit }) };
@@ -501,13 +493,6 @@ async openWindow(window: NewWindow) : Promise<Result<string, string>> {
/** user-defined events **/
export const events = __makeEvents__<{
negentropyEvent: NegentropyEvent,
subscription: Subscription
}>({
negentropyEvent: "negentropy-event",
subscription: "subscription"
})
/** user-defined constants **/
@@ -518,15 +503,12 @@ subscription: "subscription"
export type Column = { label: string; url: string; x: number; y: number; width: number; height: number }
export type Mention = { pubkey: string; avatar: string; display_name: string; name: string }
export type Meta = { content: string; images: string[]; events: string[]; mentions: string[]; hashtags: string[] }
export type NegentropyEvent = { kind: NegentropyKind; total_event: number }
export type NegentropyKind = "Profile" | "Metadata" | "Events" | "EventIds" | "Global" | "Notification" | "Others"
export type NewWindow = { label: string; title: string; url: string; width: number; height: number; maximizable: boolean; minimizable: boolean; hidden_title: boolean; closable: boolean }
export type Profile = { name: string; display_name: string; about: string | null; picture: string; banner: string | null; nip05: string | null; lud16: string | null; website: string | null }
export type Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null }
export type RichEvent = { raw: string; parsed: Meta | null }
export type Settings = { proxy: string | null; image_resize_service: string | null; use_relay_hint: boolean; content_warning: boolean; trusted_only: boolean; display_avatar: boolean; display_zap_button: boolean; display_repost_button: boolean; display_media: boolean; transparent: boolean }
export type Subscription = { label: string; kind: SubscriptionMethod; event_id: string | null; contacts: string[] | null }
export type SubscriptionMethod = "Subscribe" | "Unsubscribe"
export type TAURI_CHANNEL<TSend> = null
/** tauri-specta globals **/

View File

@@ -4,18 +4,10 @@ import type { LumeColumn } from "@/types";
import { CaretDown, Check } from "@phosphor-icons/react";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { getCurrentWindow } from "@tauri-apps/api/window";
import {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useState,
} from "react";
import { useCallback, useEffect, useLayoutEffect, useState } from "react";
import { User } from "./user";
export function Column({ column }: { column: LumeColumn }) {
const webviewLabel = useMemo(() => `column-${column.label}`, [column.label]);
const [rect, ref] = useRect();
const [_error, setError] = useState<string>("");
@@ -23,7 +15,7 @@ export function Column({ column }: { column: LumeColumn }) {
(async () => {
if (rect) {
const res = await commands.updateColumn(
webviewLabel,
column.label,
rect.width,
rect.height,
rect.x,
@@ -31,7 +23,7 @@ export function Column({ column }: { column: LumeColumn }) {
);
if (res.status === "ok") {
console.log("webview is updated: ", webviewLabel);
console.log("webview is updated: ", column.label);
} else {
console.log("webview error: ", res.error);
}
@@ -40,12 +32,13 @@ export function Column({ column }: { column: LumeColumn }) {
}, [rect]);
useLayoutEffect(() => {
console.log(column.label);
if (ref.current) {
const initialRect = ref.current.getBoundingClientRect();
commands
.createColumn({
label: webviewLabel,
label: column.label,
x: initialRect.x,
y: initialRect.y,
width: initialRect.width,
@@ -54,16 +47,16 @@ export function Column({ column }: { column: LumeColumn }) {
})
.then((res) => {
if (res.status === "ok") {
console.log("webview is created: ", webviewLabel);
console.log("webview is created: ", column.label);
} else {
setError(res.error);
}
});
return () => {
commands.closeColumn(webviewLabel).then((res) => {
commands.closeColumn(column.label).then((res) => {
if (res.status === "ok") {
console.log("webview is closed: ", webviewLabel);
console.log("webview is closed: ", column.label);
} else {
console.log("webview error: ", res.error);
}
@@ -77,7 +70,6 @@ export function Column({ column }: { column: LumeColumn }) {
<div className="flex flex-col gap-px size-full">
<Header
label={column.label}
webviewLabel={webviewLabel}
name={column.name}
account={column.account}
/>
@@ -89,10 +81,9 @@ export function Column({ column }: { column: LumeColumn }) {
function Header({
label,
webviewLabel,
name,
account,
}: { label: string; webviewLabel: string; name: string; account?: string }) {
}: { label: string; name: string; account?: string }) {
const [title, setTitle] = useState("");
const [isChanged, setIsChanged] = useState(false);
@@ -105,7 +96,7 @@ function Header({
MenuItem.new({
text: "Reload",
action: async () => {
await commands.reloadColumn(webviewLabel);
await commands.reloadColumn(label);
},
}),
PredefinedMenuItem.new({ item: "Separator" }),

View File

@@ -1,9 +1,7 @@
import { events } from "@/commands.gen";
import { Spinner } from "@/components";
import type { QueryClient } from "@tanstack/react-query";
import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";
import type { OsType } from "@tauri-apps/plugin-os";
import { useEffect } from "react";
interface RouterContext {
queryClient: QueryClient;
@@ -17,21 +15,6 @@ export const Route = createRootRouteWithContext<RouterContext>()({
});
function Screen() {
const { queryClient } = Route.useRouteContext();
useEffect(() => {
const unlisten = events.negentropyEvent.listen(async (data) => {
const queryKey = [data.payload.kind.toLowerCase()];
console.info("invalidate: ", queryKey);
await queryClient.refetchQueries({ queryKey });
});
return () => {
unlisten.then((f) => f());
};
}, []);
return <Outlet />;
}

View File

@@ -1,4 +1,4 @@
import { events, commands } from "@/commands.gen";
import { commands } from "@/commands.gen";
import { Note, ReplyNote, Spinner } from "@/components";
import { LumeEvent, useEvent } from "@/system";
import type { EventPayload } from "@/types";
@@ -91,7 +91,6 @@ function RootEvent() {
}
function ReplyList() {
const { label } = Route.useSearch();
const { id } = Route.useParams();
const { queryClient } = Route.useRouteContext();
const { data, isLoading } = useQuery({
@@ -179,28 +178,6 @@ function ReplyList() {
refetchOnWindowFocus: false,
});
useEffect(() => {
events.subscription
.emit({
label: label || id,
kind: "Subscribe",
event_id: id,
contacts: null,
})
.then(() => console.log("Subscribe: ", label));
return () => {
events.subscription
.emit({
label: label || id,
kind: "Unsubscribe",
event_id: id,
contacts: null,
})
.then(() => console.log("Unsubscribe: ", label));
};
}, []);
useEffect(() => {
const unlisten = getCurrentWindow().listen<EventPayload>(
"event",

View File

@@ -1,4 +1,4 @@
import { events, commands } from "@/commands.gen";
import { commands } from "@/commands.gen";
import { toLumeEvents } from "@/commons";
import { RepostNote, Spinner, TextNote } from "@/components";
import type { LumeEvent } from "@/system";
@@ -83,28 +83,6 @@ export function Screen() {
[data],
);
useEffect(() => {
events.subscription
.emit({
label: search.label as string,
kind: "Subscribe",
event_id: null,
contacts,
})
.then(() => console.log("Subscribe: ", search.label));
return () => {
events.subscription
.emit({
label: search.label as string,
kind: "Unsubscribe",
event_id: null,
contacts,
})
.then(() => console.log("Unsubscribe: ", search.label));
};
}, []);
useEffect(() => {
const unlisten = listen("synchronized", async () => {
await queryClient.refetchQueries({