Improve news style
[vchess.git] / client / src / views / News.vue
index ec1517d..e7fabe3 100644 (file)
@@ -26,10 +26,10 @@ main
         :class="{margintop:idx>0}"
       )
         span.ndt {{ formatDatetime(n.added) }}
-        div(v-if="devs.includes(st.user.id)")
+        .dev-buttons(v-if="devs.includes(st.user.id)")
           button(@click="editNews(n)") {{ st.tr["Edit"] }}
           button(@click="deleteNews(n)") {{ st.tr["Delete"] }}
-        p(v-html="parseHtml(n.content)")
+        .news-content(v-html="parseHtml(n.content)")
       button#loadMoreBtn(
         v-if="hasMore"
         @click="loadMore()"
@@ -48,8 +48,10 @@ export default {
     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: ""
@@ -62,9 +64,11 @@ export default {
       {
         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;
         }
       }
     );
@@ -166,10 +170,10 @@ export default {
         {
           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;
           }
         }
@@ -207,8 +211,10 @@ span.ndt
 
 .news
   padding-top: 10px
-  & > div
+  & > .dev-buttons
     display: inline-block
+  & > .news-content
+    margin: 0
 
 .margintop
   margin-top: 25px