Add retry/delete to note broadcaster

This commit is contained in:
Kieran 2023-10-11 19:23:59 +01:00
parent 88ac4063cd
commit a0c8012f8e
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 69 additions and 15 deletions

View File

@ -24,9 +24,9 @@
<symbol id="bookmark" viewBox="0 0 12 14" fill="none">
<path d="M1.3335 4.2C1.3335 3.0799 1.3335 2.51984 1.55148 2.09202C1.74323 1.71569 2.04919 1.40973 2.42552 1.21799C2.85334 1 3.41339 1 4.5335 1H7.46683C8.58693 1 9.14699 1 9.57481 1.21799C9.95114 1.40973 10.2571 1.71569 10.4488 2.09202C10.6668 2.51984 10.6668 3.0799 10.6668 4.2V13L6.00016 10.3333L1.3335 13V4.2Z" stroke="currentColor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round" />
</symbol>
<symbol id="check" viewBox="0 0 18 13" fill="none">
<path d="M17 1L6 12L1 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</symbol>
<svg id="check" viewBox="0 0 24 25" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.7071 5.79289C21.0976 6.18342 21.0976 6.81658 20.7071 7.20711L9.70711 18.2071C9.31658 18.5976 8.68342 18.5976 8.29289 18.2071L3.29289 13.2071C2.90237 12.8166 2.90237 12.1834 3.29289 11.7929C3.68342 11.4024 4.31658 11.4024 4.70711 11.7929L9 16.0858L19.2929 5.79289C19.6834 5.40237 20.3166 5.40237 20.7071 5.79289Z" fill="currentColor"/>
</svg>
<symbol id="chevronDown" viewBox="0 0 24 24" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.29289 8.29289C5.68342 7.90237 6.31658 7.90237 6.70711 8.29289L12 13.5858L17.2929 8.29289C17.6834 7.90237 18.3166 7.90237 18.7071 8.29289C19.0976 8.68342 19.0976 9.31658 18.7071 9.70711L12.7071 15.7071C12.3166 16.0976 11.6834 16.0976 11.2929 15.7071L5.29289 9.70711C4.90237 9.31658 4.90237 8.68342 5.29289 8.29289Z" fill="currentColor" />
</symbol>
@ -352,11 +352,13 @@
<path d="M13.3333 5.5013V4.83464C13.3333 3.90121 13.3333 3.4345 13.1517 3.07798C12.9919 2.76438 12.7369 2.50941 12.4233 2.34962C12.0668 2.16797 11.6001 2.16797 10.6667 2.16797H9.33333C8.39991 2.16797 7.9332 2.16797 7.57668 2.34962C7.26308 2.50941 7.00811 2.76438 6.84832 3.07798C6.66667 3.4345 6.66667 3.90121 6.66667 4.83464V5.5013M8.33333 10.0846V14.2513M11.6667 10.0846V14.2513M2.5 5.5013H17.5M15.8333 5.5013V14.8346C15.8333 16.2348 15.8333 16.9348 15.5608 17.4696C15.3212 17.94 14.9387 18.3225 14.4683 18.5622C13.9335 18.8346 13.2335 18.8346 11.8333 18.8346H8.16667C6.76654 18.8346 6.06647 18.8346 5.53169 18.5622C5.06129 18.3225 4.67883 17.94 4.43915 17.4696C4.16667 16.9348 4.16667 16.2348 4.16667 14.8346V5.5013" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
</g>
</symbol>
<svg id="refresh-ccw-01" viewBox="0 0 20 21" fill="none">
<symbol id="refresh-ccw-01" viewBox="0 0 20 21" fill="none">
<g>
<path d="M5.28415 5.78889C6.49163 4.58059 8.15782 3.83464 9.99983 3.83464C13.6817 3.83464 16.6665 6.8194 16.6665 10.5013C16.6665 14.1832 13.6817 17.168 9.99983 17.168C6.96172 17.168 4.39626 15.135 3.59364 12.3536C3.46603 11.9114 3.00412 11.6564 2.56193 11.784C2.11973 11.9116 1.86471 12.3735 1.99231 12.8157C2.99526 16.2914 6.19946 18.8346 9.99983 18.8346C14.6022 18.8346 18.3332 15.1037 18.3332 10.5013C18.3332 5.89893 14.6022 2.16797 9.99983 2.16797C7.69784 2.16797 5.61252 3.10246 4.10524 4.61079C3.57518 5.14121 3.00475 5.7994 2.49992 6.41325V3.83464C2.49992 3.3744 2.12682 3.0013 1.66659 3.0013C1.20635 3.0013 0.833252 3.3744 0.833252 3.83464V8.83464C0.833252 9.29487 1.20635 9.66797 1.66659 9.66797H6.66659C7.12682 9.66797 7.49992 9.29487 7.49992 8.83464C7.49992 8.3744 7.12682 8.0013 6.66659 8.0013H3.35886C3.92894 7.28583 4.64729 6.4262 5.28415 5.78889Z" fill="currentColor"/>
</g>
</svg>
</symbol>
<symbol id="x" viewBox="0 0 24 25" fill="none">
<path d="M17.7071 8.20711C18.0976 7.81658 18.0976 7.18342 17.7071 6.79289C17.3166 6.40237 16.6834 6.40237 16.2929 6.79289L12 11.0858L7.70711 6.79289C7.31658 6.40237 6.68342 6.40237 6.29289 6.79289C5.90237 7.18342 5.90237 7.81658 6.29289 8.20711L10.5858 12.5L6.29289 16.7929C5.90237 17.1834 5.90237 17.8166 6.29289 18.2071C6.68342 18.5976 7.31658 18.5976 7.70711 18.2071L12 13.9142L16.2929 18.2071C16.6834 18.5976 17.3166 18.5976 17.7071 18.2071C18.0976 17.8166 18.0976 17.1834 17.7071 16.7929L13.4142 12.5L17.7071 8.20711Z" fill="currentColor"/>
</symbol>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 96 KiB

View File

@ -1,12 +1,15 @@
import { useEffect, useState } from "react";
import { FormattedMessage } from "react-intl";
import { removeUndefined } from "@snort/shared";
import { FormattedMessage, useIntl } from "react-intl";
import { removeUndefined, unwrap } from "@snort/shared";
import { NostrEvent, OkResponse } from "@snort/system";
import AsyncButton from "Element/AsyncButton";
import Icon from "Icons/Icon";
import { getRelayName } from "SnortUtils";
import { getRelayName, sanitizeRelayUrl } from "SnortUtils";
import { System } from "index";
import { removeRelay } from "Login";
import useLogin from "Hooks/useLogin";
import useEventPublisher from "Hooks/useEventPublisher";
export function NoteBroadcaster({
evs,
@ -18,6 +21,9 @@ export function NoteBroadcaster({
customRelays?: Array<string>;
}) {
const [results, setResults] = useState<Array<OkResponse>>([]);
const { formatMessage } = useIntl();
const login = useLogin();
const publisher = useEventPublisher();
async function sendEventToRelays(ev: NostrEvent) {
if (customRelays) {
@ -48,8 +54,32 @@ export function NoteBroadcaster({
sendNote().catch(console.error);
}, []);
async function removeRelayFromResult(r: OkResponse) {
if (publisher) {
removeRelay(login, unwrap(sanitizeRelayUrl(r.relay)));
const ev = await publisher.contactList(login.follows.item, login.relays.item);
await System.BroadcastEvent(ev);
setResults(s => s.filter(a => a.relay !== r.relay));
}
}
async function retryPublish(r: OkResponse) {
const ev = evs.find(a => a.id === r.id);
if (ev) {
const rsp = await System.WriteOnceToRelay(unwrap(sanitizeRelayUrl(r.relay)), ev);
setResults(s =>
s.map(x => {
if (x.relay === r.relay && x.id === r.id) {
return rsp; //replace with new response
}
return x;
}),
);
}
}
return (
<div className="flex-column g4">
<div className="flex-column g16">
<h3>
<FormattedMessage defaultMessage="Sending notes and other stuff" />
</h3>
@ -57,18 +87,28 @@ export function NoteBroadcaster({
.filter(a => a.message !== "Duplicate request")
.sort(a => (a.ok ? -1 : 1))
.map(r => (
<div className="p-compact flex-row g16">
<Icon name={r.ok ? "check" : "x-close"} className={r.ok ? "success" : "error"} />
<div className="flex-row g16">
<Icon name={r.ok ? "check" : "x"} className={r.ok ? "success" : "error"} size={24} />
<div className="flex-column f-grow g4">
<b>{getRelayName(r.relay)}</b>
{r.message && <small>{r.message}</small>}
</div>
{!r.ok && false && (
{!r.ok && (
<div className="flex g8">
<AsyncButton onClick={() => {}} className="p4 br-compact flex f-center secondary">
<AsyncButton
onClick={() => retryPublish(r)}
className="p4 br-compact flex f-center secondary"
title={formatMessage({
defaultMessage: "Retry publishing",
})}>
<Icon name="refresh-ccw-01" />
</AsyncButton>
<AsyncButton onClick={() => {}} className="p4 br-compact flex f-center secondary">
<AsyncButton
onClick={() => removeRelayFromResult(r)}
className="p4 br-compact flex f-center secondary"
title={formatMessage({
defaultMessage: "Remove from my relays",
})}>
<Icon name="trash-01" className="trash-icon" />
</AsyncButton>
</div>

View File

@ -183,6 +183,10 @@ a.ext {
padding: 4px;
}
.p12 {
padding: 12px;
}
.p24 {
padding: 24px;
}

View File

@ -279,6 +279,9 @@
"defaultMessage": "Login",
"description": "Login button"
},
"9kSari": {
"defaultMessage": "Retry publishing"
},
"9pMqYs": {
"defaultMessage": "Nostr Address"
},
@ -820,6 +823,9 @@
"UDYlxu": {
"defaultMessage": "Pending Subscriptions"
},
"UJTWqI": {
"defaultMessage": "Remove from my relays"
},
"UT7Nkj": {
"defaultMessage": "New Chat"
},

View File

@ -91,6 +91,7 @@
"9SvQep": "Follows {n}",
"9WRlF4": "Send",
"9gqH2W": "Login",
"9kSari": "Retry publishing",
"9pMqYs": "Nostr Address",
"9wO4wJ": "Lightning Invoice",
"ADmfQT": "Parent",
@ -268,6 +269,7 @@
"TpgeGw": "Hex Salt..",
"Tpy00S": "People",
"UDYlxu": "Pending Subscriptions",
"UJTWqI": "Remove from my relays",
"UT7Nkj": "New Chat",
"UUPFlt": "Users must accept the content warning to show the content of your note.",
"Up5U7K": "Block",