Some minor fixes

This commit is contained in:
WolverinDEV 2021-01-22 18:01:37 +01:00
parent e28217979d
commit 817fedd00a
5 changed files with 20 additions and 9 deletions

View file

@ -465,7 +465,7 @@ export function EventHandler<EventTypes>(events: (keyof EventTypes) | (keyof Eve
} }
} }
export function ReactEventHandler<ObjectClass = React.Component<any, any>, Events extends EventMap<Events> = EventMap<any>>(registry_callback: (object: ObjectClass) => Registry<Events>) { export function ReactEventHandler<ObjectClass = React.Component<any, any>, Events = any>(registry_callback: (object: ObjectClass) => Registry<Events>) {
return function (constructor: Function) { return function (constructor: Function) {
if(!React.Component.prototype.isPrototypeOf(constructor.prototype)) if(!React.Component.prototype.isPrototypeOf(constructor.prototype))
throw "Class/object isn't an instance of React.Component"; throw "Class/object isn't an instance of React.Component";

View file

@ -1,5 +1,4 @@
import {spawnReactModal} from "tc-shared/ui/react-elements/Modal"; import {spawnModal} from "tc-shared/ui/react-elements/Modal";
import {ModalGlobalSettingsEditor} from "tc-shared/ui/modal/global-settings-editor/Renderer";
import {Registry} from "tc-shared/events"; import {Registry} from "tc-shared/events";
import {ModalGlobalSettingsEditorEvents, Setting} from "tc-shared/ui/modal/global-settings-editor/Definitions"; import {ModalGlobalSettingsEditorEvents, Setting} from "tc-shared/ui/modal/global-settings-editor/Definitions";
import {RegistryKey, RegistryValueType, Settings, settings} from "tc-shared/settings"; import {RegistryKey, RegistryValueType, Settings, settings} from "tc-shared/settings";
@ -8,9 +7,9 @@ export function spawnGlobalSettingsEditor() {
const events = new Registry<ModalGlobalSettingsEditorEvents>(); const events = new Registry<ModalGlobalSettingsEditorEvents>();
initializeController(events); initializeController(events);
const modal = spawnReactModal(ModalGlobalSettingsEditor, events); const modal = spawnModal("global-settings-editor", [ events.generateIpcDescription() ], { popoutable: true, popedOut: true });
modal.show(); modal.show();
modal.events.on("destroy", () => { modal.getEvents().on("destroy", () => {
events.fire("notify_destroy"); events.fire("notify_destroy");
events.destroy(); events.destroy();
}); });

View file

@ -2,10 +2,11 @@ import {Translatable} from "tc-shared/ui/react-elements/i18n";
import * as React from "react"; import * as React from "react";
import {createContext, useContext, useRef, useState} from "react"; import {createContext, useContext, useRef, useState} from "react";
import {InternalModal} from "tc-shared/ui/react-elements/internal-modal/Controller"; import {InternalModal} from "tc-shared/ui/react-elements/internal-modal/Controller";
import {Registry} from "tc-shared/events"; import {IpcRegistryDescription, Registry} from "tc-shared/events";
import {ModalGlobalSettingsEditorEvents, Setting} from "tc-shared/ui/modal/global-settings-editor/Definitions"; import {ModalGlobalSettingsEditorEvents, Setting} from "tc-shared/ui/modal/global-settings-editor/Definitions";
import {LoadingDots} from "tc-shared/ui/react-elements/LoadingDots"; import {LoadingDots} from "tc-shared/ui/react-elements/LoadingDots";
import {FlatInputField} from "tc-shared/ui/react-elements/InputField"; import {FlatInputField} from "tc-shared/ui/react-elements/InputField";
import {AbstractModal} from "tc-shared/ui/react-elements/modal/Definitions";
const ModalEvents = createContext<Registry<ModalGlobalSettingsEditorEvents>>(undefined); const ModalEvents = createContext<Registry<ModalGlobalSettingsEditorEvents>>(undefined);
const cssStyle = require("./Renderer.scss"); const cssStyle = require("./Renderer.scss");
@ -159,13 +160,13 @@ const SettingList = () => {
); );
} }
export class ModalGlobalSettingsEditor extends InternalModal { class ModalGlobalSettingsEditor extends AbstractModal {
protected readonly events: Registry<ModalGlobalSettingsEditorEvents>; protected readonly events: Registry<ModalGlobalSettingsEditorEvents>;
constructor(events: Registry<ModalGlobalSettingsEditorEvents>) { constructor(events: IpcRegistryDescription<ModalGlobalSettingsEditorEvents>) {
super(); super();
this.events = events; this.events = Registry.fromIpcDescription(events);
} }
renderBody(): React.ReactElement { renderBody(): React.ReactElement {
@ -194,3 +195,4 @@ export class ModalGlobalSettingsEditor extends InternalModal {
} }
} }
export = ModalGlobalSettingsEditor;

View file

@ -4,6 +4,7 @@ import {ReactElement} from "react";
import * as React from "react"; import * as React from "react";
import {ChannelEditEvents} from "tc-shared/ui/modal/channel-edit/Definitions"; import {ChannelEditEvents} from "tc-shared/ui/modal/channel-edit/Definitions";
import {EchoTestEvents} from "tc-shared/ui/modal/echo-test/Definitions"; import {EchoTestEvents} from "tc-shared/ui/modal/echo-test/Definitions";
import {ModalGlobalSettingsEditorEvents} from "tc-shared/ui/modal/global-settings-editor/Definitions";
export type ModalType = "error" | "warning" | "info" | "none"; export type ModalType = "error" | "warning" | "info" | "none";
@ -116,6 +117,9 @@ export interface ModalConstructorArguments {
"echo-test": [ "echo-test": [
/* events */ IpcRegistryDescription<EchoTestEvents> /* events */ IpcRegistryDescription<EchoTestEvents>
], ],
"global-settings-editor": [
/* events */ IpcRegistryDescription<ModalGlobalSettingsEditorEvents>
],
"conversation": any, "conversation": any,
"css-editor": any, "css-editor": any,
"channel-tree": any, "channel-tree": any,

View file

@ -37,6 +37,12 @@ registerModal({
popoutSupported: false /* TODO: Needs style fixing */ popoutSupported: false /* TODO: Needs style fixing */
}); });
registerModal({
modalId: "global-settings-editor",
classLoader: async () => await import("tc-shared/ui/modal/global-settings-editor/Renderer"),
popoutSupported: true
});
registerModal({ registerModal({
modalId: "conversation", modalId: "conversation",
classLoader: async () => await import("../../frames/side/PopoutConversationRenderer"), classLoader: async () => await import("../../frames/side/PopoutConversationRenderer"),