remove attachment button from dms
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Martti Malmi 2023-11-27 14:22:48 +02:00
parent ae73e2b383
commit 77ab39470f

View File

@ -1,54 +1,12 @@
import { useState } from "react";
import { NostrEvent, NostrLink, NostrPrefix } from "@snort/system";
import useEventPublisher from "@/Hooks/useEventPublisher";
import useFileUpload from "@/Upload";
import { openFile } from "@/SnortUtils";
import Textarea from "../Textarea";
import { Chat } from "@/chat";
import { AsyncIcon } from "@/Element/AsyncIcon";
export default function WriteMessage({ chat }: { chat: Chat }) {
const [msg, setMsg] = useState("");
const [otherEvents, setOtherEvents] = useState<Array<NostrEvent>>([]);
const [error, setError] = useState("");
const { publisher, system } = useEventPublisher();
const uploader = useFileUpload();
async function attachFile() {
try {
const file = await openFile();
if (file) {
uploadFile(file);
}
} catch (e) {
if (e instanceof Error) {
setError(e.message);
}
}
}
async function uploadFile(file: File | Blob) {
try {
if (file) {
const rx = await uploader.upload(file, file.name);
if (rx.header) {
const link = `nostr:${new NostrLink(NostrPrefix.Event, rx.header.id, rx.header.kind).encode(
CONFIG.eventLinkPrefix,
)}`;
setMsg(`${msg ? `${msg}\n` : ""}${link}`);
setOtherEvents([...otherEvents, rx.header]);
} else if (rx.url) {
setMsg(`${msg ? `${msg}\n` : ""}${rx.url}`);
} else if (rx?.error) {
setError(rx.error);
}
}
} catch (e) {
if (e instanceof Error) {
setError(e.message);
}
}
}
async function sendMessage() {
if (msg && publisher && chat) {
@ -72,7 +30,6 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
return (
<>
<AsyncIcon className="circle flex items-center button" iconName="attachment" onClick={() => attachFile()} />
<div className="grow">
<Textarea
autoFocus={true}
@ -85,7 +42,6 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
// ignored
}}
/>
{error && <b className="error">{error}</b>}
</div>
<AsyncIcon className="circle flex items-center button" iconName="arrow-right" onClick={() => sendMessage()} />
</>