Merge pull request #510 from vivganes/patch-502
add ability to paste image from clipboard
This commit is contained in:
commit
c3c1e02ad8
@ -27,6 +27,8 @@ import type { RootState } from "State/Store";
|
|||||||
import { LNURL } from "LNURL";
|
import { LNURL } from "LNURL";
|
||||||
|
|
||||||
import messages from "./messages";
|
import messages from "./messages";
|
||||||
|
import { ClipboardEventHandler, useState } from "react";
|
||||||
|
import Spinner from "Icons/Spinner";
|
||||||
|
|
||||||
interface NotePreviewProps {
|
interface NotePreviewProps {
|
||||||
note: TaggedRawEvent;
|
note: TaggedRawEvent;
|
||||||
@ -58,6 +60,7 @@ export function NoteCreator() {
|
|||||||
const zapForward = useSelector((s: RootState) => s.noteCreator.zapForward);
|
const zapForward = useSelector((s: RootState) => s.noteCreator.zapForward);
|
||||||
const sensitive = useSelector((s: RootState) => s.noteCreator.sensitive);
|
const sensitive = useSelector((s: RootState) => s.noteCreator.sensitive);
|
||||||
const pollOptions = useSelector((s: RootState) => s.noteCreator.pollOptions);
|
const pollOptions = useSelector((s: RootState) => s.noteCreator.pollOptions);
|
||||||
|
const [uploadInProgress, setUploadInProgress] = useState(false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
async function sendNote() {
|
async function sendNote() {
|
||||||
@ -99,6 +102,19 @@ export function NoteCreator() {
|
|||||||
async function attachFile() {
|
async function attachFile() {
|
||||||
try {
|
try {
|
||||||
const file = await openFile();
|
const file = await openFile();
|
||||||
|
if (file) {
|
||||||
|
uploadFile(file);
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
dispatch(setError(error?.message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadFile(file: File | Blob) {
|
||||||
|
setUploadInProgress(true);
|
||||||
|
try {
|
||||||
if (file) {
|
if (file) {
|
||||||
const rx = await uploader.upload(file, file.name);
|
const rx = await uploader.upload(file, file.name);
|
||||||
if (rx.url) {
|
if (rx.url) {
|
||||||
@ -111,6 +127,8 @@ export function NoteCreator() {
|
|||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
dispatch(setError(error?.message));
|
dispatch(setError(error?.message));
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
setUploadInProgress(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +223,25 @@ export function NoteCreator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePaste: ClipboardEventHandler<HTMLDivElement> = evt => {
|
||||||
|
if (evt.clipboardData) {
|
||||||
|
const clipboardItems = evt.clipboardData.items;
|
||||||
|
const items: DataTransferItem[] = Array.from(clipboardItems).filter(function (item: DataTransferItem) {
|
||||||
|
// Filter the image items only
|
||||||
|
return /^image\//.test(item.type);
|
||||||
|
});
|
||||||
|
if (items.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = items[0];
|
||||||
|
const blob = item.getAsFile();
|
||||||
|
if (blob) {
|
||||||
|
uploadFile(blob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{show && (
|
{show && (
|
||||||
@ -212,7 +249,9 @@ export function NoteCreator() {
|
|||||||
{replyTo && <NotePreview note={replyTo} />}
|
{replyTo && <NotePreview note={replyTo} />}
|
||||||
{preview && getPreviewNote()}
|
{preview && getPreviewNote()}
|
||||||
{!preview && (
|
{!preview && (
|
||||||
<div className={`flex note-creator${replyTo ? " note-reply" : ""}${pollOptions ? " poll" : ""}`}>
|
<div
|
||||||
|
onPaste={handlePaste}
|
||||||
|
className={`flex note-creator${replyTo ? " note-reply" : ""}${pollOptions ? " poll" : ""}`}>
|
||||||
<div className="flex f-col f-grow">
|
<div className="flex f-col f-grow">
|
||||||
<Textarea
|
<Textarea
|
||||||
autoFocus
|
autoFocus
|
||||||
@ -242,6 +281,7 @@ export function NoteCreator() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="note-creator-actions">
|
<div className="note-creator-actions">
|
||||||
|
{uploadInProgress && <Spinner />}
|
||||||
<button className="secondary" type="button" onClick={() => dispatch(setShowAdvanced(!showAdvanced))}>
|
<button className="secondary" type="button" onClick={() => dispatch(setShowAdvanced(!showAdvanced))}>
|
||||||
<FormattedMessage defaultMessage="Advanced" />
|
<FormattedMessage defaultMessage="Advanced" />
|
||||||
</button>
|
</button>
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "انت جاهز!",
|
"zjJZBd": "انت جاهز!",
|
||||||
"zonsdq": "فشل تحميل خدمة LNURL",
|
"zonsdq": "فشل تحميل خدمة LNURL",
|
||||||
"zvCDao": "تظهر تلقائيا أحدث الملاحظات"
|
"zvCDao": "تظهر تلقائيا أحدث الملاحظات"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "You're ready!",
|
"zjJZBd": "You're ready!",
|
||||||
"zonsdq": "Failed to load LNURL service",
|
"zonsdq": "Failed to load LNURL service",
|
||||||
"zvCDao": "Automatically show latest notes"
|
"zvCDao": "Automatically show latest notes"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Sie sind bereit!",
|
"zjJZBd": "Sie sind bereit!",
|
||||||
"zonsdq": "Fehler beim Laden des LNURL-Dienstes",
|
"zonsdq": "Fehler beim Laden des LNURL-Dienstes",
|
||||||
"zvCDao": "Neueste Beiträge automatisch anzeigen"
|
"zvCDao": "Neueste Beiträge automatisch anzeigen"
|
||||||
}
|
}
|
||||||
|
@ -343,4 +343,4 @@
|
|||||||
"zjJZBd": "You're ready!",
|
"zjJZBd": "You're ready!",
|
||||||
"zonsdq": "Failed to load LNURL service",
|
"zonsdq": "Failed to load LNURL service",
|
||||||
"zvCDao": "Automatically show latest notes"
|
"zvCDao": "Automatically show latest notes"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Estás listo!",
|
"zjJZBd": "Estás listo!",
|
||||||
"zonsdq": "Error al contactar con el servicio LNURL",
|
"zonsdq": "Error al contactar con el servicio LNURL",
|
||||||
"zvCDao": "Mostrar notas nuevas automáticamente"
|
"zvCDao": "Mostrar notas nuevas automáticamente"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Tu es prêt!",
|
"zjJZBd": "Tu es prêt!",
|
||||||
"zonsdq": "Échec du chargement du service LNURL",
|
"zonsdq": "Échec du chargement du service LNURL",
|
||||||
"zvCDao": "Afficher automatiquement les dernières notes"
|
"zvCDao": "Afficher automatiquement les dernières notes"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Spremni ste!",
|
"zjJZBd": "Spremni ste!",
|
||||||
"zonsdq": "Neuspješno učitavanje LNURL usluge",
|
"zonsdq": "Neuspješno učitavanje LNURL usluge",
|
||||||
"zvCDao": "Automatski prikaži najnovije bilješke"
|
"zvCDao": "Automatski prikaži najnovije bilješke"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Készen vagy!",
|
"zjJZBd": "Készen vagy!",
|
||||||
"zonsdq": "Az LNURL szolgáltatás betöltése nem sikerült",
|
"zonsdq": "Az LNURL szolgáltatás betöltése nem sikerült",
|
||||||
"zvCDao": "Automatikusan a legfrissebb bejegyzéseket mutassa"
|
"zvCDao": "Automatikusan a legfrissebb bejegyzéseket mutassa"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Anda siap!",
|
"zjJZBd": "Anda siap!",
|
||||||
"zonsdq": "Gagal memuat layanan LNURL",
|
"zonsdq": "Gagal memuat layanan LNURL",
|
||||||
"zvCDao": "Tampilkan catatan terbaru secara otomatis"
|
"zvCDao": "Tampilkan catatan terbaru secara otomatis"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Sei pronto!",
|
"zjJZBd": "Sei pronto!",
|
||||||
"zonsdq": "Caricamento del servizio LNURL fallito",
|
"zonsdq": "Caricamento del servizio LNURL fallito",
|
||||||
"zvCDao": "Visualizza automaticamente le ultime note"
|
"zvCDao": "Visualizza automaticamente le ultime note"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "準備完了!",
|
"zjJZBd": "準備完了!",
|
||||||
"zonsdq": "LNURLサービスの読み込みに失敗しました",
|
"zonsdq": "LNURLサービスの読み込みに失敗しました",
|
||||||
"zvCDao": "最新の記事を自動で表示する"
|
"zvCDao": "最新の記事を自動で表示する"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "You're ready!",
|
"zjJZBd": "You're ready!",
|
||||||
"zonsdq": "Failed to load LNURL service",
|
"zonsdq": "Failed to load LNURL service",
|
||||||
"zvCDao": "Automatically show latest notes"
|
"zvCDao": "Automatically show latest notes"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "You're ready!",
|
"zjJZBd": "You're ready!",
|
||||||
"zonsdq": "Failed to load LNURL service",
|
"zonsdq": "Failed to load LNURL service",
|
||||||
"zvCDao": "Automatically show latest notes"
|
"zvCDao": "Automatically show latest notes"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Готово!",
|
"zjJZBd": "Готово!",
|
||||||
"zonsdq": "Не удалось загрузить службу LNURL",
|
"zonsdq": "Не удалось загрузить службу LNURL",
|
||||||
"zvCDao": "Автоматически показывать новые заметки"
|
"zvCDao": "Автоматически показывать новые заметки"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "Du är redo!",
|
"zjJZBd": "Du är redo!",
|
||||||
"zonsdq": "Det gick inte att ladda LNURL-tjänsten",
|
"zonsdq": "Det gick inte att ladda LNURL-tjänsten",
|
||||||
"zvCDao": "Visa automatiskt de senaste anteckningarna"
|
"zvCDao": "Visa automatiskt de senaste anteckningarna"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "你已准备就绪!",
|
"zjJZBd": "你已准备就绪!",
|
||||||
"zonsdq": "加载 LNURL 服务失败",
|
"zonsdq": "加载 LNURL 服务失败",
|
||||||
"zvCDao": "自动显示最新便条"
|
"zvCDao": "自动显示最新便条"
|
||||||
}
|
}
|
||||||
|
@ -338,4 +338,4 @@
|
|||||||
"zjJZBd": "你已經準備就緒!",
|
"zjJZBd": "你已經準備就緒!",
|
||||||
"zonsdq": "加載 LNURL 服務失敗",
|
"zonsdq": "加載 LNURL 服務失敗",
|
||||||
"zvCDao": "自動顯示最新便條"
|
"zvCDao": "自動顯示最新便條"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user