diff --git a/internal/conf/templates/edit.tmpl.html b/internal/conf/templates/edit.tmpl.html index e637b48..b8e9aff 100644 --- a/internal/conf/templates/edit.tmpl.html +++ b/internal/conf/templates/edit.tmpl.html @@ -37,7 +37,7 @@ var commandBar = new TinyMDE.CommandBar({ '|', 'h1', 'h2', '|', - 'ul', 'ol', + 'ul', 'ol', {name: "checklist", title: "Check List", action: makeChecklist}, '|', 'blockquote', 'hr', '|', @@ -45,23 +45,9 @@ var commandBar = new TinyMDE.CommandBar({ ], }); -let editTimeout; -let autoSaveDelay = 2000; - -tinyMDE.addEventListener("change", function() { - clearTimeout(editTimeout); - editTimeout = setTimeout(() => { - let form = document.querySelector("form"); - let formData = new FormData(form); - - fetch("{{.urlSave}}", { - method: "POST", - body: formData, - }).then((data) => { - console.log("Saved Note") - }); - }, autoSaveDelay); -}); +function makeChecklist(editor) { + editor.wrapSelection("* [ ] ", "") +}; {{end}} diff --git a/internal/notes/notes.go b/internal/notes/notes.go index 375e192..d0338ea 100644 --- a/internal/notes/notes.go +++ b/internal/notes/notes.go @@ -13,7 +13,6 @@ import ( "os" "path/filepath" "strings" - "time" "forgejo.gwairfelin.com/max/gonotes/internal/conf" markdown "github.com/teekennedy/goldmark-markdown" @@ -37,7 +36,6 @@ type Note struct { Owner string Viewers map[string]struct{} Uid string - LastModified time.Time } type NoteStore struct { @@ -65,7 +63,7 @@ func Init() error { files, err := os.ReadDir(notesDir) if err != nil { if os.IsNotExist(err) { - os.MkdirAll(notesDir, os.FileMode(0o750)) + os.MkdirAll(notesDir, os.FileMode(0750)) } else { log.Print(err.Error()) return err @@ -167,7 +165,7 @@ func (n *Note) Save() error { return os.WriteFile( filename, []byte(fmt.Sprintf("---\n%s---\n%s", frontmatter, n.Body)), - 0o600, + 0600, ) } @@ -192,11 +190,6 @@ func loadNote(uid string) (*Note, error) { } defer f.Close() - stat, err := os.Stat(filename) - if err != nil { - return nil, err - } - bodyScanner := bufio.NewScanner(f) body := make([]byte, 0, 10) fullBody := make([]byte, 0, 10) @@ -243,7 +236,6 @@ func loadNote(uid string) (*Note, error) { note := NewNoteNoSave(title, owner) note.Uid = uid note.Body = body - note.LastModified = stat.ModTime() viewers := metaData["viewers"].([]interface{})