return {
devs: [1], //for now the only dev is me
st: store.state,
- cursor: 0, //ID of last showed news
- hasMore: true, //a priori there could be more news to load
+ // timestamp of oldest showed news:
+ cursor: Number.MAX_SAFE_INTEGER,
+ // hasMore == TRUE: a priori there could be more news to load
+ hasMore: true,
curnews: { id: 0, content: "" },
newsList: [],
infoMsg: ""
{
data: { cursor: this.cursor },
success: (res) => {
- this.newsList = res.newsList.sort((n1, n2) => n2.added - n1.added);
+ // The returned list is sorted from most recent to oldest
+ this.newsList = res.newsList;
const L = res.newsList.length;
- if (L > 0) this.cursor = this.newsList[0].id;
+ if (L > 0) this.cursor = res.newsList[L - 1].added;
+ else this.hasMore = false;
}
}
);
},
mounted: function() {
+ // Mark that I've read the news:
+ localStorage.setItem("newsRead", Date.now());
+ if (this.st.user.id > 0) ajax("/newsread", "PUT");
+ document.getElementById("newsMenu").classList.remove("somenews");
document
.getElementById("newnewsDiv")
.addEventListener("click", processModalClick);
{
data: { cursor: this.cursor },
success: (res) => {
- if (res.newsList.length > 0) {
+ const L = res.newsList.length;
+ if (L > 0) {
this.newsList = this.newsList.concat(res.newsList);
- const L = res.newsList.length;
- if (L > 0) this.cursor = res.newsList[L - 1].id;
+ this.cursor = res.newsList[L - 1].added;
} else this.hasMore = false;
}
}