Exclude extension when renaming
authorAdam Dullage <redacted>
Thu, 17 Feb 2022 18:57:54 +0000 (18:57 +0000)
committerAdam Dullage <redacted>
Thu, 17 Feb 2022 18:57:54 +0000 (18:57 +0000)
README.md
flatnotes/src/components/App.js
flatnotes/src/components/App.vue
flatnotes/src/components/classes.js

index 7501db356d6fd8671a8a39a82561c5ba896886c4..eb896fea99d11814f24c6c2031474a3cbe8dbf95 100644 (file)
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ This is what flatnotes aims to achieve.
 * [x] Routing
 * [x] e to edit
 * [x] Ability to Delete a Note
-* [ ] Exclude extension when renaming
+* [x] Exclude extension when renaming
 * [ ] Loading & Not Found Indicators
 * [ ] / to search
 * [ ] CTRL-S to save
index 2c307a49e573a4b20fd0805e47303d75647c126a..cd2d450d0779fcbaebb7ab5b252f3158f5484e3a 100644 (file)
@@ -32,7 +32,7 @@ export default {
       searchTimeout: null,
       searchResults: null,
       currentNote: null,
-      newFilename: null,
+      titleInput: null,
       editMode: false,
     };
   },
@@ -170,7 +170,7 @@ export default {
             response.data.lastModified,
             response.data.content
           );
-          parent.newFilename = parent.currentNote.filename;
+          parent.titleInput = parent.currentNote.title;
           parent.updateDocumentTitle();
         });
     },
@@ -192,7 +192,7 @@ export default {
       if (this.currentNote.lastModified == null) {
         api
           .post(`/api/notes`, {
-            filename: this.newFilename,
+            filename: `${this.titleInput}.${constants.markdownExt}`,
             content: newContent,
           })
           .then(this.saveNoteResponseHandler);
@@ -201,11 +201,11 @@ export default {
       // Modified Note
       else if (
         newContent != this.currentNote.content ||
-        this.newFilename != this.currentNote.filename
+        this.titleInput != this.currentNote.title
       ) {
         api
           .patch(`/api/notes/${this.currentNote.filename}`, {
-            newFilename: this.newFilename,
+            newFilename: `${this.titleInput}.${this.currentNote.ext}`,
             newContent: newContent,
           })
           .then(this.saveNoteResponseHandler);
@@ -223,7 +223,7 @@ export default {
         response.data.lastModified,
         response.data.content
       );
-      this.newFilename = this.currentNote.filename;
+      this.titleInput = this.currentNote.title;
       this.updateDocumentTitle();
       history.replaceState(null, "", this.currentNote.href);
       this.toggleEditMode();
index 13f12cb5202e5a16ba135dfb5c1ba4d64e6e8916..d0bdf5ac70d4265f46de4951d63376fa1120f3d1 100644 (file)
 
         <!-- Editor -->
         <div v-else>
-          <input type="text" class="form-control" v-model="newFilename" />
+          <input type="text" class="form-control" v-model="titleInput" />
           <editor
             :initialValue="currentNote.content"
             previewStyle="tab"
index d55e562fbd3feaafa4df7c1b213f9e39c5aae968..1efb1ba1c2ed4b52e34babcdfca01fd93a09e0aa 100644 (file)
@@ -8,11 +8,15 @@ class Note {
   }
 
   get title() {
-    return this.filename.slice(0, -3);
+    return this.filename.substring(0, this.filename.lastIndexOf("."));
+  }
+
+  get ext() {
+    return this.filename.substring(this.filename.lastIndexOf(".") + 1);
   }
 
   get href() {
-    return `/${constants.basePaths.note}/${this.title}`
+    return `/${constants.basePaths.note}/${this.title}`;
   }
 }
 
git clone https://git.99rst.org/PROJECT