refactor: app settings

This commit is contained in:
2024-10-30 10:57:43 +07:00
parent 11dcef4e87
commit 618a45d349
33 changed files with 617 additions and 629 deletions

View File

@@ -1,5 +1,5 @@
import { commands } from "@/commands.gen";
import { appColumns, cn } from "@/commons";
import { cn } from "@/commons";
import { PublishIcon } from "@/components";
import { User } from "@/components/user";
import { LumeWindow } from "@/system";
@@ -14,6 +14,7 @@ import {
import { listen } from "@tauri-apps/api/event";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
import { message } from "@tauri-apps/plugin-dialog";
import { useCallback, useEffect } from "react";
export const Route = createLazyFileRoute("/_app")({
@@ -107,7 +108,7 @@ function Account({ pubkey }: { pubkey: string }) {
const items = await Promise.all([
MenuItem.new({
text: "Activate",
text: "Unlock",
enabled: !isActive || true,
action: async () => await commands.setSigner(pubkey),
}),
@@ -116,10 +117,31 @@ function Account({ pubkey }: { pubkey: string }) {
text: "View Profile",
action: () => LumeWindow.openProfile(pubkey),
}),
MenuItem.new({
text: "Update Profile",
action: () =>
LumeWindow.openPopup(
`${pubkey}/set-profile`,
"Update Profile",
true,
),
}),
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
text: "Copy Public Key",
action: async () => await writeText(pubkey),
}),
MenuItem.new({
text: "Copy Private Key",
action: async () => {
const res = await commands.getPrivateKey(pubkey);
if (res.status === "ok") {
await writeText(res.data);
} else {
await message(res.error, { kind: "error" });
}
},
}),
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
text: "Settings",
@@ -127,20 +149,13 @@ function Account({ pubkey }: { pubkey: string }) {
}),
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
text: "Delete Account",
text: "Logout",
action: async () => {
const res = await commands.deleteAccount(pubkey);
if (res.status === "ok") {
router.invalidate();
// Delete column associate with this account
appColumns.setState((prev) =>
prev.filter((col) =>
col.account ? col.account !== pubkey : col,
),
);
// Check remain account
const newAccounts = context.accounts.filter(
(account) => account !== pubkey,
@@ -176,6 +191,7 @@ function Account({ pubkey }: { pubkey: string }) {
<button
type="button"
onClick={(e) => showContextMenu(e)}
onContextMenu={(e) => showContextMenu(e)}
className="h-10 relative"
>
<User.Provider pubkey={pubkey}>