X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FNews.vue;h=ec1517df9e81bdaa9913a5279e0f097c6436bb30;hb=d9a7a1e40254bda6e545514596a7363048c084f9;hp=2686552c2ae061248399302be2f610bc27b430ea;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/views/News.vue b/client/src/views/News.vue index 2686552c..ec1517df 100644 --- a/client/src/views/News.vue +++ b/client/src/views/News.vue @@ -1,8 +1,11 @@ @@ -47,13 +56,24 @@ export default { }; }, created: function() { - ajax("/news", "GET", { cursor: this.cursor }, res => { - this.newsList = res.newsList.sort((n1, n2) => n1.added - n2.added); - const L = res.newsList.length; - if (L > 0) this.cursor = this.newsList[0].id; - }); + ajax( + "/news", + "GET", + { + data: { cursor: this.cursor }, + success: (res) => { + this.newsList = res.newsList.sort((n1, n2) => n2.added - n1.added); + const L = res.newsList.length; + if (L > 0) this.cursor = this.newsList[0].id; + } + } + ); }, 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); @@ -90,23 +110,30 @@ export default { sendNews: function() { const edit = this.curnews.id > 0; this.infoMsg = "Processing... Please wait"; - ajax("/news", edit ? "PUT" : "POST", { news: this.curnews }, res => { - if (edit) { - let n = this.newsList.find(n => n.id == this.curnews.id); - if (n) n.content = this.curnews.content; - } else { - const newNews = { - content: this.curnews.content, - added: Date.now(), - uid: this.st.user.id, - id: res.id - }; - this.newsList = [newNews].concat(this.newsList); + ajax( + "/news", + edit ? "PUT" : "POST", + { + data: { news: this.curnews }, + success: (res) => { + if (edit) { + let n = this.newsList.find(n => n.id == this.curnews.id); + if (n) n.content = this.curnews.content; + } else { + const newNews = { + content: this.curnews.content, + added: Date.now(), + uid: this.st.user.id, + id: res.id + }; + this.newsList = [newNews].concat(this.newsList); + } + document.getElementById("modalNews").checked = false; + this.infoMsg = ""; + this.resetCurnews(); + } } - document.getElementById("modalNews").checked = false; - this.infoMsg = ""; - this.resetCurnews(); - }); + ); }, editNews: function(n) { this.curnews.content = n.content; @@ -117,22 +144,36 @@ export default { deleteNews: function(n) { if (confirm(this.st.tr["Are you sure?"])) { this.infoMsg = "Processing... Please wait"; - ajax("/news", "DELETE", { id: n.id }, () => { - const nIdx = this.newsList.findIndex(nw => nw.id == n.id); - this.newsList.splice(nIdx, 1); - this.infoMsg = ""; - document.getElementById("modalNews").checked = false; - }); + ajax( + "/news", + "DELETE", + { + data: { id: n.id }, + success: () => { + const nIdx = this.newsList.findIndex(nw => nw.id == n.id); + this.newsList.splice(nIdx, 1); + this.infoMsg = ""; + document.getElementById("modalNews").checked = false; + } + } + ); } }, loadMore: function() { - ajax("/news", "GET", { cursor: this.cursor }, res => { - if (res.newsList.length > 0) { - this.newsList = this.newsList.concat(res.newsList); - const L = res.newsList.length; - if (L > 0) this.cursor = res.newsList[L - 1].id; - } else this.hasMore = false; - }); + ajax( + "/news", + "GET", + { + data: { cursor: this.cursor }, + success: (res) => { + if (res.newsList.length > 0) { + this.newsList = this.newsList.concat(res.newsList); + const L = res.newsList.length; + if (L > 0) this.cursor = res.newsList[L - 1].id; + } else this.hasMore = false; + } + } + ); } } }; @@ -142,27 +183,36 @@ export default { [type="checkbox"].modal+div .card max-width: 767px max-height: 100% + textarea#newsContent margin: 0 width: 100% min-height: 200px max-height: 100% + #dialog padding: 5px color: blue -button#writeNews + +#writeNews + padding-top: 50px + +button#writeNewsBtn, button#loadMoreBtn margin-top: 0 margin-bottom: 0 + span.ndt color: darkblue padding: 0 5px 0 var(--universal-margin) -.margintop - margin-top: 25px - border-top: 1px solid grey + .news padding-top: 10px & > div display: inline-block + +.margintop + margin-top: 25px + border-top: 1px solid grey @media screen and (max-width: 767px) .margintop margin-top: 10px