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 { getCurrent } from "@tauri-apps/api/webviewWindow"; import { useEffect, useRef, useState } from "react"; export function Column({ column, account, isScroll, isResize, }: { column: LumeColumn; account: string; isScroll: boolean; isResize: boolean; }) { const container = useRef(null); const webviewLabel = `column-${account}_${column.label}`; const [isCreated, setIsCreated] = useState(false); const repositionWebview = async () => { const newRect = container.current.getBoundingClientRect(); await invoke("reposition_column", { label: webviewLabel, x: newRect.x, y: newRect.y, }); }; const resizeWebview = async () => { const newRect = container.current.getBoundingClientRect(); await invoke("resize_column", { label: webviewLabel, width: newRect.width, height: newRect.height, }); }; useEffect(() => { if (isCreated) resizeWebview(); }, [isResize]); useEffect(() => { if (isScroll && isCreated) repositionWebview(); }, [isScroll]); useEffect(() => { const rect = container.current.getBoundingClientRect(); const url = `${column.content}?account=${account}&label=${column.label}&name=${column.name}`; // create new webview invoke("create_column", { label: webviewLabel, x: rect.x, y: rect.y, width: rect.width, height: rect.height, url, }).then(() => setIsCreated(true)); // close webview when unmounted return () => { invoke("close_column", { label: webviewLabel }); }; }, [account]); return (
{column.label !== "open" ? (
) : null}
); } 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}
); }