mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-23 03:43:47 +01:00
Web: support pasting images from clipboard
This commit is contained in:
parent
87bcf59bd4
commit
a3312f69fb
2 changed files with 33 additions and 1 deletions
|
@ -10,6 +10,7 @@ import Navigation from "./Navigation";
|
||||||
|
|
||||||
const Messaging = (props) => {
|
const Messaging = (props) => {
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
const [attachFile, setAttachFile] = useState(null);
|
||||||
const [dialogKey, setDialogKey] = useState(0);
|
const [dialogKey, setDialogKey] = useState(0);
|
||||||
|
|
||||||
const { dialogOpenMode } = props;
|
const { dialogOpenMode } = props;
|
||||||
|
@ -22,12 +23,19 @@ const Messaging = (props) => {
|
||||||
const handleDialogClose = () => {
|
const handleDialogClose = () => {
|
||||||
props.onDialogOpenModeChange("");
|
props.onDialogOpenModeChange("");
|
||||||
setDialogKey((prev) => prev + 1);
|
setDialogKey((prev) => prev + 1);
|
||||||
|
setAttachFile(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{subscription && (
|
{subscription && (
|
||||||
<MessageBar subscription={subscription} message={message} onMessageChange={setMessage} onOpenDialogClick={handleOpenDialogClick} />
|
<MessageBar
|
||||||
|
subscription={subscription}
|
||||||
|
message={message}
|
||||||
|
onMessageChange={setMessage}
|
||||||
|
onFilePasted={setAttachFile}
|
||||||
|
onOpenDialogClick={handleOpenDialogClick}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<PublishDialog
|
<PublishDialog
|
||||||
key={`publishDialog${dialogKey}`} // Resets dialog when canceled/closed
|
key={`publishDialog${dialogKey}`} // Resets dialog when canceled/closed
|
||||||
|
@ -35,6 +43,7 @@ const Messaging = (props) => {
|
||||||
baseUrl={subscription?.baseUrl ?? config.base_url}
|
baseUrl={subscription?.baseUrl ?? config.base_url}
|
||||||
topic={subscription?.topic ?? ""}
|
topic={subscription?.topic ?? ""}
|
||||||
message={message}
|
message={message}
|
||||||
|
attachFile={attachFile}
|
||||||
onClose={handleDialogClose}
|
onClose={handleDialogClose}
|
||||||
onDragEnter={() => props.onDialogOpenModeChange((prev) => prev || PublishDialog.OPEN_MODE_DRAG)} // Only update if not already open
|
onDragEnter={() => props.onDialogOpenModeChange((prev) => prev || PublishDialog.OPEN_MODE_DRAG)} // Only update if not already open
|
||||||
onResetOpenMode={() => props.onDialogOpenModeChange(PublishDialog.OPEN_MODE_DEFAULT)}
|
onResetOpenMode={() => props.onDialogOpenModeChange(PublishDialog.OPEN_MODE_DEFAULT)}
|
||||||
|
@ -56,6 +65,21 @@ const MessageBar = (props) => {
|
||||||
}
|
}
|
||||||
props.onMessageChange("");
|
props.onMessageChange("");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePaste = (ev) => {
|
||||||
|
const clipboardData = ev.clipboardData || window.clipboardData;
|
||||||
|
const { items } = clipboardData;
|
||||||
|
for (let i = 0; i < items.length; i += 1) {
|
||||||
|
if (items[i].type.indexOf("image") !== -1) {
|
||||||
|
const blob = items[i].getAsFile();
|
||||||
|
props.onFilePasted(blob);
|
||||||
|
props.onOpenDialogClick();
|
||||||
|
console.log(`[MessageBar] Pasted image`, blob);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
elevation={3}
|
elevation={3}
|
||||||
|
@ -89,6 +113,7 @@ const MessageBar = (props) => {
|
||||||
handleSendClick();
|
handleSendClick();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onPaste={handlePaste}
|
||||||
/>
|
/>
|
||||||
<IconButton color="inherit" size="large" edge="end" onClick={handleSendClick} aria-label={t("message_bar_publish")}>
|
<IconButton color="inherit" size="large" edge="end" onClick={handleSendClick} aria-label={t("message_bar_publish")}>
|
||||||
<SendIcon />
|
<SendIcon />
|
||||||
|
|
|
@ -235,6 +235,13 @@ const PublishDialog = (props) => {
|
||||||
await checkAttachmentLimits(file);
|
await checkAttachmentLimits(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.attachFile) {
|
||||||
|
updateAttachFile(props.attachFile);
|
||||||
|
console.log(`[PublishDialog] Attach file changed`, props.attachFile);
|
||||||
|
}
|
||||||
|
}, [props.attachFile]);
|
||||||
|
|
||||||
const handleAttachFileChanged = async (ev) => {
|
const handleAttachFileChanged = async (ev) => {
|
||||||
await updateAttachFile(ev.target.files[0]);
|
await updateAttachFile(ev.target.files[0]);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue