From 14e56285f5fbd4d6f9404e8e59d63e95ed417cdc Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Thu, 17 Jul 2025 16:42:25 -0400 Subject: [PATCH] wip making UI actions for notes --- Controllers/NoteController.cs | 10 +++++++++- Services/FileNoteService.cs | 9 +++++++-- Services/INoteService.cs | 2 +- Views/Login/Login.cshtml | 2 +- Views/Note/Index.cshtml | 19 +++++++++++++------ wwwroot/css/site.css | 35 ++++++++++++++++------------------- wwwroot/js/site.js | 8 ++++++++ 7 files changed, 55 insertions(+), 30 deletions(-) diff --git a/Controllers/NoteController.cs b/Controllers/NoteController.cs index 3f22767..80d846b 100644 --- a/Controllers/NoteController.cs +++ b/Controllers/NoteController.cs @@ -25,7 +25,15 @@ public class NoteController : Controller return View(model); } - [Route("{noteName}/delete")] + [HttpPost, Route("create")] + public IActionResult Create(string noteName) + { + noteService.SaveNote(noteName); + + return Redirect($"/{noteName}"); + } + + [Route("delete/{noteName}")] public IActionResult Delete(string noteName) { noteService.DeleteNote(noteName); diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index a5088d7..228c60f 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -30,8 +30,13 @@ .ToList(); } - public void SaveNote(string noteName, string content) + public void SaveNote(string noteName, string? content = null) { + if (string.IsNullOrWhiteSpace(noteName)) + { + content = "Hi! Feel free to start typing. Everything will be saved soon after you are done typing."; + } + File.WriteAllText(GetFilePath(noteName), content); } @@ -51,7 +56,7 @@ { Directory.CreateDirectory(folderPath); - SaveNote(noteName, "Hi! Feel free to start typing. Everything will be saved soon after you are done typing."); + SaveNote(noteName); } } diff --git a/Services/INoteService.cs b/Services/INoteService.cs index efd5717..d8ddd25 100644 --- a/Services/INoteService.cs +++ b/Services/INoteService.cs @@ -4,7 +4,7 @@ { ICollection GetNoteNames(); string GetNote(string noteName); - void SaveNote(string noteName, string content); + void SaveNote(string noteName, string? content = null); void DeleteNote(string noteName); } } diff --git a/Views/Login/Login.cshtml b/Views/Login/Login.cshtml index f94d1ce..097b82e 100644 --- a/Views/Login/Login.cshtml +++ b/Views/Login/Login.cshtml @@ -1,6 +1,6 @@ @Html.ValidationSummary() -
+
diff --git a/Views/Note/Index.cshtml b/Views/Note/Index.cshtml index a1f0bbb..66c2afd 100644 --- a/Views/Note/Index.cshtml +++ b/Views/Note/Index.cshtml @@ -2,13 +2,20 @@ -
- @foreach (var note in Model.NoteNames.Order()) - { - var css = note.Equals(Model.CurrentNote, StringComparison.OrdinalIgnoreCase) ? "current" : null; +
+ - @note - } + Delete +
+ + +
Saved
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 7f842f6..bf422a2 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -20,26 +20,16 @@ body { min-height: 100%; } -div.note-names { +div.note-actions { position: fixed; bottom: 5px; left: 0; font-size: 14px; - opacity: 0.5; -} +} -div.note-names a { - color: #aaa; - padding-left: 10px; - text-decoration: none; -} - -div.note-names a.current { - font-weight: bold; -} - -div .note-names a:not(:last-of-type) { - border-right: 1px solid #666; +select.note-dropdown { + padding: 6px; + border-radius: 5px; } textarea { @@ -88,8 +78,8 @@ body.dark textarea { background-color: orangered; } -form input[type=password], -button { +form.login-form input[type=password], +form.login-form button { display: block; width: 100%; max-width: 300px; @@ -101,12 +91,19 @@ button { box-sizing: border-box; } -form input[type=password] { +form.login-form input[type=password] { color: #999; } +button, select { + cursor: pointer; +} + form button { - cursor: pointer; color: #fff; background-color: #009E60; +} + +form.action-form { + display: inline; } \ No newline at end of file diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 33b51c3..f9c635c 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -47,6 +47,14 @@ $(function () { // set focus on load $textarea.focus(); + // handle note dropdown change + $('#note-dropdown').change(function () { + var selectedNote = $(this).val(); + if (selectedNote && selectedNote !== noteName) { + window.location.href = selectedNote; + } + }); + // update content upon sync save connection.on('updateNote', function (content) { $textarea.val(content);