From 5d59040224a74b030302d867797279264ea9ad56 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 19 Mar 2024 15:36:20 +0700 Subject: [PATCH] chore: follow up --- apps/desktop2/src/components/accounts.tsx | 96 ++--------------------- packages/icons/index.ts | 2 + packages/icons/src/laurel.tsx | 13 +++ packages/icons/src/link.tsx | 10 +-- packages/icons/src/quote.tsx | 13 +++ packages/icons/src/reply.tsx | 5 +- packages/icons/src/repost.tsx | 4 +- packages/icons/src/zap.tsx | 4 +- packages/types/index.d.ts | 7 ++ packages/ui/src/note/buttons/reply.tsx | 69 +++++----------- packages/ui/src/note/buttons/repost.tsx | 4 +- src-tauri/src/commands.rs | 1 + src-tauri/src/commands/window.rs | 69 ++++++++++++++++ src-tauri/src/main.rs | 3 + 14 files changed, 145 insertions(+), 155 deletions(-) create mode 100644 packages/icons/src/laurel.tsx create mode 100644 packages/icons/src/quote.tsx create mode 100644 src-tauri/src/commands/window.rs diff --git a/apps/desktop2/src/components/accounts.tsx b/apps/desktop2/src/components/accounts.tsx index fc8c0505..b9d22946 100644 --- a/apps/desktop2/src/components/accounts.tsx +++ b/apps/desktop2/src/components/accounts.tsx @@ -1,12 +1,8 @@ import { useArk } from "@lume/ark"; import { Account } from "@lume/types"; import { User } from "@lume/ui"; -import { useNavigate, useParams, useSearch } from "@tanstack/react-router"; +import { useNavigate, useParams } from "@tanstack/react-router"; import { useEffect, useState } from "react"; -import * as Popover from "@radix-ui/react-popover"; -import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; -import { BackupDialog } from "./backup"; -import { LoginDialog } from "./login"; export function Accounts() { const ark = useArk(); @@ -60,91 +56,11 @@ function Inactive({ pubkey }: { pubkey: string }) { } function Active({ pubkey }: { pubkey: string }) { - const ark = useArk(); - const navigate = useNavigate(); - - // @ts-ignore, magic !!! - const { guest } = useSearch({ strict: false }); - // @ts-ignore, magic !!! - const { account } = useParams({ strict: false }); - - if (guest) { - return ( - - - - - - -
-

- You're using random account -

-

- You can continue by claim and backup this account, or you can - import your own account. -

-
-
- - -
- -
-
-
- ); - } - return ( - - - - - - - - - - - - Add account - - ark.open_profile(account)} - className="group relative flex h-9 select-none items-center rounded-md px-3 text-sm font-medium leading-none outline-none hover:bg-neutral-900 dark:hover:bg-neutral-100" - > - Profile -
- ⌘+Shift+P -
-
- navigate({ to: "/", search: { manually: true } })} - className="group relative flex h-9 select-none items-center rounded-md px-3 text-sm font-medium leading-none outline-none hover:bg-neutral-900 dark:hover:bg-neutral-100" - > - Logout -
- ⌘+Shift+L -
-
- -
-
-
+ + + + + ); } diff --git a/packages/icons/index.ts b/packages/icons/index.ts index c8c62141..3259161d 100644 --- a/packages/icons/index.ts +++ b/packages/icons/index.ts @@ -120,3 +120,5 @@ export * from "./src/local"; export * from "./src/global"; export * from "./src/infoCircle"; export * from "./src/cancelCircle"; +export * from "./src/laurel"; +export * from "./src/quote"; diff --git a/packages/icons/src/laurel.tsx b/packages/icons/src/laurel.tsx new file mode 100644 index 00000000..bc2876ac --- /dev/null +++ b/packages/icons/src/laurel.tsx @@ -0,0 +1,13 @@ +export function LaurelIcon(props: JSX.IntrinsicElements["svg"]) { + return ( + + + + ); +} diff --git a/packages/icons/src/link.tsx b/packages/icons/src/link.tsx index 87ec9c23..5e941d3b 100644 --- a/packages/icons/src/link.tsx +++ b/packages/icons/src/link.tsx @@ -1,16 +1,12 @@ -import { SVGProps } from "react"; - -export function LinkIcon( - props: JSX.IntrinsicAttributes & SVGProps, -) { +export function LinkIcon(props: JSX.IntrinsicElements["svg"]) { return ( ); diff --git a/packages/icons/src/quote.tsx b/packages/icons/src/quote.tsx new file mode 100644 index 00000000..f8ae261c --- /dev/null +++ b/packages/icons/src/quote.tsx @@ -0,0 +1,13 @@ +export function QuoteIcon(props: JSX.IntrinsicElements["svg"]) { + return ( + + + + ); +} diff --git a/packages/icons/src/reply.tsx b/packages/icons/src/reply.tsx index 3c397914..7c41933d 100644 --- a/packages/icons/src/reply.tsx +++ b/packages/icons/src/reply.tsx @@ -3,10 +3,9 @@ export function ReplyIcon(props: JSX.IntrinsicElements["svg"]) { ); diff --git a/packages/icons/src/repost.tsx b/packages/icons/src/repost.tsx index c41afa98..dd0eb51d 100644 --- a/packages/icons/src/repost.tsx +++ b/packages/icons/src/repost.tsx @@ -5,8 +5,8 @@ export function RepostIcon(props: JSX.IntrinsicElements["svg"]) { stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" - strokeWidth="2" - d="m17.25 21 2.47-2.47a.75.75 0 0 0 0-1.06L17.25 15M6.75 3 4.28 5.47a.75.75 0 0 0 0 1.06L6.75 9M5 6h13a2 2 0 0 1 2 2v3M4 13v3a2 2 0 0 0 2 2h13" + strokeWidth="1.5" + d="m17.5 21.25 2.47-2.47a.75.75 0 0 0 0-1.06l-2.47-2.47m-11-12.5L4.03 5.22a.75.75 0 0 0 0 1.06L6.5 8.75m-1.25-3h13a2 2 0 0 1 2 2v3m-16.5 3v2.5a2 2 0 0 0 2 2h13" /> ); diff --git a/packages/icons/src/zap.tsx b/packages/icons/src/zap.tsx index c3fe1e5c..9a6188b9 100644 --- a/packages/icons/src/zap.tsx +++ b/packages/icons/src/zap.tsx @@ -4,8 +4,8 @@ export function ZapIcon(props: JSX.IntrinsicElements["svg"]) { ); diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index cb9d91d4..9c91d000 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -81,6 +81,7 @@ export interface RichContent { } export interface LumeColumn { + id: number; content: string; name: string; description?: string; @@ -88,6 +89,12 @@ export interface LumeColumn { logo?: string; } +export interface EventColumns { + type: "add" | "remove" | "update" | "left" | "right"; + id?: number; + column?: LumeColumn; +} + export interface Opengraph { url: string; title?: string; diff --git a/packages/ui/src/note/buttons/reply.tsx b/packages/ui/src/note/buttons/reply.tsx index b9948f0a..07de067e 100644 --- a/packages/ui/src/note/buttons/reply.tsx +++ b/packages/ui/src/note/buttons/reply.tsx @@ -1,9 +1,8 @@ -import { LinkIcon, ReplyIcon } from "@lume/icons"; +import { ReplyIcon } from "@lume/icons"; import * as Tooltip from "@radix-ui/react-tooltip"; import { useTranslation } from "react-i18next"; import { useNoteContext } from "../provider"; import { useArk } from "@lume/ark"; -import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; export function NoteReply() { const ark = useArk(); @@ -12,52 +11,24 @@ export function NoteReply() { const { t } = useTranslation(); return ( - - - - - - - - - - - {t("note.menu.viewThread")} - - - - - - - - - - - - - - - - - + + + + + + + + {t("note.menu.viewThread")} + + + + + ); } diff --git a/packages/ui/src/note/buttons/repost.tsx b/packages/ui/src/note/buttons/repost.tsx index 544242cf..759248cf 100644 --- a/packages/ui/src/note/buttons/repost.tsx +++ b/packages/ui/src/note/buttons/repost.tsx @@ -1,4 +1,4 @@ -import { LoaderIcon, ReplyIcon, RepostIcon } from "@lume/icons"; +import { LoaderIcon, QuoteIcon, ReplyIcon, RepostIcon } from "@lume/icons"; import { cn } from "@lume/utils"; import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import * as Tooltip from "@radix-ui/react-tooltip"; @@ -84,7 +84,7 @@ export function NoteRepost() { onClick={() => ark.open_editor(event.id, true)} className="inline-flex h-9 items-center gap-2 rounded-lg px-3 text-sm font-medium text-white hover:bg-neutral-900 focus:outline-none dark:text-black dark:hover:bg-neutral-100" > - + {t("note.buttons.quote")} diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 1434139e..99001bdc 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,2 +1,3 @@ pub mod folder; pub mod opg; +pub mod window; diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs new file mode 100644 index 00000000..4770662e --- /dev/null +++ b/src-tauri/src/commands/window.rs @@ -0,0 +1,69 @@ +use std::path::PathBuf; +use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl}; + +#[tauri::command] +pub fn create_column( + label: &str, + x: f32, + y: f32, + width: f32, + height: f32, + url: &str, + app_handle: tauri::AppHandle, +) -> Result { + match app_handle.get_window("main") { + Some(main_window) => match app_handle.get_webview(label) { + Some(_) => Err("Webview is exist".into()), + None => { + let path = PathBuf::from(url); + let webview_url = WebviewUrl::App(path); + let builder = tauri::webview::WebviewBuilder::new(label, webview_url) + .auto_resize() + .user_agent("Lume/4.0") + .transparent(true); + match main_window.add_child( + builder, + LogicalPosition::new(x, y), + LogicalSize::new(width, height), + ) { + Ok(webview) => Ok(webview.label().into()), + Err(_) => Err("Something is wrong".into()), + } + } + }, + None => Err("Main window not found".into()), + } +} + +#[tauri::command] +pub fn close_column(label: &str, app_handle: tauri::AppHandle) -> Result { + match app_handle.get_webview(label) { + Some(webview) => { + if let Ok(_) = webview.close() { + Ok(true) + } else { + Ok(false) + } + } + None => Err("Webview not found".into()), + } +} + +#[tauri::command] +pub fn reposition_column( + label: &str, + x: f32, + y: f32, + app_handle: tauri::AppHandle, +) -> Result<(), String> { + match app_handle.get_webview(label) { + Some(webview) => { + if let Ok(_) = webview.set_position(LogicalPosition::new(x, y)) { + Ok(()) + } else { + Err("Reposition column failed".into()) + } + } + None => Err("Webview not found".into()), + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a777881d..85260529 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -117,6 +117,9 @@ fn main() { commands::folder::show_in_folder, commands::folder::get_accounts, commands::opg::fetch_opg, + commands::window::create_column, + commands::window::close_column, + commands::window::reposition_column ]) .build(tauri::generate_context!()) .expect("error while running tauri application")