import React, { useState } from "react"; import { Room } from "matrix-js-sdk/src"; import { _t } from "../../../languageHandler"; import { IDialogProps } from "./IDialogProps"; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; import Field from "../elements/Field"; import StyledRadioGroup from "../elements/StyledRadioGroup"; import StyledCheckbox from "../elements/StyledCheckbox"; import exportConversationalHistory, { exportFormats, exportTypes, textForFormat, textForType, } from "../../../utils/exportUtils/exportUtils"; interface IProps extends IDialogProps { room: Room; } const ExportDialog: React.FC = ({ room, onFinished }) => { const [exportFormat, setExportFormat] = useState("HTML"); const [exportType, setExportType] = useState("TIMELINE"); const [includeAttachments, setAttachments] = useState(false); const [numberOfMessages, setNumberOfMessages] = useState(); const [sizeLimit, setSizeLimit] = useState(8); const onExportClick = async () => { await exportConversationalHistory( room, exportFormats[exportFormat], exportTypes[exportType], { numberOfMessages, attachmentsIncluded: includeAttachments, maxSize: sizeLimit * 1024 * 1024, }, ); }; const onCancel = () => { onFinished(false); }; const exportFormatOptions = Object.keys(exportFormats).map((format) => ({ value: format, label: textForFormat(format), })); const exportTypeOptions = Object.keys(exportTypes).map((type) => { return ( ); }); let MessageCount = null; if (exportType === exportTypes.LAST_N_MESSAGES) { MessageCount = ( { setNumberOfMessages(parseInt(e.target.value)); }} type="number" /> ); } const sizePostFix = ({_t("MB")}); return (

{_t( "Select from the options below to export chats from your timeline", )}

{_t("Format")} setExportFormat(key)} definitions={exportFormatOptions} /> {_t("Messages")} { setExportType(e.target.value); }} > {exportTypeOptions} { MessageCount } {_t("Size Limit")} setSizeLimit(e.target.value)} /> setAttachments((e.target as HTMLInputElement).checked) } > {_t("Include Attachments")}
); }; export default ExportDialog;