import * as React from 'react'; import {useEffect, useRef, useState} from 'react'; import {NotificationItem} from "./Notifications"; import theme from "./theme"; import {Chip, FormControl, InputLabel, Link, Select, useMediaQuery} from "@mui/material"; import TextField from "@mui/material/TextField"; import priority1 from "../img/priority-1.svg"; import priority2 from "../img/priority-2.svg"; import priority3 from "../img/priority-3.svg"; import priority4 from "../img/priority-4.svg"; import priority5 from "../img/priority-5.svg"; import Dialog from "@mui/material/Dialog"; import DialogTitle from "@mui/material/DialogTitle"; import DialogContent from "@mui/material/DialogContent"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import IconButton from "@mui/material/IconButton"; import InsertEmoticonIcon from '@mui/icons-material/InsertEmoticon'; import {Close} from "@mui/icons-material"; import MenuItem from "@mui/material/MenuItem"; import {basicAuth, formatBytes, shortUrl, splitNoEmpty, splitTopicUrl, validTopicUrl} from "../app/utils"; import Box from "@mui/material/Box"; import Icon from "./Icon"; import DialogFooter from "./DialogFooter"; import api from "../app/Api"; import Divider from "@mui/material/Divider"; import EditIcon from '@mui/icons-material/Edit'; import CheckIcon from '@mui/icons-material/Check'; import userManager from "../app/UserManager"; const SendDialog = (props) => { const [topicUrl, setTopicUrl] = useState(props.topicUrl); const [message, setMessage] = useState(props.message || ""); const [title, setTitle] = useState(""); const [tags, setTags] = useState(""); const [priority, setPriority] = useState(3); const [clickUrl, setClickUrl] = useState(""); const [attachUrl, setAttachUrl] = useState(""); const [attachFile, setAttachFile] = useState(null); const [filename, setFilename] = useState(""); const [filenameEdited, setFilenameEdited] = useState(false); const [email, setEmail] = useState(""); const [delay, setDelay] = useState(""); const [showTopicUrl, setShowTopicUrl] = useState(props.topicUrl === ""); const [showClickUrl, setShowClickUrl] = useState(false); const [showAttachUrl, setShowAttachUrl] = useState(false); const [showEmail, setShowEmail] = useState(false); const [showDelay, setShowDelay] = useState(false); const showAttachFile = !!attachFile && !showAttachUrl; const attachFileInput = useRef(); const [sendRequest, setSendRequest] = useState(null); const [statusText, setStatusText] = useState(""); const disabled = !!sendRequest; const fullScreen = useMediaQuery(theme.breakpoints.down('sm')); const sendButtonEnabled = (() => { if (!validTopicUrl(topicUrl)) { return false; } return true; })(); const handleSubmit = async () => { const { baseUrl, topic } = splitTopicUrl(topicUrl); const headers = {}; if (title.trim()) { headers["X-Title"] = title.trim(); } if (tags.trim()) { headers["X-Tags"] = tags.trim(); } if (priority && priority !== 3) { headers["X-Priority"] = priority.toString(); } if (clickUrl.trim()) { headers["X-Click"] = clickUrl.trim(); } if (attachUrl.trim()) { headers["X-Attach"] = attachUrl.trim(); } if (filename.trim()) { headers["X-Filename"] = filename.trim(); } if (email.trim()) { headers["X-Email"] = email.trim(); } if (delay.trim()) { headers["X-Delay"] = delay.trim(); } if (attachFile && message.trim()) { headers["X-Message"] = message.replaceAll("\n", "\\n").trim(); } const body = (attachFile) ? attachFile : message; try { const user = await userManager.get(baseUrl); if (user) { headers["Authorization"] = basicAuth(user.username, user.password); } const progressFn = (ev) => { console.log(ev); if (ev.loaded > 0 && ev.total > 0) { const percent = Math.round(ev.loaded * 100.0 / ev.total); setStatusText(`Uploading ${formatBytes(ev.loaded)}/${formatBytes(ev.total)} (${percent}%) ...`); } else { setStatusText(`Uploading ...`); } }; const request = api.publishXHR(baseUrl, topic, body, headers, progressFn); setSendRequest(request); await request; setStatusText("Message published"); //props.onClose(); } catch (e) { console.log("error", e); setStatusText("An error occurred"); } setSendRequest(null); }; const handleAttachFileClick = () => { attachFileInput.current.click(); }; const handleAttachFileChanged = (ev) => { const file = ev.target.files[0]; setAttachFile(file); setFilename(file.name); console.log(ev.target.files[0]); console.log(URL.createObjectURL(ev.target.files[0])); }; return ( ); }; const Row = (props) => { return (