Show only 5 recently modified
authorAdam Dullage <redacted>
Wed, 15 Jun 2022 12:26:13 +0000 (13:26 +0100)
committerAdam Dullage <redacted>
Wed, 15 Jun 2022 12:26:13 +0000 (13:26 +0100)
flatnotes/src/components/App.js

index 160a651dce9d8b32a28d9eba2db76823e6b70252..fc3eece009b0cd2e06a45fdffeebec9a58136d4a 100644 (file)
@@ -17,18 +17,6 @@ export default {
     return constants.dataDefaults();
   },
 
-  computed: {
-    notesByLastModifiedDesc: function() {
-      if (this.notes == null) {
-        return null;
-      } else {
-        return this.notes.sort(function(a, b) {
-          return b.lastModified - a.lastModified;
-        });
-      }
-    },
-  },
-
   methods: {
     route: function() {
       let path = window.location.pathname.split("/");
@@ -36,7 +24,7 @@ export default {
 
       // Home Page
       if (basePath == "") {
-        this.getNotes();
+        this.getNotes(5, "lastModified", "desc");
         this.currentView = this.views.home;
       }
 
@@ -120,14 +108,18 @@ export default {
       this.navigate(`/${constants.basePaths.login}`);
     },
 
-    getNotes: function() {
+    getNotes: function(limit = null, sort = "filename", order = "asc") {
       let parent = this;
-      api.get("/api/notes").then(function(response) {
-        parent.notes = [];
-        response.data.forEach(function(note) {
-          parent.notes.push(new Note(note.filename, note.lastModified));
+      api
+        .get("/api/notes", {
+          params: { limit: limit, sort: sort, order: order },
+        })
+        .then(function(response) {
+          parent.notes = [];
+          response.data.forEach(function(note) {
+            parent.notes.push(new Note(note.filename, note.lastModified));
+          });
         });
-      });
     },
 
     search: function() {
git clone https://git.99rst.org/PROJECT