Format dropdown

This commit is contained in:
Jaiwanth 2021-06-26 13:04:10 +05:30
parent c3dc51c452
commit 92e34c7993
4 changed files with 76 additions and 45 deletions

View file

@ -1,56 +1,75 @@
import React from 'react'; import React, { useState } from "react";
import { Room } from 'matrix-js-sdk/src'; import { Room } from "matrix-js-sdk/src";
import { _t } from '../../../languageHandler'; import { _t } from "../../../languageHandler";
import { IDialogProps } from './IDialogProps'; import { IDialogProps } from "./IDialogProps";
import BaseDialog from "./BaseDialog" import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons"; 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; room: Room;
} }
export default class ExportDialog extends React.PureComponent<IProps> { const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
onExportClick = async () => { const [format, setFormat] = useState("HTML");
const { const onExportClick = async () => {
default: exportConversationalHistory,
exportFormats,
exportTypes,
} = await import("../../../utils/exportUtils/exportUtils");
await exportConversationalHistory( await exportConversationalHistory(
this.props.room, room,
exportFormats.PLAIN_TEXT, exportFormats.PLAIN_TEXT,
exportTypes.START_DATE, 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, attachmentsIncluded: true,
maxSize: 7 * 1024 * 1024, // 7 MB maxSize: 7 * 1024 * 1024, // 7 MB
}, },
); );
}; };
onCancel = () => { const onCancel = () => {
this.props.onFinished(false); onFinished(false);
}; };
render() { const options = Object.keys(exportFormats).map(key => {
return ( return <div key={key}>
<BaseDialog { exportFormats[key] }
title={_t("Export Chat")} </div>
contentId='mx_Dialog_content' })
hasCancel={true}
onFinished={this.props.onFinished} return (
fixedWidth={false} <BaseDialog
title={_t("Export Chat")}
contentId="mx_Dialog_content"
hasCancel={true}
onFinished={onFinished}
fixedWidth={true}
>
<p>
{_t(
"Select from the options below to export chats from your timeline",
)}
</p>
<Dropdown
onOptionChange={(key: string) => { setFormat(key) }}
value={format}
label={_t("Export formats")}
> >
<div className="mx_Dialog_content" id='mx_Dialog_content'> { options }
Export </Dropdown>
</div>
<DialogButtons <DialogButtons
primaryButton={_t('Export')} primaryButton={_t("Export")}
onPrimaryButtonClick={this.onExportClick} onPrimaryButtonClick={onExportClick}
onCancel={this.onCancel} onCancel={onCancel}
/> />
</BaseDialog> </BaseDialog>
); );
} };
}
export default ExportDialog;

View file

@ -47,7 +47,6 @@ import {useRoomMemberCount} from "../../../hooks/useRoomMembers";
import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore"; import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
import RoomName from "../elements/RoomName"; import RoomName from "../elements/RoomName";
import UIStore from "../../../stores/UIStore"; import UIStore from "../../../stores/UIStore";
import ExportDialog from "../dialogs/ExportDialog";
interface IProps { interface IProps {
room: Room; room: Room;
@ -234,7 +233,9 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, onClose }) => {
}); });
}; };
const onRoomExportClick = () => { const onRoomExportClick = async () => {
const {default: ExportDialog} = await import("../dialogs/ExportDialog");
Modal.createTrackedDialog('export room dialog', '', ExportDialog, { Modal.createTrackedDialog('export room dialog', '', ExportDialog, {
room, room,
}); });

View file

@ -2250,6 +2250,7 @@
"Update community": "Update community", "Update community": "Update community",
"An error has occurred.": "An error has occurred.", "An error has occurred.": "An error has occurred.",
"Export Chat": "Export Chat", "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", "Export": "Export",
"Feedback sent": "Feedback sent", "Feedback sent": "Feedback sent",
"Rate %(brand)s": "Rate %(brand)s", "Rate %(brand)s": "Rate %(brand)s",

View file

@ -1,19 +1,29 @@
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { _t } from "../../languageHandler";
import HTMLExporter from "./HtmlExport"; import HTMLExporter from "./HtmlExport";
import JSONExporter from "./JSONExport"; import JSONExporter from "./JSONExport";
import PlainTextExporter from "./PlainTextExport"; import PlainTextExporter from "./PlainTextExport";
_t("HTML");
_t("JSON");
_t("Plain Text");
export enum exportFormats { export enum exportFormats {
HTML = "HTML", HTML = "HTML",
JSON = "JSON", 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 { export enum exportTypes {
TIMELINE = "TIMELINE", TIMELINE = "Current Timeline",
BEGINNING = "BEGINNING", BEGINNING = "From the beginning",
START_DATE = "START_DATE", START_DATE = "From a specific date",
LAST_N_MESSAGES = "LAST_N_MESSAGES", LAST_N_MESSAGES = "Last n messages",
} }
export interface exportOptions { export interface exportOptions {