From f4e73c25d5d3a31a11f25d2c7c551bd68f3a1d15 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 21 Aug 2023 17:11:46 +0530 Subject: [PATCH] Create vm/view for InvitePanel --- .../rightpanel/InvitePanelViewModel.ts | 54 +++++++++++++++++++ .../ui/session/rightpanel/InvitePanelView.ts | 50 +++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/domain/session/rightpanel/InvitePanelViewModel.ts create mode 100644 src/platform/web/ui/session/rightpanel/InvitePanelView.ts diff --git a/src/domain/session/rightpanel/InvitePanelViewModel.ts b/src/domain/session/rightpanel/InvitePanelViewModel.ts new file mode 100644 index 00000000..4a4409c2 --- /dev/null +++ b/src/domain/session/rightpanel/InvitePanelViewModel.ts @@ -0,0 +1,54 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {ErrorReportViewModel} from "../../ErrorReportViewModel"; +import type {Options as BaseOptions} from "../../ViewModel"; +import type {SegmentType} from "../../navigation"; +import type {Room} from "../../../matrix/room/Room.js"; +import type {Session} from "../../../matrix/Session.js"; + +type Options = { room: Room, session: Session } & BaseOptions; + +export class InvitePanelViewModel extends ErrorReportViewModel { + constructor(options: Options) { + super(options); + } + + get type() { + return "invite"; + } + + get shouldShowBackButton() { + return true; + } + + get previousSegmentName() { + return "members"; + } + + get roomName() { + return this.getOption("room").name; + } + + async invite(userId: string) { + await this.logAndCatch("InvitePanelViewModel.invite", async () => { + const room = this.getOption("room"); + await room.inviteUser(userId); + const path = this.navigation.path.until("room"); + this.navigation.applyPath(path); + }); + } +} diff --git a/src/platform/web/ui/session/rightpanel/InvitePanelView.ts b/src/platform/web/ui/session/rightpanel/InvitePanelView.ts new file mode 100644 index 00000000..4c3c9d4f --- /dev/null +++ b/src/platform/web/ui/session/rightpanel/InvitePanelView.ts @@ -0,0 +1,50 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {Builder, TemplateView} from "../../general/TemplateView"; +import {ErrorView} from "../../general/ErrorView"; +import type {InvitePanelViewModel} from "../../../../../domain/session/rightpanel/InvitePanelViewModel"; + +export class InvitePanelView extends TemplateView { + render(t: Builder, vm: InvitePanelViewModel) { + const input = t.input({ + className: "InvitePanelView__input", + type: "text", + placeholder: "Enter user-id of user", + onkeydown: (e: KeyboardEvent) => { + if (e.key === "Enter") { + vm.invite((input as HTMLInputElement).value); + } + } + }); + return t.div({ className: "InvitePanelView" }, [ + t.h3({ className: "InvitePanelView__heading" }, + (vm: InvitePanelViewModel) => vm.i18n`Invite to ${vm.roomName}` + ), + t.div({ className: "InvitePanelView__form" }, [ + input, + t.button({ + className: "InvitePanelView__btn button-action primary", + onClick: () => vm.invite((input as HTMLInputElement).value), + }, "Invite"), + ]), + t.div({ className: "InvitePanelView__error" }, [ + t.ifView(vm => !!vm.errorViewModel, vm => new ErrorView(vm.errorViewModel!)), + ]), + ]); + } + +}