1
1
<template >
2
- <div id =" home" >
3
- <NavBar ></NavBar >
4
- <Editor v-on:finished =" handleClose()" ></Editor >
5
- </div >
2
+ <div id =" home" >
3
+ <NavBar >
4
+ <router-link slot =" controls" :to =" 'settings'" ><a ><i class =" fas fa-cog" ></i ></a ></router-link >
5
+ <input v-on:change =" updateFileName" v-model =" fileName" type =" text" name =" fileName" />
6
+ <select
7
+ v-on:change =" changeFile"
8
+ v-model =" SelectedFile"
9
+ id =" filePicker"
10
+ style =" margin-left :20px ;"
11
+ name =" selectedFile"
12
+ >
13
+ <option
14
+ v-for =" file in Files()"
15
+ :value =" file.value"
16
+ :key =" file.id"
17
+ :id =" file.id"
18
+ >{{ file.value }}</option >
19
+ </select >
20
+ <a v-on:click =" newNote()" >
21
+ <i class =" fas fa-file-medical" ></i >
22
+ </a >
23
+ <a v-on:click =" deleteNote()" >
24
+ <i class =" fas fa-trash" ></i >
25
+ </a >
26
+ </NavBar >
27
+ <Editor v-on:finished =" handleClose()" v-on:fileLoaded =" setFileName" ></Editor >
28
+ </div >
6
29
</template >
7
30
8
31
<script lang="ts">
9
- import { Component , Vue } from ' vue-property-decorator' ;
10
- import Editor from ' @/components/Editor.vue' ; // @ is an alias to /src
11
- import NavBar from ' @/components/NavBar.vue'
32
+ import { Component , Vue } from " vue-property-decorator" ;
33
+ import Editor from " @/components/Editor.vue" ; // @ is an alias to /src
34
+ import NavBar from " @/components/NavBar.vue" ;
35
+ import {unlink , writeFile , readdirSync } from " fs" ;
36
+ import * as path from " path" ;
37
+ import Configuration from " @/utility/Configuration" ;
38
+ const defaultNoteText =
39
+ " # Welcome to your new note!\n Let's write something awesome." ;
12
40
13
41
@Component ({
14
42
components: {
@@ -17,9 +45,60 @@ import NavBar from '@/components/NavBar.vue'
17
45
}
18
46
})
19
47
export default class Home extends Vue {
20
- handleClose(){
21
- console .log (" Closing" );
22
- const remote = require (' electron' ).remote ;
48
+ private fileName: string = " " ;
49
+ private SelectedFile = " " ;
50
+
51
+ private configuration = new Configuration ();
52
+
53
+ Files() {
54
+ return readdirSync (this .configuration .notePath ).map ((v , i ) => {
55
+ return { id: i , value: v };
56
+ });
57
+ }
58
+
59
+ public mounted() {
60
+ Configuration .getConfig ().then (c => {
61
+ this .configuration = c ;
62
+ });
63
+ }
64
+
65
+ updateFileName() {
66
+ this .$root .$emit (" fileNameUpdated" , this .fileName );
67
+ }
68
+
69
+ changeFile() {
70
+ this .$root .$emit (" fileChange" , this .SelectedFile );
71
+ }
72
+
73
+ newNote() {
74
+ let FileName = ` ${Date .now ()}.md ` ;
75
+ writeFile (
76
+ path .join (this .configuration .notePath , FileName ),
77
+ defaultNoteText ,
78
+ " " ,
79
+ _ => {
80
+ this .setFileName (FileName );
81
+ this .changeFile ();
82
+ }
83
+ );
84
+ }
85
+
86
+ deleteNote() {
87
+ confirm (` This will permantly delete "${this .SelectedFile }". Continue? ` );
88
+ unlink (path .join (this .configuration .notePath , this .SelectedFile ), _ => {
89
+ this .setFileName (this .Files ()[0 ].value )
90
+ this .changeFile ();
91
+ });
92
+ }
93
+
94
+ setFileName(fileName ) {
95
+ var rawFileName= fileName .replace (/ . md$ / , " " );
96
+ this .SelectedFile = rawFileName + " .md" ;
97
+ this .fileName = rawFileName
98
+ }
99
+
100
+ handleClose() {
101
+ const remote = require (" electron" ).remote ;
23
102
let w = remote .getCurrentWindow ();
24
103
w .close ();
25
104
}
0 commit comments