FIX: last visited line not rendering correctly

- stop changing cached models
This commit is contained in:
Sam 2016-10-05 15:37:47 +11:00
parent f936bd6607
commit 601a96333a
4 changed files with 53 additions and 39 deletions

View File

@ -1,4 +1,4 @@
import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; import { observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({ export default Ember.Component.extend({
tagName: 'table', tagName: 'table',
@ -9,6 +9,7 @@ export default Ember.Component.extend({
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);
this.refreshLastVisited();
}.on('init'), }.on('init'),
toggleInTitle: function(){ toggleInTitle: function(){
@ -31,28 +32,45 @@ export default Ember.Component.extend({
return this.get('order') === "op_likes"; return this.get('order') === "op_likes";
}.property('order'), }.property('order'),
@computed('topics.@each', 'order', 'ascending') @observes('topics.@each')
lastVisitedTopic(topics, order, ascending) { topicsAdded() {
// special case so we don't keep scanning huge lists
if (!this.get('lastVisitedTopic')) {
this.refreshLastVisited();
}
},
this._cleanLastVisitedTopic(); @observes('topics', 'order', 'ascending', 'category')
lastVisitedTopicChanged() {
this.refreshLastVisited();
},
if (!this.get('highlightLastVisited')) { return; } _updateLastVisitedTopic(topics, order, ascending) {
if (order !== "default" && order !== "activity") { return; }
if (!topics || topics.length === 1) { return; } this.set('lastVisitedTopic', null);
if (ascending) { return; }
if (!this.get('highlightLastVisited')) {
return;
}
if (order !== "default" && order !== "activity") {
return;
}
if (!topics || topics.length === 1) {
return;
}
if (ascending) {
return;
}
let user = Discourse.User.current(); let user = Discourse.User.current();
if (!user || !user.previous_visit_at) { if (!user || !user.previous_visit_at) {
return; return;
} }
let prevTopic, topic; let lastVisitedTopic, topic;
prevTopic = this.get('prevTopic');
if (prevTopic) {
return prevTopic;
}
let prevVisit = user.get('previousVisitAt'); let prevVisit = user.get('previousVisitAt');
@ -66,13 +84,13 @@ export default Ember.Component.extend({
let i; let i;
for(i=topics.length-1;i>=start;i--){ for(i=topics.length-1;i>=start;i--){
if (topics[i].get('bumpedAt') > prevVisit) { if (topics[i].get('bumpedAt') > prevVisit) {
prevTopic = topics[i]; lastVisitedTopic = topics[i];
break; break;
} }
topic = topics[i]; topic = topics[i];
} }
if (!prevTopic || !topic) { if (!lastVisitedTopic || !topic) {
return; return;
} }
@ -81,20 +99,11 @@ export default Ember.Component.extend({
return; return;
} }
prevTopic.set('isLastVisited', true); this.set('lastVisitedTopic', lastVisitedTopic);
this.set('prevTopic', prevTopic);
return prevTopic;
}, },
@observes('category') refreshLastVisited() {
_cleanLastVisitedTopic() { this._updateLastVisitedTopic(this.get('topics'), this.get('order'), this.get('ascending'));
const prevTopic = this.get('prevTopic');
if (prevTopic) {
prevTopic.set('isLastVisited', false);
this.set('prevTopic', null);
}
}, },
click(e) { click(e) {

View File

@ -28,15 +28,6 @@
expandAllPinned=expandAllPinned expandAllPinned=expandAllPinned
lastVisitedTopic=lastVisitedTopic lastVisitedTopic=lastVisitedTopic
selected=selected}} selected=selected}}
{{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
{{#if topic.isLastVisited}}
<tr class='topic-list-item-separator'>
<td colspan="6">
<span>
{{i18n 'topics.new_messages_marker'}}
</span>
</td>
</tr>
{{/if}}
{{/each}} {{/each}}
</tbody> </tbody>

View File

@ -0,0 +1,9 @@
{{#if view.isLastVisited}}
<tr class='topic-list-item-separator'>
<td colspan="6">
<span>
{{i18n 'topics.new_messages_marker'}}
</span>
</td>
</tr>
{{/if}}

View File

@ -0,0 +1,5 @@
export default Ember.Object.extend({
isLastVisited: function(){
return (this.get('lastVisitedTopic') === this.get('topic'));
}.property()
});