mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-14 23:31:30 +03:00
Move export dialog to async-components
This commit is contained in:
parent
7207329c15
commit
31c9e5962c
7 changed files with 28 additions and 52 deletions
|
@ -17,27 +17,27 @@ limitations under the License.
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useRef, 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 "../../../components/views/dialogs/IDialogProps";
|
||||||
import BaseDialog from "./BaseDialog";
|
import BaseDialog from "../../../components/views/dialogs/BaseDialog";
|
||||||
import DialogButtons from "../elements/DialogButtons";
|
import DialogButtons from "../../../components/views/elements/DialogButtons";
|
||||||
import Field from "../elements/Field";
|
import Field from "../../../components/views/elements/Field";
|
||||||
import StyledRadioGroup from "../elements/StyledRadioGroup";
|
import StyledRadioGroup from "../../../components/views/elements/StyledRadioGroup";
|
||||||
import StyledCheckbox from "../elements/StyledCheckbox";
|
import StyledCheckbox from "../../../components/views/elements/StyledCheckbox";
|
||||||
import {
|
import {
|
||||||
ExportFormat,
|
ExportFormat,
|
||||||
ExportType,
|
ExportType,
|
||||||
textForFormat,
|
textForFormat,
|
||||||
textForType,
|
textForType,
|
||||||
} from "../../../utils/exportUtils/exportUtils";
|
} from "../../../utils/exportUtils/exportUtils";
|
||||||
import withValidation, { IFieldState, IValidationResult } from "../elements/Validation";
|
import withValidation, { IFieldState, IValidationResult } from "../../../components/views/elements/Validation";
|
||||||
import HTMLExporter from "../../../utils/exportUtils/HtmlExport";
|
import HTMLExporter from "../../../utils/exportUtils/HtmlExport";
|
||||||
import JSONExporter from "../../../utils/exportUtils/JSONExport";
|
import JSONExporter from "../../../utils/exportUtils/JSONExport";
|
||||||
import PlainTextExporter from "../../../utils/exportUtils/PlainTextExport";
|
import PlainTextExporter from "../../../utils/exportUtils/PlainTextExport";
|
||||||
import { useStateCallback } from "../../../hooks/useStateCallback";
|
import { useStateCallback } from "../../../hooks/useStateCallback";
|
||||||
import Exporter from "../../../utils/exportUtils/Exporter";
|
import Exporter from "../../../utils/exportUtils/Exporter";
|
||||||
import Spinner from "../elements/Spinner";
|
import Spinner from "../../../components/views/elements/Spinner";
|
||||||
import Modal from "../../../Modal";
|
import Modal from "../../../Modal";
|
||||||
import InfoDialog from "./InfoDialog";
|
import InfoDialog from "../../../components/views/dialogs/InfoDialog";
|
||||||
|
|
||||||
interface IProps extends IDialogProps {
|
interface IProps extends IDialogProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
@ -52,7 +52,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
|
||||||
const [sizeLimit, setSizeLimit] = useState<number | null>(8);
|
const [sizeLimit, setSizeLimit] = useState<number | null>(8);
|
||||||
const sizeLimitRef = useRef<Field>();
|
const sizeLimitRef = useRef<Field>();
|
||||||
const messageCountRef = useRef<Field>();
|
const messageCountRef = useRef<Field>();
|
||||||
const exportProgressRef = useRef<HTMLParagraphElement>();
|
const [exportProgressText, setExportProgressText] = useState("Processing...");
|
||||||
const [displayCancel, setCancelWarning] = useState(false);
|
const [displayCancel, setCancelWarning] = useState(false);
|
||||||
const [exportCancelled, setExportCancelled] = useState(false);
|
const [exportCancelled, setExportCancelled] = useState(false);
|
||||||
const [exportSuccessful, setExportSuccessful] = useState(false);
|
const [exportSuccessful, setExportSuccessful] = useState(false);
|
||||||
|
@ -78,7 +78,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
|
||||||
room,
|
room,
|
||||||
ExportType[exportType],
|
ExportType[exportType],
|
||||||
exportOptions,
|
exportOptions,
|
||||||
exportProgressRef,
|
setExportProgressText,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -88,7 +88,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
|
||||||
room,
|
room,
|
||||||
ExportType[exportType],
|
ExportType[exportType],
|
||||||
exportOptions,
|
exportOptions,
|
||||||
exportProgressRef,
|
setExportProgressText,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -98,7 +98,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
|
||||||
room,
|
room,
|
||||||
ExportType[exportType],
|
ExportType[exportType],
|
||||||
exportOptions,
|
exportOptions,
|
||||||
exportProgressRef,
|
setExportProgressText,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -368,8 +368,8 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
|
||||||
{ isExporting ? (
|
{ isExporting ? (
|
||||||
<div className="mx_ExportDialog_progress">
|
<div className="mx_ExportDialog_progress">
|
||||||
<Spinner w={24} h={24} />
|
<Spinner w={24} h={24} />
|
||||||
<p ref={exportProgressRef}>
|
<p>
|
||||||
{ _t("Processing...") }
|
{ exportProgressText }
|
||||||
</p>
|
</p>
|
||||||
<DialogButtons
|
<DialogButtons
|
||||||
primaryButton={_t("Cancel")}
|
primaryButton={_t("Cancel")}
|
|
@ -234,8 +234,7 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, onClose }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onRoomExportClick = async () => {
|
const onRoomExportClick = async () => {
|
||||||
const { default: ExportDialog } = await import("../dialogs/ExportDialog");
|
const { default: ExportDialog } = await import("../../../async-components/views/dialogs/ExportDialog");
|
||||||
|
|
||||||
Modal.createTrackedDialog('export room dialog', '', ExportDialog, {
|
Modal.createTrackedDialog('export room dialog', '', ExportDialog, {
|
||||||
room,
|
room,
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,6 @@ import { decryptFile } from "../DecryptFile";
|
||||||
import { mediaFromContent } from "../../customisations/Media";
|
import { mediaFromContent } from "../../customisations/Media";
|
||||||
import { formatFullDateNoDay } from "../../DateUtils";
|
import { formatFullDateNoDay } from "../../DateUtils";
|
||||||
import { Direction, MatrixClient } from "matrix-js-sdk";
|
import { Direction, MatrixClient } from "matrix-js-sdk";
|
||||||
import { MutableRefObject } from "react";
|
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
import { saveAs } from "file-saver";
|
import { saveAs } from "file-saver";
|
||||||
import { _t } from "../../languageHandler";
|
import { _t } from "../../languageHandler";
|
||||||
|
@ -41,7 +40,7 @@ export default abstract class Exporter {
|
||||||
protected room: Room,
|
protected room: Room,
|
||||||
protected exportType: ExportType,
|
protected exportType: ExportType,
|
||||||
protected exportOptions: IExportOptions,
|
protected exportOptions: IExportOptions,
|
||||||
protected exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
protected setProgressText: React.Dispatch<React.SetStateAction<string>>,
|
||||||
) {
|
) {
|
||||||
if (exportOptions.maxSize < 1 * 1024 * 1024|| // Less than 1 MB
|
if (exportOptions.maxSize < 1 * 1024 * 1024|| // Less than 1 MB
|
||||||
exportOptions.maxSize > 2000 * 1024 * 1024|| // More than ~ 2 GB
|
exportOptions.maxSize > 2000 * 1024 * 1024|| // More than ~ 2 GB
|
||||||
|
@ -60,7 +59,7 @@ export default abstract class Exporter {
|
||||||
|
|
||||||
protected updateProgress(progress: string, log = true, show = true): void {
|
protected updateProgress(progress: string, log = true, show = true): void {
|
||||||
if (log) console.log(progress);
|
if (log) console.log(progress);
|
||||||
if (show && this.exportProgressRef.current) this.exportProgressRef.current.innerText = progress;
|
if (show) this.setProgressText(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addFile(filePath: string, blob: Blob): void {
|
protected addFile(filePath: string, blob: Blob): void {
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { MutableRefObject } from "react";
|
import React from "react";
|
||||||
import Exporter from "./Exporter";
|
import Exporter from "./Exporter";
|
||||||
import { mediaFromMxc } from "../../customisations/Media";
|
import { mediaFromMxc } from "../../customisations/Media";
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
@ -47,9 +47,9 @@ export default class HTMLExporter extends Exporter {
|
||||||
room: Room,
|
room: Room,
|
||||||
exportType: ExportType,
|
exportType: ExportType,
|
||||||
exportOptions: IExportOptions,
|
exportOptions: IExportOptions,
|
||||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
setProgressText: React.Dispatch<React.SetStateAction<string>>,
|
||||||
) {
|
) {
|
||||||
super(room, exportType, exportOptions, exportProgressRef);
|
super(room, exportType, exportOptions, setProgressText);
|
||||||
this.avatars = new Map<string, boolean>();
|
this.avatars = new Map<string, boolean>();
|
||||||
this.permalinkCreator = new RoomPermalinkCreator(this.room);
|
this.permalinkCreator = new RoomPermalinkCreator(this.room);
|
||||||
this.totalSize = 0;
|
this.totalSize = 0;
|
||||||
|
|
|
@ -32,9 +32,9 @@ export default class JSONExporter extends Exporter {
|
||||||
room: Room,
|
room: Room,
|
||||||
exportType: ExportType,
|
exportType: ExportType,
|
||||||
exportOptions: IExportOptions,
|
exportOptions: IExportOptions,
|
||||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
setProgressText: React.Dispatch<React.SetStateAction<string>>,
|
||||||
) {
|
) {
|
||||||
super(room, exportType, exportOptions, exportProgressRef);
|
super(room, exportType, exportOptions, setProgressText);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createJSONString(): string {
|
protected createJSONString(): string {
|
||||||
|
|
|
@ -33,9 +33,9 @@ export default class PlainTextExporter extends Exporter {
|
||||||
room: Room,
|
room: Room,
|
||||||
exportType: ExportType,
|
exportType: ExportType,
|
||||||
exportOptions: IExportOptions,
|
exportOptions: IExportOptions,
|
||||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
setProgressText: React.Dispatch<React.SetStateAction<string>>,
|
||||||
) {
|
) {
|
||||||
super(room, exportType, exportOptions, exportProgressRef);
|
super(room, exportType, exportOptions, setProgressText);
|
||||||
this.totalSize = 0;
|
this.totalSize = 0;
|
||||||
this.mediaOmitText = !this.exportOptions.attachmentsIncluded
|
this.mediaOmitText = !this.exportOptions.attachmentsIncluded
|
||||||
? _t("Media omitted")
|
? _t("Media omitted")
|
||||||
|
|
|
@ -102,27 +102,15 @@ const getExportCSS = async (): Promise<string> => {
|
||||||
to {bottom: 0; opacity: 0;}
|
to {bottom: 0; opacity: 0;}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_MFileBody_info .mx_MFileBody_info_icon img.mx_export_attach_icon {
|
|
||||||
content: '';
|
|
||||||
background-color: ${theme == 'light' ? "#ffffff": "inherit"};
|
|
||||||
width: 13px;
|
|
||||||
height: 15px;
|
|
||||||
position: absolute;
|
|
||||||
top: 8px;
|
|
||||||
left: 9px;
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
scroll-behavior: smooth !important;
|
scroll-behavior: smooth !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.mx_Export_EventWrapper:target {
|
.mx_Export_EventWrapper:target {
|
||||||
background: ${theme == 'light' ? "white" : "#15191E"};
|
background: ${theme == 'light' ? "white" : "#15191E"};
|
||||||
animation: mx_event_highlight_animation 2s linear;
|
animation: mx_event_highlight_animation 2s linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@keyframes mx_event_highlight_animation {
|
@keyframes mx_event_highlight_animation {
|
||||||
0%,100% {
|
0%,100% {
|
||||||
background: ${theme == 'light' ? "white" : "#15191E"};
|
background: ${theme == 'light' ? "white" : "#15191E"};
|
||||||
|
@ -137,16 +125,6 @@ const getExportCSS = async (): Promise<string> => {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_RedactedBody img.mx_export_trash_icon {
|
|
||||||
height: 14px;
|
|
||||||
width: 14px;
|
|
||||||
background-color: ${theme == 'light' ? "#ffffff": "inherit"};
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 1px;
|
|
||||||
left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mx_RedactedBody {
|
.mx_RedactedBody {
|
||||||
padding-left: unset;
|
padding-left: unset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue