-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Arkshine/compat-modernize
COMPATIBILITY: Modernize the component
- Loading branch information
Showing
20 changed files
with
2,578 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
< 3.3.0.beta1-dev: 1e8401edaa432c5babd2393f3eb7a268d6e984d3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/eslint-theme"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Discourse Theme | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
ci: | ||
uses: discourse/.github/.github/workflows/discourse-theme.yml@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/prettier"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/template-lint"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
color: var(--danger); | ||
font-size: 1.25rem; | ||
margin-bottom: 0.25rem; | ||
width: 100%; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,34 @@ | ||
import { apiInitializer } from "discourse/lib/api"; | ||
import User from "discourse/models/user"; | ||
import DiscordHeaderMenu from "../components/discord-header-menu"; | ||
|
||
export default apiInitializer("0.11.1", (api) => { | ||
// If login is required | ||
if (settings.require_login && !api.getCurrentUser()) { | ||
return; | ||
} | ||
|
||
// If a trust level is required | ||
if (User.currentProp("trust_level") < settings.minimum_trust_level) { | ||
return; | ||
} | ||
export default apiInitializer("1.28.0", (api) => { | ||
const currentUser = api.getCurrentUser(); | ||
|
||
// If user must be staff | ||
if (settings.require_staff && !api.getCurrentUser().staff) { | ||
if (!currentUser && settings.require_login) { | ||
return; | ||
} | ||
|
||
// If user must be a group member | ||
if (settings.required_groups.length > 0) { | ||
const requiredGroups = settings.required_groups | ||
.split("|") | ||
.map((g) => Number(g)); | ||
|
||
const currentUserGroups = api.getCurrentUser().groups.map((g) => g.id); | ||
if (currentUser) { | ||
if (currentUser.trust_level < settings.minimum_trust_level) { | ||
return; | ||
} | ||
|
||
if (!currentUserGroups.some((g) => requiredGroups.includes(g))) { | ||
if (!currentUser.staff && settings.require_staff) { | ||
return; | ||
} | ||
} | ||
|
||
api.decorateWidget("header-icons:before", (helper) => { | ||
const headerState = helper.widget.parentWidget.state; | ||
return helper.attach("header-dropdown", { | ||
title: themePrefix("discord_widget.title"), | ||
icon: "fab-discord", | ||
active: headerState.discordChatVisible, | ||
action: "toggleDiscordChat", | ||
}); | ||
}); | ||
|
||
api.decorateWidget("header-icons:after", (helper) => { | ||
const headerState = helper.widget.parentWidget.state; | ||
if (headerState.discordChatVisible) { | ||
return [helper.attach("discord-chat-menu")]; | ||
if (settings.required_groups.length > 0) { | ||
const requiredGroups = settings.required_groups | ||
.split("|") | ||
.map((g) => Number(g)); | ||
|
||
const currentUserGroups = currentUser.groups.map((g) => g.id); | ||
|
||
if (!currentUserGroups.some((g) => requiredGroups.includes(g))) { | ||
return; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
api.attachWidgetAction("header", "toggleDiscordChat", function () { | ||
this.state.discordChatVisible = !this.state.discordChatVisible; | ||
}); | ||
api.headerIcons.add("discord", DiscordHeaderMenu, { before: "search" }); | ||
}); |
106 changes: 106 additions & 0 deletions
106
javascripts/discourse/components/discord-header-menu.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { tracked } from "@glimmer/tracking"; | ||
import Component from "@ember/component"; | ||
import { action } from "@ember/object"; | ||
import { bool } from "@ember/object/computed"; | ||
import { inject as service } from "@ember/service"; | ||
import { and, not } from "truth-helpers"; | ||
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner"; | ||
import DButton from "discourse/components/d-button"; | ||
import DMenu from "discourse/components/d-menu"; | ||
import MenuPanel from "discourse/components/menu-panel"; | ||
import DiscourseURL from "discourse/lib/url"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
import PanelMessage from "./panel-message"; | ||
|
||
export default class DiscordHeaderMenu extends Component { | ||
@service site; | ||
|
||
@tracked loading = true; | ||
|
||
@bool("serverId") hasServerId; | ||
@bool("serverInviteUrl") hasInviteUrl; | ||
|
||
get serverId() { | ||
return settings.discord_server_id.trim(); | ||
} | ||
|
||
get serverInviteUrl() { | ||
return settings.discord_invite_url.trim(); | ||
} | ||
|
||
get theme() { | ||
let theme = settings.theme; | ||
|
||
if (theme === "auto") { | ||
theme = getComputedStyle(document.body) | ||
.getPropertyValue("--scheme-type") | ||
.trim(); | ||
} | ||
|
||
return theme; | ||
} | ||
|
||
@action | ||
redirectToUrl() { | ||
DiscourseURL.routeTo(this.serverInviteUrl); | ||
} | ||
|
||
@action | ||
iframeLoaded() { | ||
this.loading = false; | ||
} | ||
|
||
<template> | ||
<li> | ||
{{#if (and this.site.mobileView this.hasInviteUrl)}} | ||
<DButton | ||
@action={{this.redirectToUrl}} | ||
@icon="fab-discord" | ||
@title={{i18n (themePrefix "discord_widget.title")}} | ||
class="icon btn-flat discord-widget" | ||
/> | ||
{{else}} | ||
<DMenu | ||
@identifier="discord-widget" | ||
@icon="fab-discord" | ||
@title={{i18n (themePrefix "discord_widget.title")}} | ||
@inline="true" | ||
class="icon btn-flat discord-widget" | ||
> | ||
<:content> | ||
<MenuPanel @panelClass="discord-panel"> | ||
{{#if (not this.hasServerId)}} | ||
<PanelMessage | ||
@type="warning" | ||
@icon="exclamation-triangle" | ||
@message="discord_widget.no_server_id" | ||
/> | ||
{{else if (and this.site.mobileView (not this.hasInviteUrl))}} | ||
<PanelMessage | ||
@type="warning" | ||
@icon="exclamation-triangle" | ||
@message="discord_widget.no_invite_url" | ||
/> | ||
{{else}} | ||
<iframe | ||
src="https://discordapp.com/widget?id={{this.serverId}}&theme={{this.theme}}" | ||
sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts" | ||
width="350" | ||
height="500" | ||
allowtransparency="true" | ||
frameborder="0" | ||
id="chatwidget" | ||
name="chatwidget" | ||
onload={{this.iframeLoaded}} | ||
class={{if this.loading "hidden" ""}} | ||
title={{i18n (themePrefix "discord_widget.title")}} | ||
></iframe> | ||
<ConditionalLoadingSpinner @condition={{this.loading}} /> | ||
{{/if}} | ||
</MenuPanel> | ||
</:content> | ||
</DMenu> | ||
{{/if}} | ||
</li> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import dIcon from "discourse-common/helpers/d-icon"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
|
||
const PanelMessage = <template> | ||
<div class="panel-message"> | ||
<div class="panel-message-type-{{@type}}"> | ||
{{dIcon @icon}} | ||
{{i18n (themePrefix @message)}} | ||
</div> | ||
</div> | ||
</template>; | ||
|
||
export default PanelMessage; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.