FEATURE: Show FAQ at top of the hamburger until the user reads it

This commit is contained in:
Robin Ward 2015-09-04 16:56:02 -04:00
parent 5881f68556
commit 32e2d7963a
7 changed files with 54 additions and 21 deletions

View File

@ -3,8 +3,11 @@ export default Ember.Controller.extend({
actions: {
markFaqRead() {
if (this.currentUser) {
Discourse.ajax("/users/read-faq", { method: "POST" });
const currentUser = this.currentUser;
if (currentUser) {
Discourse.ajax("/users/read-faq", { method: "POST" }).then(() => {
currentUser.set('read_faq', true);
});
}
}
}

View File

@ -1,6 +1,17 @@
{{#menu-panel visible=visible}}
{{#unless currentUser.read_faq}}
{{#menu-links}}
<li>
{{#d-link path=faqUrl class="faq-link"}}
{{i18n "faq"}}
<span class='new'>{{i18n "new_item"}}</span>
{{/d-link}}
</li>
{{/menu-links}}
{{/unless}}
{{#if currentUser.staff}}
{{#menu-links class="columned"}}
{{#menu-links}}
<li>{{d-link route="admin" class="admin-link" icon="wrench" label="admin_title"}}</li>
<li>
{{#d-link route="adminFlags" class="flagged-posts-link"}}
@ -70,7 +81,9 @@
{{#menu-links omitRule="true"}}
<li>{{d-link route="about" class="about-link" label="about.simple_title"}}</li>
<li>{{d-link path=faqUrl class="faq-link" label="faq"}}</li>
{{#if currentUser.read_faq}}
<li>{{d-link path=faqUrl class="faq-link" label="faq"}}</li>
{{/if}}
{{#if showKeyboardShortcuts}}
<li>{{d-link action="keyboardShortcuts" class="keyboard-shortcuts-link" label="keyboard_shortcuts_help.title"}}</li>

View File

@ -1,24 +1,28 @@
import isElementInViewport from "discourse/lib/is-element-in-viewport";
import ScrollTop from 'discourse/mixins/scroll-top';
var readFaq = false;
import { on } from 'ember-addons/ember-computed-decorators';
export default Ember.View.extend(ScrollTop, {
_checkRead: function() {
const path = this.get('controller.model.path');
if (path === "faq" || path === "guidelines") {
const controller = this.get('controller');
$(window).on('load.faq resize.faq scroll.faq', function() {
if (!readFaq && isElementInViewport($(".contents p").last())) {
readFaq = true;
controller.send('markFaqRead');
}
});
@on('didInsertElement')
_checkRead() {
const currentUser = this.get('controller.currentUser');
if (currentUser) {
const path = this.get('controller.model.path');
if (path === "faq" || path === "guidelines") {
const controller = this.get('controller');
$(window).on('load.faq resize.faq scroll.faq', function() {
const faqUnread = !currentUser.get('read_faq');
if (faqUnread && isElementInViewport($(".contents p").last())) {
controller.send('markFaqRead');
}
});
}
}
}.on('didInsertElement'),
},
_stopChecking: function(){
@on('willDestroyElement')
_stopChecking() {
$(window).off('load.faq resize.faq scroll.faq');
}.on('willDestroyElement')
}
});

View File

@ -62,6 +62,13 @@
background-color: dark-light-diff($highlight, $secondary, 50%, -55%);
}
}
.new {
font-size: 0.8em;
margin-left: 0.5em;
color: dark-light-choose(scale-color($primary, $lightness: 50%), scale-color($secondary, $lightness: 50%));
}
}
li.category-link {

View File

@ -572,7 +572,7 @@ class UsersController < ApplicationController
end
def read_faq
if(user = current_user)
if user = current_user
user.user_stat.read_faq = 1.second.ago
user.user_stat.save
end

View File

@ -30,12 +30,17 @@ class CurrentUserSerializer < BasicUserSerializer
:dismissed_banner_key,
:is_anonymous,
:post_queue_new_count,
:show_queued_posts
:show_queued_posts,
:read_faq
def include_site_flagged_posts_count?
object.staff?
end
def read_faq
object.user_stat.read_faq?
end
def topic_count
object.topics.count
end

View File

@ -952,6 +952,7 @@ en:
private_messages: "Search messages"
hamburger_menu: "go to another topic list or category"
new_item: "New!"
go_back: 'go back'
not_logged_in_user: 'user page with summary of current activity and preferences'
current_user: 'go to your user page'