Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Update modal to Component API #20

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/eslint");
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/prettier");
5 changes: 1 addition & 4 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
module.exports = {
plugins: ["ember-template-lint-plugin-discourse"],
extends: "discourse:recommended",
};
module.exports = require("@discourse/lint-configs/template-lint");
40 changes: 0 additions & 40 deletions javascripts/discourse-insert-jitsi/controllers/insert-jitsi.js

This file was deleted.

102 changes: 102 additions & 0 deletions javascripts/discourse/components/modal/insert-jitsi.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { Input } from "@ember/component";
import { action } from "@ember/object";
import DButton from "discourse/components/d-button";
import DModal from "discourse/components/d-modal";
import TextField from "discourse/components/text-field";
import themePrefix from "discourse/helpers/theme-prefix";
import i18n from "discourse-common/helpers/i18n";

export default class InsertJitsi extends Component {
@tracked mobileIframe = true;
@tracked desktopIframe = true;
@tracked jitsiRoom = "";
@tracked buttonText = "";

keyDown(e) {
if (e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
return false;
}
}

randomID() {
return Math.random().toString(36).slice(-8);
}

@action
insert() {
const btnTxt = this.buttonText ? ` label="${this.buttonText}"` : "";
const roomID = this.jitsiRoom || this.randomID();
const text = `[wrap=discourse-jitsi room="${roomID}"${btnTxt} mobileIframe="${this.mobileIframe}" desktopIframe="${this.desktopIframe}"][/wrap]`;
this.args.model.toolbarEvent.addText(text);

this.args.closeModal();
}

@action
cancel() {
this.args.closeModal();
}

<template>
<DModal
@title={{i18n (themePrefix "modal.title")}}
class="insert-jitsi"
@closeModal={{@closeModal}}
>
<:body>
<div class="insert-jitsi-form">
<div class="insert-jitsi-input">
<label>
{{i18n (themePrefix "room_label")}}
</label>
<TextField
@value={{this.jitsiRoom}}
@autofocus="autofocus"
@autocomplete="off"
/>
<div class="desc">{{i18n
(themePrefix "modal.room_field_description")
}}</div>
</div>

<div class="insert-jitsi-input">
<label>
{{i18n (themePrefix "button_text_label")}}
</label>
<TextField
@value={{this.buttonText}}
@placeholderKey={{themePrefix "launch_jitsi"}}
/>
</div>

<div class="insert-jitsi-input">
<label class="checkbox-label">
<Input @type="checkbox" @checked={{this.mobileIframe}} />
{{i18n (themePrefix "modal.mobile_iframe")}}
</label>
</div>

<div class="insert-bbb-input">
<label class="checkbox-label">
<Input @type="checkbox" @checked={{this.desktopIframe}} />
{{i18n (themePrefix "modal.desktop_iframe")}}
</label>
</div>
</div>

</:body>
<:footer>
<DButton
class="btn-primary"
@disabled={{this.insertDisabled}}
@label={{themePrefix "modal.insert"}}
@action={{this.insert}}
/>
</:footer>
</DModal>
</template>
}
43 changes: 20 additions & 23 deletions javascripts/discourse/initializers/insert-jitsi.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* global JitsiMeetExternalAPI */
import { withPluginApi } from "discourse/lib/plugin-api";
import showModal from "discourse/lib/show-modal";
import themePrefix from "discourse/helpers/theme-prefix";
import loadScript from "discourse/lib/load-script";
import { withPluginApi } from "discourse/lib/plugin-api";
import { iconHTML } from "discourse-common/lib/icon-library";
import I18n from "I18n";
import InsertJitsi from "../components/modal/insert-jitsi";

/* eslint-disable */
// prettier-ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll live with the jQuery for now, eh?

function launchJitsi($elem, user, site) {
const data = $elem.data();
const domain = settings.meet_jitsi_domain;
Expand Down Expand Up @@ -63,49 +66,43 @@ function attachJitsi($elem, helper) {
});
}
}
/* eslint-enable */

export default {
name: "insert-jitsi",

initialize() {
withPluginApi("0.8.31", (api) => {
let currentUser = api.getCurrentUser();
const currentUser = api.getCurrentUser();
const modal = api.container.lookup("service:modal");
const settings = api.container.lookup("site-settings:main");

if (settings.show_in_options_dropdown) {
if (
settings.only_available_to_staff &&
currentUser &&
!currentUser.staff
) {
// do nothing if limited to staff
} else {
if (settings.only_available_to_staff && currentUser?.staff) {
api.addComposerToolbarPopupMenuOption({
icon: settings.button_icon,
label: themePrefix("composer_title"),
action: (toolbarEvent) => {
showModal("insert-jitsi").setProperties({
toolbarEvent,
});
modal.show(InsertJitsi, { model: { toolbarEvent } });
},
});
}
} else {
if (
settings.only_available_to_staff &&
currentUser &&
!currentUser.staff
) {
return;
}
api.onToolbarCreate((toolbar) => {
if (
settings.only_available_to_staff &&
currentUser &&
!currentUser.staff
) {
return;
}

toolbar.addButton({
title: themePrefix("composer_title"),
id: "insertJitsi",
group: "insertions",
icon: settings.button_icon,
perform: (e) =>
showModal("insert-jitsi").setProperties({ toolbarEvent: e }),
perform: (toolbarEvent) =>
modal.show(InsertJitsi, { model: { toolbarEvent } }),
});
});
}
Expand Down
49 changes: 0 additions & 49 deletions javascripts/discourse/templates/modal/insert-jitsi.hbs

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "^3.2.0"
"@discourse/lint-configs": "^1.2.0",
"ember-template-lint": "^5.13.0",
"eslint": "^8.54.0",
"prettier": "^2.8.8"
}
}
Loading