FEATURE: highlight last visited topic in topic list

This commit is contained in:
Sam 2016-08-19 11:58:20 +10:00
parent eb953c0904
commit 11f9a463ac
6 changed files with 48 additions and 2 deletions

View file

@ -47,6 +47,10 @@ export default Ember.Component.extend(StringBuffer, {
} }
}); });
if (topic === this.get('lastVisitedTopic')) {
classes.push('last-visit');
}
return classes.join(' '); return classes.join(' ');
}.property(), }.property(),

View file

@ -1,10 +1,11 @@
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({ export default Ember.Component.extend({
tagName: 'table', tagName: 'table',
classNames: ['topic-list'], classNames: ['topic-list'],
showTopicPostBadges: true, showTopicPostBadges: true,
_observeHideCategory: function(){ _init: function(){
this.addObserver('hideCategory', this.rerender); this.addObserver('hideCategory', this.rerender);
this.addObserver('order', this.rerender); this.addObserver('order', this.rerender);
this.addObserver('ascending', this.rerender); this.addObserver('ascending', this.rerender);
@ -30,6 +31,36 @@ export default Ember.Component.extend({
return this.get('order') === "op_likes"; return this.get('order') === "op_likes";
}.property('order'), }.property('order'),
@computed('topics.@each')
lastVisitedTopic() {
let user = Discourse.User.current();
if (!user || !user.previous_visit_at) {
return;
}
let prevVisit = user.get('previousVisitAt');
let prevTopic, topic;
let skipPinned = true;
this.get('topics').any(t => {
if (skipPinned && t.get('pinned')) {
return false;
}
skipPinned = false;
prevTopic = topic;
topic = t;
return t.get('bumpedAt') < prevVisit;
});
if (!prevTopic || !topic) {
return;
}
return prevTopic;
},
click(e) { click(e) {
var self = this; var self = this;
var on = function(sel, callback){ var on = function(sel, callback){

View file

@ -156,6 +156,11 @@ const User = RestModel.extend({
isSuspended: Em.computed.equal('suspended', true), isSuspended: Em.computed.equal('suspended', true),
@computed("previous_visit_at")
previousVisitAt(previous_visit_at) {
return new Date(previous_visit_at);
},
@computed("suspended_till") @computed("suspended_till")
suspended(suspendedTill) { suspended(suspendedTill) {
return suspendedTill && moment(suspendedTill).isAfter(); return suspendedTill && moment(suspendedTill).isAfter();

View file

@ -26,6 +26,7 @@
showOpLikes=showOpLikes showOpLikes=showOpLikes
expandGloballyPinned=expandGloballyPinned expandGloballyPinned=expandGloballyPinned
expandAllPinned=expandAllPinned expandAllPinned=expandAllPinned
lastVisitedTopic=lastVisitedTopic
selected=selected}} selected=selected}}
{{/each}} {{/each}}
</tbody> </tbody>

View file

@ -31,6 +31,10 @@ html.anon .topic-list a.title:visited:not(.badge-notification) {color: dark-ligh
margin-top: 2px; margin-top: 2px;
} }
border-bottom: 1px solid dark-light-diff($primary, $secondary, 90%, -75%); border-bottom: 1px solid dark-light-diff($primary, $secondary, 90%, -75%);
&.last-visit {
border-bottom: 1px solid scale-color($danger, $lightness: 60%);
}
} }
> tbody > tr:first-of-type { > tbody > tr:first-of-type {

View file

@ -33,7 +33,8 @@ class CurrentUserSerializer < BasicUserSerializer
:show_queued_posts, :show_queued_posts,
:read_faq, :read_faq,
:automatically_unpin_topics, :automatically_unpin_topics,
:mailing_list_mode :mailing_list_mode,
:previous_visit_at
def include_site_flagged_posts_count? def include_site_flagged_posts_count?
object.staff? object.staff?