diff --git a/src/components/views/dialogs/ExportDialog.tsx b/src/components/views/dialogs/ExportDialog.tsx index 22223848ea..7aba38c5c0 100644 --- a/src/components/views/dialogs/ExportDialog.tsx +++ b/src/components/views/dialogs/ExportDialog.tsx @@ -1,56 +1,75 @@ -import React from 'react'; -import { Room } from 'matrix-js-sdk/src'; -import { _t } from '../../../languageHandler'; -import { IDialogProps } from './IDialogProps'; -import BaseDialog from "./BaseDialog" +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 Dropdown from "../elements/Dropdown"; +import exportConversationalHistory, { + exportFormats, + exportTypes, +} from "../../../utils/exportUtils/exportUtils"; -interface IProps extends IDialogProps{ +interface IProps extends IDialogProps { room: Room; } -export default class ExportDialog extends React.PureComponent { - onExportClick = async () => { - const { - default: exportConversationalHistory, - exportFormats, - exportTypes, - } = await import("../../../utils/exportUtils/exportUtils"); - +const ExportDialog: React.FC = ({ room, onFinished }) => { + const [format, setFormat] = useState("HTML"); + const onExportClick = async () => { await exportConversationalHistory( - this.props.room, + room, exportFormats.PLAIN_TEXT, exportTypes.START_DATE, { - startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)), + startDate: parseInt( + new Date("2021.05.20").getTime().toFixed(0), + ), attachmentsIncluded: true, maxSize: 7 * 1024 * 1024, // 7 MB }, ); }; - onCancel = () => { - this.props.onFinished(false); + const onCancel = () => { + onFinished(false); }; - render() { - return ( - { + return
+ { exportFormats[key] } +
+ }) + + return ( + +

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

+ + { setFormat(key) }} + value={format} + label={_t("Export formats")} > -
- Export -
- -
- ); - } -} + { options } + + + +
+ ); +}; + +export default ExportDialog; diff --git a/src/components/views/right_panel/RoomSummaryCard.tsx b/src/components/views/right_panel/RoomSummaryCard.tsx index 0cc5bf8e7f..5dd5790bfb 100644 --- a/src/components/views/right_panel/RoomSummaryCard.tsx +++ b/src/components/views/right_panel/RoomSummaryCard.tsx @@ -47,7 +47,6 @@ import {useRoomMemberCount} from "../../../hooks/useRoomMembers"; import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore"; import RoomName from "../elements/RoomName"; import UIStore from "../../../stores/UIStore"; -import ExportDialog from "../dialogs/ExportDialog"; interface IProps { room: Room; @@ -234,7 +233,9 @@ const RoomSummaryCard: React.FC = ({ room, onClose }) => { }); }; - const onRoomExportClick = () => { + const onRoomExportClick = async () => { + const {default: ExportDialog} = await import("../dialogs/ExportDialog"); + Modal.createTrackedDialog('export room dialog', '', ExportDialog, { room, }); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 00212fa137..9ab4a77c9f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2250,6 +2250,7 @@ "Update community": "Update community", "An error has occurred.": "An error has occurred.", "Export Chat": "Export Chat", + "Select from the options below to export chats from your timeline": "Select from the options below to export chats from your timeline", "Export": "Export", "Feedback sent": "Feedback sent", "Rate %(brand)s": "Rate %(brand)s", diff --git a/src/utils/exportUtils/exportUtils.ts b/src/utils/exportUtils/exportUtils.ts index 0439d51ee2..7a1d4a9f11 100644 --- a/src/utils/exportUtils/exportUtils.ts +++ b/src/utils/exportUtils/exportUtils.ts @@ -1,19 +1,29 @@ import { Room } from "matrix-js-sdk/src/models/room"; +import { _t } from "../../languageHandler"; import HTMLExporter from "./HtmlExport"; import JSONExporter from "./JSONExport"; import PlainTextExporter from "./PlainTextExport"; +_t("HTML"); +_t("JSON"); +_t("Plain Text"); + export enum exportFormats { HTML = "HTML", JSON = "JSON", - PLAIN_TEXT = "PLAIN_TEXT", + PLAIN_TEXT = "Plain Text", } +_t("Current Timeline"); +_t("From the beginning") +_t("From a specific date") +_t("Last n messages"); + export enum exportTypes { - TIMELINE = "TIMELINE", - BEGINNING = "BEGINNING", - START_DATE = "START_DATE", - LAST_N_MESSAGES = "LAST_N_MESSAGES", + TIMELINE = "Current Timeline", + BEGINNING = "From the beginning", + START_DATE = "From a specific date", + LAST_N_MESSAGES = "Last n messages", } export interface exportOptions {