wip: rework multi account
This commit is contained in:
@@ -20,6 +20,7 @@ export const Route = createRootRouteWithContext<RouterContext>()({
|
||||
function Screen() {
|
||||
const { queryClient } = Route.useRouteContext();
|
||||
|
||||
/*
|
||||
useEffect(() => {
|
||||
const unlisten = events.newSettings.listen((data) => {
|
||||
appSettings.setState((state) => {
|
||||
@@ -31,6 +32,7 @@ function Screen() {
|
||||
unlisten.then((f) => f());
|
||||
};
|
||||
}, []);
|
||||
*/
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = events.negentropyEvent.listen(async (data) => {
|
||||
|
||||
+11
-36
@@ -9,7 +9,7 @@ import { Link, Outlet, createLazyFileRoute } from "@tanstack/react-router";
|
||||
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 { memo, useCallback, useEffect, useState } from "react";
|
||||
import { useCallback, useEffect } from "react";
|
||||
|
||||
export const Route = createLazyFileRoute("/_layout")({
|
||||
component: Layout,
|
||||
@@ -80,41 +80,6 @@ function Topbar() {
|
||||
);
|
||||
}
|
||||
|
||||
const NegentropyBadge = memo(function NegentropyBadge() {
|
||||
const [process, setProcess] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = listen("negentropy", async (data) => {
|
||||
if (data.payload === "Ok") {
|
||||
setProcess(null);
|
||||
} else {
|
||||
setProcess(data.payload);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlisten.then((f) => f());
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!process) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-7 w-max px-3 inline-flex items-center justify-center text-[9px] font-medium rounded-full bg-black/5 dark:bg-white/5">
|
||||
{process ? (
|
||||
<span>
|
||||
{process.message}
|
||||
{process.total_event > 0 ? ` / ${process.total_event}` : null}
|
||||
</span>
|
||||
) : (
|
||||
"Syncing"
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
function Account({ pubkey }: { pubkey: string }) {
|
||||
const navigate = Route.useNavigate();
|
||||
const context = Route.useRouteContext();
|
||||
@@ -183,6 +148,16 @@ function Account({ pubkey }: { pubkey: string }) {
|
||||
[pubkey],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = listen("signer-updated", async () => {
|
||||
await context.queryClient.invalidateQueries({ queryKey: ["signer"] });
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlisten.then((f) => f());
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -24,7 +24,7 @@ function Screen() {
|
||||
|
||||
const submit = () => {
|
||||
startTransition(async () => {
|
||||
if (!key.startsWith("nsec1") && !key.startsWith("ncryptsec")) {
|
||||
if (!key.startsWith("nsec") && !key.startsWith("ncryptsec")) {
|
||||
await message(
|
||||
"You need to enter a valid private key starts with nsec or ncryptsec",
|
||||
{ title: "Login", kind: "info" },
|
||||
@@ -32,15 +32,18 @@ function Screen() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.startsWith("nsec1") && !password.length) {
|
||||
await message("You must set password to secure your key", {
|
||||
if (key.startsWith("ncryptsec") && !password.length) {
|
||||
await message("You must enter a password to decrypt your key", {
|
||||
title: "Login",
|
||||
kind: "info",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await commands.importAccount(key, password);
|
||||
const res = await commands.importAccount(
|
||||
key,
|
||||
password.length ? password : null,
|
||||
);
|
||||
|
||||
if (res.status === "ok") {
|
||||
navigate({ to: "/", replace: true });
|
||||
@@ -94,15 +97,13 @@ function Screen() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{key.length ? (
|
||||
{key.startsWith("ncryptsec") ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<label
|
||||
htmlFor="password"
|
||||
className="text-sm font-medium text-neutral-800 dark:text-neutral-200"
|
||||
>
|
||||
{!key.startsWith("ncryptsec")
|
||||
? "Set password to secure your key"
|
||||
: "Enter password to decrypt your key"}
|
||||
Enter password to decrypt your key
|
||||
</label>
|
||||
<input
|
||||
name="password"
|
||||
|
||||
@@ -26,7 +26,7 @@ function Screen() {
|
||||
if (!key.startsWith("npub") && !key.startsWith("nprofile")) {
|
||||
await message(
|
||||
"You need to enter a valid public key starts with npub or nprofile",
|
||||
{ title: "Login", kind: "info" },
|
||||
{ kind: "info" },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function Screen() {
|
||||
queryKey: ["events", "newsfeed", search.label],
|
||||
initialPageParam: 0,
|
||||
queryFn: async ({ pageParam }: { pageParam: number }) => {
|
||||
const until = pageParam > 0 ? pageParam.toString() : undefined;
|
||||
const until = pageParam > 0 ? pageParam.toString() : null;
|
||||
const res = await commands.getAllEventsByAuthors(contacts, until);
|
||||
|
||||
if (res.status === "error") {
|
||||
@@ -76,9 +76,9 @@ export function Screen() {
|
||||
useEffect(() => {
|
||||
events.subscription
|
||||
.emit({
|
||||
label: search.label,
|
||||
label: search.label as string,
|
||||
kind: "Subscribe",
|
||||
event_id: undefined,
|
||||
event_id: null,
|
||||
contacts,
|
||||
})
|
||||
.then(() => console.log("Subscribe: ", search.label));
|
||||
@@ -86,9 +86,9 @@ export function Screen() {
|
||||
return () => {
|
||||
events.subscription
|
||||
.emit({
|
||||
label: search.label,
|
||||
label: search.label as string,
|
||||
kind: "Unsubscribe",
|
||||
event_id: undefined,
|
||||
event_id: null,
|
||||
contacts,
|
||||
})
|
||||
.then(() => console.log("Unsubscribe: ", search.label));
|
||||
|
||||
Reference in New Issue
Block a user