import { CancelIcon, CheckIcon } from "@lume/icons"; import type { LumeColumn } from "@lume/types"; import { cn } from "@lume/utils"; import { invoke } from "@tauri-apps/api/core"; import { listen } from "@tauri-apps/api/event"; import { getCurrent } from "@tauri-apps/api/webviewWindow"; import { useCallback, useEffect, useRef, useState } from "react"; type WindowEvent = { scroll: boolean; resize: boolean; }; export function Column({ column, account, }: { column: LumeColumn; account: string; }) { const container = useRef(null); const webviewLabel = `column-${account}_${column.label}`; const [isCreated, setIsCreated] = useState(false); const repositionWebview = useCallback(async () => { const newRect = container.current.getBoundingClientRect(); await invoke("reposition_column", { label: webviewLabel, x: newRect.x, y: newRect.y, }); }, []); const resizeWebview = useCallback(async () => { const newRect = container.current.getBoundingClientRect(); await invoke("resize_column", { label: webviewLabel, width: newRect.width, height: newRect.height, }); }, []); useEffect(() => { if (!isCreated) return; const unlisten = listen("child-webview", (data) => { if (data.payload.scroll) repositionWebview(); if (data.payload.resize) repositionWebview().then(() => resizeWebview()); }); return () => { unlisten.then((f) => f()); }; }, [isCreated]); useEffect(() => { if (!container?.current) return; const rect = container.current.getBoundingClientRect(); const url = `${column.content}?account=${account}&label=${column.label}&name=${column.name}`; const prop = { label: webviewLabel, x: rect.x, y: rect.y, width: rect.width, height: rect.height, url, }; // create new webview invoke("create_column", { column: prop }).then(() => { console.log("created: ", webviewLabel); setIsCreated(true); }); // close webview when unmounted return () => { invoke("close_column", { label: webviewLabel }).then(() => { console.log("closed: ", webviewLabel); }); }; }, [account]); return (
); } function Header({ label, name }: { label: string; name: string }) { const [title, setTitle] = useState(name); const [isChanged, setIsChanged] = useState(false); const saveNewTitle = async () => { const mainWindow = getCurrent(); await mainWindow.emit("columns", { type: "set_title", label, title }); // update search params // @ts-ignore, hahaha search.name = title; // reset state setIsChanged(false); }; const close = async () => { const mainWindow = getCurrent(); await mainWindow.emit("columns", { type: "remove", label }); }; useEffect(() => { if (title.length !== name.length) setIsChanged(true); }, [title]); return (
setTitle(e.currentTarget.textContent)} className="text-sm font-medium focus:outline-none" > {name}
{isChanged ? ( ) : null}
); }