PascalCasing for enums

This commit is contained in:
Jaiwanth 2021-07-27 00:00:52 +05:30
parent b91309be82
commit 9771f4d6c4
6 changed files with 36 additions and 36 deletions

View file

@ -24,8 +24,8 @@ import Field from "../elements/Field";
import StyledRadioGroup from "../elements/StyledRadioGroup"; import StyledRadioGroup from "../elements/StyledRadioGroup";
import StyledCheckbox from "../elements/StyledCheckbox"; import StyledCheckbox from "../elements/StyledCheckbox";
import { import {
exportFormats, ExportFormats,
exportTypes, ExportTypes,
textForFormat, textForFormat,
textForType, textForType,
} from "../../../utils/exportUtils/exportUtils"; } from "../../../utils/exportUtils/exportUtils";
@ -42,8 +42,8 @@ interface IProps extends IDialogProps {
} }
const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => { const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
const [exportFormat, setExportFormat] = useState(exportFormats.HTML); const [exportFormat, setExportFormat] = useState(ExportFormats.HTML);
const [exportType, setExportType] = useState(exportTypes.TIMELINE); const [exportType, setExportType] = useState(ExportTypes.TIMELINE);
const [includeAttachments, setAttachments] = useState(false); const [includeAttachments, setAttachments] = useState(false);
const [isExporting, setExporting] = useState(false); const [isExporting, setExporting] = useState(false);
const [numberOfMessages, setNumberOfMessages] = useState<number>(100); const [numberOfMessages, setNumberOfMessages] = useState<number>(100);
@ -70,31 +70,31 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
maxSize: sizeLimit * 1024 * 1024, maxSize: sizeLimit * 1024 * 1024,
}; };
switch (exportFormat) { switch (exportFormat) {
case exportFormats.HTML: case ExportFormats.HTML:
setExporter( setExporter(
new HTMLExporter( new HTMLExporter(
room, room,
exportTypes[exportType], ExportTypes[exportType],
exportOptions, exportOptions,
exportProgressRef, exportProgressRef,
), ),
); );
break; break;
case exportFormats.JSON: case ExportFormats.JSON:
setExporter( setExporter(
new JSONExporter( new JSONExporter(
room, room,
exportTypes[exportType], ExportTypes[exportType],
exportOptions, exportOptions,
exportProgressRef, exportProgressRef,
), ),
); );
break; break;
case exportFormats.PLAIN_TEXT: case ExportFormats.PLAIN_TEXT:
setExporter( setExporter(
new PlainTextExporter( new PlainTextExporter(
room, room,
exportTypes[exportType], ExportTypes[exportType],
exportOptions, exportOptions,
exportProgressRef, exportProgressRef,
), ),
@ -114,7 +114,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
sizeLimitRef.current.validate({ focused: true }); sizeLimitRef.current.validate({ focused: true });
return; return;
} }
if (exportType === exportTypes.LAST_N_MESSAGES) { if (exportType === ExportTypes.LAST_N_MESSAGES) {
const isValidNumberOfMessages = const isValidNumberOfMessages =
await messageCountRef.current.validate({ focused: false }); await messageCountRef.current.validate({ focused: false });
if (!isValidNumberOfMessages) { if (!isValidNumberOfMessages) {
@ -202,12 +202,12 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
}); });
}; };
const exportFormatOptions = Object.keys(exportFormats).map((format) => ({ const exportFormatOptions = Object.keys(ExportFormats).map((format) => ({
value: format, value: format,
label: textForFormat(format), label: textForFormat(format),
})); }));
const exportTypeOptions = Object.keys(exportTypes).map((type) => { const exportTypeOptions = Object.keys(ExportTypes).map((type) => {
return ( return (
<option key={type} value={type}> <option key={type} value={type}>
{ textForType(type) } { textForType(type) }
@ -216,7 +216,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
}); });
let messageCount = null; let messageCount = null;
if (exportType === exportTypes.LAST_N_MESSAGES) { if (exportType === ExportTypes.LAST_N_MESSAGES) {
messageCount = ( messageCount = (
<Field <Field
element="input" element="input"
@ -322,7 +322,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
<StyledRadioGroup <StyledRadioGroup
name="exportFormat" name="exportFormat"
value={exportFormat} value={exportFormat}
onChange={(key) => setExportFormat(exportFormats[key])} onChange={(key) => setExportFormat(ExportFormats[key])}
definitions={exportFormatOptions} definitions={exportFormatOptions}
/> />
@ -334,7 +334,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
element="select" element="select"
value={exportType} value={exportType}
onChange={(e) => { onChange={(e) => {
setExportType(exportTypes[e.target.value]); setExportType(ExportTypes[e.target.value]);
}} }}
> >
{ exportTypeOptions } { exportTypeOptions }

View file

@ -17,7 +17,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClientPeg } from "../../MatrixClientPeg"; import { MatrixClientPeg } from "../../MatrixClientPeg";
import { IExportOptions, exportTypes } from "./exportUtils"; import { IExportOptions, ExportTypes } from "./exportUtils";
import { decryptFile } from "../DecryptFile"; import { decryptFile } from "../DecryptFile";
import { mediaFromContent } from "../../customisations/Media"; import { mediaFromContent } from "../../customisations/Media";
import { formatFullDateNoDay } from "../../DateUtils"; import { formatFullDateNoDay } from "../../DateUtils";
@ -38,7 +38,7 @@ export default abstract class Exporter {
protected constructor( protected constructor(
protected room: Room, protected room: Room,
protected exportType: exportTypes, protected exportType: ExportTypes,
protected exportOptions: IExportOptions, protected exportOptions: IExportOptions,
protected exportProgressRef: MutableRefObject<HTMLParagraphElement>, protected exportProgressRef: MutableRefObject<HTMLParagraphElement>,
) { ) {
@ -114,10 +114,10 @@ export default abstract class Exporter {
protected getLimit(): number { protected getLimit(): number {
let limit: number; let limit: number;
switch (this.exportType) { switch (this.exportType) {
case exportTypes.LAST_N_MESSAGES: case ExportTypes.LAST_N_MESSAGES:
limit = this.exportOptions.numberOfMessages; limit = this.exportOptions.numberOfMessages;
break; break;
case exportTypes.TIMELINE: case ExportTypes.TIMELINE:
limit = 40; limit = 40;
break; break;
default: default:
@ -162,7 +162,7 @@ export default abstract class Exporter {
events.push(mxEv); events.push(mxEv);
} }
this.updateProgress( this.updateProgress(
("Fetched " + events.length + " events ") + (this.exportType === exportTypes.LAST_N_MESSAGES ("Fetched " + events.length + " events ") + (this.exportType === ExportTypes.LAST_N_MESSAGES
? `out of ${this.exportOptions.numberOfMessages}` ? `out of ${this.exportOptions.numberOfMessages}`
: "so far"), : "so far"),
); );

View file

@ -33,7 +33,7 @@ import BaseAvatar from "../../components/views/avatars/BaseAvatar";
import exportCSS from "./exportCSS"; import exportCSS from "./exportCSS";
import exportJS from "./exportJS"; import exportJS from "./exportJS";
import exportIcons from "./exportIcons"; import exportIcons from "./exportIcons";
import { exportTypes } from "./exportUtils"; import { ExportTypes } from "./exportUtils";
import { IExportOptions } from "./exportUtils"; import { IExportOptions } from "./exportUtils";
import MatrixClientContext from "../../contexts/MatrixClientContext"; import MatrixClientContext from "../../contexts/MatrixClientContext";
@ -45,7 +45,7 @@ export default class HTMLExporter extends Exporter {
constructor( constructor(
room: Room, room: Room,
exportType: exportTypes, exportType: ExportTypes,
exportOptions: IExportOptions, exportOptions: IExportOptions,
exportProgressRef: MutableRefObject<HTMLParagraphElement>, exportProgressRef: MutableRefObject<HTMLParagraphElement>,
) { ) {

View file

@ -19,7 +19,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { formatFullDateNoDay, formatFullDateNoDayNoTime } from "../../DateUtils"; import { formatFullDateNoDay, formatFullDateNoDayNoTime } from "../../DateUtils";
import { haveTileForEvent } from "../../components/views/rooms/EventTile"; import { haveTileForEvent } from "../../components/views/rooms/EventTile";
import { exportTypes } from "./exportUtils"; import { ExportTypes } from "./exportUtils";
import { IExportOptions } from "./exportUtils"; import { IExportOptions } from "./exportUtils";
import { EventType } from "matrix-js-sdk/src/@types/event"; import { EventType } from "matrix-js-sdk/src/@types/event";
import { MutableRefObject } from "react"; import { MutableRefObject } from "react";
@ -30,7 +30,7 @@ export default class JSONExporter extends Exporter {
constructor( constructor(
room: Room, room: Room,
exportType: exportTypes, exportType: ExportTypes,
exportOptions: IExportOptions, exportOptions: IExportOptions,
exportProgressRef: MutableRefObject<HTMLParagraphElement>, exportProgressRef: MutableRefObject<HTMLParagraphElement>,
) { ) {

View file

@ -20,7 +20,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { formatFullDateNoDay } from "../../DateUtils"; import { formatFullDateNoDay } from "../../DateUtils";
import { _t } from "../../languageHandler"; import { _t } from "../../languageHandler";
import { haveTileForEvent } from "../../components/views/rooms/EventTile"; import { haveTileForEvent } from "../../components/views/rooms/EventTile";
import { exportTypes } from "./exportUtils"; import { ExportTypes } from "./exportUtils";
import { IExportOptions } from "./exportUtils"; import { IExportOptions } from "./exportUtils";
import { textForEvent } from "../../TextForEvent"; import { textForEvent } from "../../TextForEvent";
import { MutableRefObject } from "react"; import { MutableRefObject } from "react";
@ -31,7 +31,7 @@ export default class PlainTextExporter extends Exporter {
constructor( constructor(
room: Room, room: Room,
exportType: exportTypes, exportType: ExportTypes,
exportOptions: IExportOptions, exportOptions: IExportOptions,
exportProgressRef: MutableRefObject<HTMLParagraphElement>, exportProgressRef: MutableRefObject<HTMLParagraphElement>,
) { ) {

View file

@ -16,37 +16,37 @@ limitations under the License.
import { _t } from "../../languageHandler"; import { _t } from "../../languageHandler";
export enum exportFormats { export enum ExportFormats {
HTML = "HTML", HTML = "HTML",
PLAIN_TEXT = "PLAIN_TEXT", PLAIN_TEXT = "PLAIN_TEXT",
JSON = "JSON", JSON = "JSON",
} }
export enum exportTypes { export enum ExportTypes {
TIMELINE = "TIMELINE", TIMELINE = "TIMELINE",
BEGINNING = "BEGINNING", BEGINNING = "BEGINNING",
// START_DATE = "START_DATE",
LAST_N_MESSAGES = "LAST_N_MESSAGES", LAST_N_MESSAGES = "LAST_N_MESSAGES",
// START_DATE = "START_DATE",
} }
export const textForFormat = (format: string): string => { export const textForFormat = (format: string): string => {
switch (format) { switch (format) {
case exportFormats.HTML: case ExportFormats.HTML:
return _t("HTML"); return _t("HTML");
case exportFormats.JSON: case ExportFormats.JSON:
return _t("JSON"); return _t("JSON");
case exportFormats.PLAIN_TEXT: case ExportFormats.PLAIN_TEXT:
return _t("Plain Text"); return _t("Plain Text");
} }
}; };
export const textForType = (type: string): string => { export const textForType = (type: string): string => {
switch (type) { switch (type) {
case exportTypes.BEGINNING: case ExportTypes.BEGINNING:
return _t("From the beginning"); return _t("From the beginning");
case exportTypes.LAST_N_MESSAGES: case ExportTypes.LAST_N_MESSAGES:
return _t("Specify a number of messages"); return _t("Specify a number of messages");
case exportTypes.TIMELINE: case ExportTypes.TIMELINE:
return _t("Current Timeline"); return _t("Current Timeline");
// case exportTypes.START_DATE: // case exportTypes.START_DATE:
// return _t("From a specific date"); // return _t("From a specific date");