feat: handle error when publish note
This commit is contained in:
@@ -353,7 +353,14 @@ pub async fn login(
|
|||||||
{
|
{
|
||||||
let keys: Vec<&str> = events
|
let keys: Vec<&str> = events
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|event| event.get_tags_content(TagKind::p()))
|
.flat_map(|event| {
|
||||||
|
event
|
||||||
|
.tags
|
||||||
|
.iter()
|
||||||
|
.filter(|t| t.kind() == TagKind::p())
|
||||||
|
.filter_map(|t| t.content())
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let trusted_list: HashSet<PublicKey> = keys
|
let trusted_list: HashSet<PublicKey> = keys
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ pub async fn publish(
|
|||||||
|
|
||||||
// Publish
|
// Publish
|
||||||
match client.send_event_builder(builder).await {
|
match client.send_event_builder(builder).await {
|
||||||
Ok(event_id) => Ok(event_id.to_bech32().unwrap()),
|
Ok(event_id) => Ok(event_id.to_hex()),
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => Err(err.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,7 +164,14 @@ pub async fn process_event(client: &Client, events: Vec<Event>) -> Vec<RichEvent
|
|||||||
if !requests.is_empty() {
|
if !requests.is_empty() {
|
||||||
let ids: Vec<&str> = requests
|
let ids: Vec<&str> = requests
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|ev| ev.get_tags_content(TagKind::e()))
|
.flat_map(|event| {
|
||||||
|
event
|
||||||
|
.tags
|
||||||
|
.iter()
|
||||||
|
.filter(|t| t.kind() == TagKind::e())
|
||||||
|
.filter_map(|t| t.content())
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Remove event if event is deleted by author
|
// Remove event if event is deleted by author
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { User } from "@/components/user";
|
|||||||
import { LumeEvent, useEvent } from "@/system";
|
import { LumeEvent, useEvent } from "@/system";
|
||||||
import { Feather } from "@phosphor-icons/react";
|
import { Feather } from "@phosphor-icons/react";
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||||
import { nip19 } from "nostr-tools";
|
import { nip19 } from "nostr-tools";
|
||||||
import { useEffect, useMemo, useRef, useState, useTransition } from "react";
|
import { useEffect, useMemo, useRef, useState, useTransition } from "react";
|
||||||
import { createPortal } from "react-dom";
|
import { createPortal } from "react-dom";
|
||||||
@@ -84,8 +85,9 @@ function Screen() {
|
|||||||
const { reply_to } = Route.useSearch();
|
const { reply_to } = Route.useSearch();
|
||||||
const { users, initialValue } = Route.useRouteContext();
|
const { users, initialValue } = Route.useRouteContext();
|
||||||
|
|
||||||
const [isPending, startTransition] = useTransition();
|
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
const [attaches, setAttaches] = useState<string[]>(null);
|
const [attaches, setAttaches] = useState<string[]>(null);
|
||||||
const [warning, setWarning] = useState({ enable: false, reason: "" });
|
const [warning, setWarning] = useState({ enable: false, reason: "" });
|
||||||
const [difficulty, setDifficulty] = useState({ enable: false, num: 21 });
|
const [difficulty, setDifficulty] = useState({ enable: false, num: 21 });
|
||||||
@@ -127,16 +129,26 @@ function Screen() {
|
|||||||
const publish = async () => {
|
const publish = async () => {
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
try {
|
try {
|
||||||
const content = text.trim();
|
// Temporary hide window
|
||||||
|
await getCurrentWindow().hide();
|
||||||
|
|
||||||
await LumeEvent.publish(
|
let res: Result<string, string>;
|
||||||
content,
|
|
||||||
warning.enable && warning.reason.length ? warning.reason : null,
|
|
||||||
difficulty.num,
|
|
||||||
reply_to,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if (reply_to) {
|
||||||
|
res = await commands.reply(content, reply_to, root_to);
|
||||||
|
} else {
|
||||||
|
res = await commands.publish(content, warning, difficulty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.status === "ok") {
|
||||||
setText("");
|
setText("");
|
||||||
|
// Close window
|
||||||
|
await getCurrentWindow().close();
|
||||||
|
} else {
|
||||||
|
setError(res.error);
|
||||||
|
// Focus window
|
||||||
|
await getCurrentWindow().setFocus();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -158,6 +170,10 @@ function Screen() {
|
|||||||
<span className="text-sm font-semibold">Reply to:</span>
|
<span className="text-sm font-semibold">Reply to:</span>
|
||||||
<EmbedNote id={reply_to} />
|
<EmbedNote id={reply_to} />
|
||||||
</div>
|
</div>
|
||||||
|
) : error?.length ? (
|
||||||
|
<div className="flex flex-col gap-2 px-3.5 pb-3 border-b border-black/5 dark:border-white/5">
|
||||||
|
<p className="text-sm font-medium text-red-600">{error}</p>
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="p-4 overflow-y-auto h-full">
|
<div className="p-4 overflow-y-auto h-full">
|
||||||
<RichTextarea
|
<RichTextarea
|
||||||
@@ -332,6 +348,7 @@ function Menu({
|
|||||||
{u.avatar?.length ? (
|
{u.avatar?.length ? (
|
||||||
<img
|
<img
|
||||||
src={u.avatar}
|
src={u.avatar}
|
||||||
|
alt=""
|
||||||
className="size-7 rounded-full outline outline-1 -outline-offset-1 outline-black/15"
|
className="size-7 rounded-full outline outline-1 -outline-offset-1 outline-black/15"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
decoding="async"
|
decoding="async"
|
||||||
|
|||||||
Reference in New Issue
Block a user