init commit

This commit is contained in:
Ella E 2022-04-05 11:34:13 -06:00 committed by GitHub
parent 28810484b9
commit 5ba71c10cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2006 additions and 0 deletions

8
about.json Normal file
View File

@ -0,0 +1,8 @@
{
"about_url": null,
"license_url": null,
"assets": {
},
"name": "discourse-gated-category",
"component": true
}

4
common/common.scss Normal file
View File

@ -0,0 +1,4 @@
.custom-need-access-prompt {
background: red;
display: block;
}

View File

@ -0,0 +1,41 @@
import Component from "@ember/component";
import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
import { default as getURL } from "discourse-common/lib/get-url";
// import cookie from "discourse/lib/cookie";
export default Component.extend({
tagName: "",
hidden: true,
didInsertElement() {
this._super(...arguments);
this.appEvents.on("cta:shown", this, this._triggerPrompt);
},
willDestroyElement() {
this.appEvents.off("cta:shown", this, this._triggerPrompt);
},
_triggerPrompt() {
this.set("hidden", false)
},
@discourseComputed("hidden")
shouldShow(hidden) {
return !hidden;
},
// @action
// dismissBanner() {
// this.keyValueStore.setItem("anon-cta-never", "t");
// this.session.set("showSignupCta", false);
// this.set("hidden", true);
// },
// @action
// showBannerLater() {
// this.keyValueStore.setItem("anon-cta-hidden", Date.now());
// this.set("hidden", true)
// },
});

View File

@ -0,0 +1 @@
{{need-access-prompt}}

View File

@ -0,0 +1,48 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import discourseComputed from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
const enabledCategories = settings.enabled_categories
.split("|")
.map((id) => parseInt(id, 10))
.filter((id) => id);
const PLUGIN_ID = "discourse-gated-category";
export default {
name: "require-signup-on-select-category",
initialize() {
withPluginApi("0.8.14", (api) => this.initWithApi(api));
},
initWithApi(api) {
const site = api.container.lookup("site:main");
api.modifyClass("component:topic-list-item", {
pluginID: PLUGIN_ID,
excerptsRouter: service("router"),
@discourseComputed(
"excerptsRouter.currentRouteName",
"excerptsRouter.currentRoute.attributes.category.id"
)
requireSignUpCategoryId(currentRouteName, categoryId) {
if (!currentRouteName.match(/^discovery\./)) return;
return categoryId;
},
@discourseComputed("requireSignUpCategoryId")
expandPinned(viewingCategory) {
const overrideEverywhere =
enabledCategories.length === 0;
const overrideInCategory = enabledCategories.includes(viewingCategory);
return overrideEverywhere || overrideInCategory
? true
: this._super();
},
});
},
};

View File

@ -0,0 +1,6 @@
{{!-- {{#if shouldShow}} --}}
<div class="custom-need-access-prompt">
<h1>{{theme-setting "prompt_heading"}}</h1>
{{d-button action=(route-action "showCreateAccount") class="btn-primary sign-up-button" translatedLabel=(theme-setting "prompt_cta_label")}}
</div>
{{!-- {{/if}} --}}

3
locales/en.yml Normal file
View File

@ -0,0 +1,3 @@
en:
theme_metadata:
description: "Categories with logged-in access only"

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"author": "ella",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "latest"
}
}

13
settings.yml Normal file
View File

@ -0,0 +1,13 @@
enabled_categories:
type: list
list_type: category
default: ""
description: "Choose which categories that users need to sign up"
prompt_heading:
type: string
default: "Sign up to read the rest of the post"
description: ""
prompt_cta_label:
type: string
default: "Sign Up"
description: ""

1875
yarn.lock Normal file

File diff suppressed because it is too large Load Diff