remove attachment button from dms
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
ae73e2b383
commit
77ab39470f
@ -1,54 +1,12 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { NostrEvent, NostrLink, NostrPrefix } from "@snort/system";
|
|
||||||
import useEventPublisher from "@/Hooks/useEventPublisher";
|
import useEventPublisher from "@/Hooks/useEventPublisher";
|
||||||
import useFileUpload from "@/Upload";
|
|
||||||
import { openFile } from "@/SnortUtils";
|
|
||||||
import Textarea from "../Textarea";
|
import Textarea from "../Textarea";
|
||||||
import { Chat } from "@/chat";
|
import { Chat } from "@/chat";
|
||||||
import { AsyncIcon } from "@/Element/AsyncIcon";
|
import { AsyncIcon } from "@/Element/AsyncIcon";
|
||||||
|
|
||||||
export default function WriteMessage({ chat }: { chat: Chat }) {
|
export default function WriteMessage({ chat }: { chat: Chat }) {
|
||||||
const [msg, setMsg] = useState("");
|
const [msg, setMsg] = useState("");
|
||||||
const [otherEvents, setOtherEvents] = useState<Array<NostrEvent>>([]);
|
|
||||||
const [error, setError] = useState("");
|
|
||||||
const { publisher, system } = useEventPublisher();
|
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() {
|
async function sendMessage() {
|
||||||
if (msg && publisher && chat) {
|
if (msg && publisher && chat) {
|
||||||
@ -72,7 +30,6 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AsyncIcon className="circle flex items-center button" iconName="attachment" onClick={() => attachFile()} />
|
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<Textarea
|
<Textarea
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
@ -85,7 +42,6 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
|
|||||||
// ignored
|
// ignored
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{error && <b className="error">{error}</b>}
|
|
||||||
</div>
|
</div>
|
||||||
<AsyncIcon className="circle flex items-center button" iconName="arrow-right" onClick={() => sendMessage()} />
|
<AsyncIcon className="circle flex items-center button" iconName="arrow-right" onClick={() => sendMessage()} />
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user