Compare commits
3 Commits
main
...
a-faq-trac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61f32e1688 | ||
|
|
9a0612e0df | ||
|
|
b4134a3405 |
@ -1,39 +1,41 @@
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import Component from "@ember/component";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import isElementInViewport from "discourse/lib/is-element-in-viewport";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
|
||||
export default class WatchRead extends Component {
|
||||
@service currentUser;
|
||||
|
||||
export default Component.extend({
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
const currentUser = this.currentUser;
|
||||
if (!currentUser) {
|
||||
super.didInsertElement(...arguments);
|
||||
|
||||
if (!this.currentUser || this.currentUser.read_faq) {
|
||||
return;
|
||||
}
|
||||
|
||||
const path = this.path;
|
||||
if (path === "faq" || path === "guidelines") {
|
||||
this._markRead();
|
||||
window.addEventListener("resize", this._markRead, false);
|
||||
window.addEventListener("scroll", this._markRead, false);
|
||||
}
|
||||
},
|
||||
this._checkIfRead();
|
||||
window.addEventListener("resize", this._checkIfRead, false);
|
||||
window.addEventListener("scroll", this._checkIfRead, false);
|
||||
}
|
||||
|
||||
willDestroyElement() {
|
||||
this._super(...arguments);
|
||||
super.willDestroyElement(...arguments);
|
||||
|
||||
window.removeEventListener("resize", this._markRead);
|
||||
window.removeEventListener("scroll", this._markRead);
|
||||
},
|
||||
window.removeEventListener("resize", this._checkIfRead);
|
||||
window.removeEventListener("scroll", this._checkIfRead);
|
||||
}
|
||||
|
||||
@bind
|
||||
_markRead() {
|
||||
const faqUnread = !this.currentUser.read_faq;
|
||||
async _checkIfRead() {
|
||||
const lastParagraph = document.querySelector(".contents p:last-child");
|
||||
|
||||
if (
|
||||
faqUnread &&
|
||||
isElementInViewport(document.querySelector(".contents p:last-child"))
|
||||
) {
|
||||
this.action();
|
||||
if (!isElementInViewport(lastParagraph)) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await ajax(userPath("read-faq"), { type: "POST" });
|
||||
this.currentUser.set("read_faq", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import Controller, { inject as controller } from "@ember/controller";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { equal, or } from "@ember/object/computed";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
|
||||
export default Controller.extend({
|
||||
application: controller(),
|
||||
@ -19,15 +17,4 @@ export default Controller.extend({
|
||||
this.get("model.path") === "login" && this.get("application.canSignUp")
|
||||
);
|
||||
},
|
||||
|
||||
actions: {
|
||||
markFaqRead() {
|
||||
const currentUser = this.currentUser;
|
||||
if (currentUser) {
|
||||
ajax(userPath("read-faq"), { type: "POST" }).then(() => {
|
||||
currentUser.set("read_faq", true);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@ -12,7 +12,7 @@ const configs = {
|
||||
export default function (page) {
|
||||
return DiscourseRoute.extend({
|
||||
renderTemplate() {
|
||||
this.render("static");
|
||||
this.render(this.templateName || "static");
|
||||
},
|
||||
|
||||
beforeModel(transition) {
|
||||
@ -33,7 +33,8 @@ export default function (page) {
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
this.controllerFor("static").set("model", model);
|
||||
const controllerName = this.controllerName || "static";
|
||||
this.controllerFor(controllerName).set("model", model);
|
||||
},
|
||||
|
||||
titleToken() {
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
import staticRouteBuilder from "discourse/lib/static-route-builder";
|
||||
|
||||
export default staticRouteBuilder("faq");
|
||||
export default class FaqRoute extends staticRouteBuilder("faq") {
|
||||
controllerName = "faq";
|
||||
templateName = "faq";
|
||||
}
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
import staticRouteBuilder from "discourse/lib/static-route-builder";
|
||||
|
||||
export default staticRouteBuilder("guidelines");
|
||||
export default class GuidelinesRoute extends staticRouteBuilder("guidelines") {
|
||||
controllerName = "faq";
|
||||
templateName = "faq";
|
||||
}
|
||||
|
||||
18
app/assets/javascripts/discourse/app/templates/faq.hbs
Normal file
18
app/assets/javascripts/discourse/app/templates/faq.hbs
Normal file
@ -0,0 +1,18 @@
|
||||
<DSection @bodyClass="static-{{this.model.path}}" @class="container">
|
||||
<WatchRead>
|
||||
<div class="contents clearfix body-page">
|
||||
<PluginOutlet
|
||||
@name="above-static"
|
||||
@tagName="span"
|
||||
@connectorTagName="div"
|
||||
/>
|
||||
|
||||
{{html-safe this.model.html}}
|
||||
|
||||
<PluginOutlet
|
||||
@name="below-static"
|
||||
@connectorTagName="div"
|
||||
/>
|
||||
</div>
|
||||
</WatchRead>
|
||||
</DSection>
|
||||
@ -1,24 +1,30 @@
|
||||
<DSection @bodyClass={{this.bodyClass}} @class="container">
|
||||
<WatchRead @action={{action "markFaqRead"}} @path={{this.model.path}}>
|
||||
<div class="contents clearfix body-page">
|
||||
<div class="contents clearfix body-page">
|
||||
<PluginOutlet
|
||||
@name="above-static"
|
||||
@tagName="span"
|
||||
@connectorTagName="div"
|
||||
@args={{hash model=this.model}}
|
||||
/>
|
||||
|
||||
<PluginOutlet @name="above-static" @tagName="span" @connectorTagName="div" />
|
||||
{{html-safe this.model.html}}
|
||||
|
||||
{{html-safe this.model.html}}
|
||||
<PluginOutlet
|
||||
@name="below-static"
|
||||
@connectorTagName="div"
|
||||
@args={{hash model=this.model}}
|
||||
/>
|
||||
|
||||
<PluginOutlet @name="below-static" @connectorTagName="div" />
|
||||
{{#if this.anyButtons}}
|
||||
<div class="body-page-button-container">
|
||||
{{#if this.showSignupButton}}
|
||||
<DButton @action={{route-action "showCreateAccount"}} @class="btn-primary sign-up-button" @label="sign_up" />
|
||||
{{/if}}
|
||||
|
||||
{{#if this.anyButtons}}
|
||||
<div class="body-page-button-container">
|
||||
{{#if this.showSignupButton}}
|
||||
<DButton @action={{route-action "showCreateAccount"}} @class="btn-primary sign-up-button" @label="sign_up" />
|
||||
{{/if}}
|
||||
|
||||
{{#if this.showLoginButton}}
|
||||
<DButton @action={{route-action "showLogin"}} @class="btn-primary login-button" @icon="user" @label="log_in" />
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</WatchRead>
|
||||
{{#if this.showLoginButton}}
|
||||
<DButton @action={{route-action "showLogin"}} @class="btn-primary login-button" @icon="user" @label="log_in" />
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</DSection>
|
||||
|
||||
Reference in New Issue
Block a user