FIX: improve last visited detection
- clear line detection cache on category change - don't show last visited unless latest / descending - improve perf of last visited detection algorithm
This commit is contained in:
parent
3bd8b55fce
commit
c51fec7fda
|
@ -1,4 +1,4 @@
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import {default as computed, observes} from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
tagName: 'table',
|
tagName: 'table',
|
||||||
|
@ -31,9 +31,18 @@ export default Ember.Component.extend({
|
||||||
return this.get('order') === "op_likes";
|
return this.get('order') === "op_likes";
|
||||||
}.property('order'),
|
}.property('order'),
|
||||||
|
|
||||||
@computed('topics.@each')
|
@observes('category')
|
||||||
lastVisitedTopic() {
|
categoryChanged: function(){
|
||||||
|
this.set('prevTopic', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@computed('topics.@each', 'order', 'ascending')
|
||||||
|
lastVisitedTopic(topics, order, ascending) {
|
||||||
if (!this.get('highlightLastVisited')) { 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) {
|
||||||
|
@ -41,24 +50,30 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
let prevTopic, topic;
|
let prevTopic, topic;
|
||||||
|
|
||||||
prevTopic = this.get('prevTopic');
|
prevTopic = this.get('prevTopic');
|
||||||
|
|
||||||
if (prevTopic) {
|
if (prevTopic) {
|
||||||
return prevTopic;
|
return prevTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
let prevVisit = user.get('previousVisitAt');
|
let prevVisit = user.get('previousVisitAt');
|
||||||
let skipPinned = true;
|
|
||||||
|
|
||||||
this.get('topics').any(t => {
|
// this is more efficient cause we keep appending to list
|
||||||
if (skipPinned && t.get('pinned')) {
|
// work backwards
|
||||||
return false;
|
let start = 0;
|
||||||
|
while(topics[start] && topics[start].get('pinned')) {
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
|
||||||
|
let i;
|
||||||
|
for(i=topics.length-1;i>=start;i--){
|
||||||
|
if (topics[i].get('bumpedAt') > prevVisit) {
|
||||||
|
prevTopic = topics[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
skipPinned = false;
|
topic = topics[i];
|
||||||
|
}
|
||||||
prevTopic = topic;
|
|
||||||
topic = t;
|
|
||||||
return t.get('bumpedAt') < prevVisit;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!prevTopic || !topic) {
|
if (!prevTopic || !topic) {
|
||||||
return;
|
return;
|
||||||
|
@ -70,6 +85,7 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('prevTopic', prevTopic);
|
this.set('prevTopic', prevTopic);
|
||||||
|
|
||||||
return prevTopic;
|
return prevTopic;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
selected=selected
|
selected=selected
|
||||||
expandGloballyPinned=expandGloballyPinned
|
expandGloballyPinned=expandGloballyPinned
|
||||||
expandAllPinned=expandAllPinned
|
expandAllPinned=expandAllPinned
|
||||||
|
category=category
|
||||||
topics=model.topics}}
|
topics=model.topics}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/discovery-topics-list}}
|
{{/discovery-topics-list}}
|
||||||
|
|
Loading…
Reference in New Issue