From 400f20e9163f2f228826610107fb77d569e19ead Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 17 May 2023 21:44:41 -0400 Subject: [PATCH] working nicely --- Controllers/NoteController.cs | 5 +++-- Models/ContentModel.cs | 1 + Services/FileNoteService.cs | 16 +++++--------- Services/INoteService.cs | 4 ++-- Views/Note/Index.cshtml | 6 +++-- appsettings.json | 5 +++-- notes/birds | 1 + notes/default | 1 + notes/sdfsds | 1 + wwwroot/css/site.css | 41 ++++++++++++++++++++--------------- 10 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 notes/birds create mode 100644 notes/default create mode 100644 notes/sdfsds diff --git a/Controllers/NoteController.cs b/Controllers/NoteController.cs index 7b835d3..9f9fe79 100644 --- a/Controllers/NoteController.cs +++ b/Controllers/NoteController.cs @@ -15,11 +15,12 @@ public class NoteController : Controller this.noteService = noteService; } - [Route("{noteName?}")] - public IActionResult Index(string? noteName) + [Route("{noteName=default}")] + public IActionResult Index(string noteName) { var model = new ContentModel { + CurrentNote = noteName, Text = noteService.GetText(noteName), NoteNames = noteService.GetNoteNames() }; diff --git a/Models/ContentModel.cs b/Models/ContentModel.cs index e91d81f..3631056 100644 --- a/Models/ContentModel.cs +++ b/Models/ContentModel.cs @@ -2,6 +2,7 @@ namespace BinaryDad.Notes.Models; public class ContentModel { + public string CurrentNote { get; set; } = string.Empty; public ICollection NoteNames { get; set; } = new List(); public string Text { get; set; } = string.Empty; } \ No newline at end of file diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 9decc84..0b9f035 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -2,18 +2,14 @@ { public class FileNoteService : INoteService { - private readonly string defaultFileName; private readonly string filePath; public FileNoteService(IConfiguration configuration) { - defaultFileName = configuration["DefaultContentFileName"].Trim().ToLower(); - filePath = configuration["ContentFilePath"].Trim(); - - CheckFile(defaultFileName); + filePath = configuration["FileNoteService:ContentFilePath"].Trim(); } - public string GetText(string? noteName) + public string GetText(string noteName) { CheckFile(noteName); @@ -27,7 +23,7 @@ .ToList(); } - public void SaveText(string content, string? noteName) + public void SaveText(string content, string noteName) { File.WriteAllText(GetFilePath(noteName), content); } @@ -39,7 +35,7 @@ File.Delete(filePath); } - private void CheckFile(string? noteName) + private void CheckFile(string noteName) { var filePath = GetFilePath(noteName); @@ -50,10 +46,8 @@ } } - private string GetFilePath(string? noteName) + private string GetFilePath(string noteName) { - noteName = string.IsNullOrWhiteSpace(noteName) ? defaultFileName : noteName; - noteName = noteName.Trim().ToLower(); return Path.Combine(filePath, noteName); diff --git a/Services/INoteService.cs b/Services/INoteService.cs index 7d9ff99..9ba6fc7 100644 --- a/Services/INoteService.cs +++ b/Services/INoteService.cs @@ -3,8 +3,8 @@ public interface INoteService { ICollection GetNoteNames(); - string GetText(string? noteName); - void SaveText(string content, string? noteName); + string GetText(string noteName); + void SaveText(string content, string noteName); void DeleteNote(string noteName); } } diff --git a/Views/Note/Index.cshtml b/Views/Note/Index.cshtml index 8dee1b3..f643373 100644 --- a/Views/Note/Index.cshtml +++ b/Views/Note/Index.cshtml @@ -3,9 +3,11 @@
- @foreach (var note in Model.NoteNames) + @foreach (var note in Model.NoteNames.Order()) { - @note + var css = note.Equals(Model.CurrentNote, StringComparison.OrdinalIgnoreCase) ? "current" : null; + + @note }
diff --git a/appsettings.json b/appsettings.json index e7daff3..17bfc41 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,6 +6,7 @@ } }, "AllowedHosts": "*", - "DefaultContentFileName": "content", - "ContentFilePath": "notes" + "FileNoteService": { + "ContentFilePath": "notes" + } } diff --git a/notes/birds b/notes/birds new file mode 100644 index 0000000..9fd7e12 --- /dev/null +++ b/notes/birds @@ -0,0 +1 @@ +some bird stufffg hfghf \ No newline at end of file diff --git a/notes/default b/notes/default new file mode 100644 index 0000000..3e82765 --- /dev/null +++ b/notes/default @@ -0,0 +1 @@ +default tesxtg dg \ No newline at end of file diff --git a/notes/sdfsds b/notes/sdfsds new file mode 100644 index 0000000..07c01f0 --- /dev/null +++ b/notes/sdfsds @@ -0,0 +1 @@ +Hi! Feel free to start typing. Every \ No newline at end of file diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 89c8b0a..f815c5e 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -24,18 +24,23 @@ div.note-names { position: fixed; bottom: 5px; left: 0; - font-size: 11px; + font-size: 14px; + opacity: 0.5; } -div.note-names a { - color: #666; - padding: 0 5px; - text-decoration: none; -} + div.note-names a { + color: #666; + padding-left: 10px; + text-decoration: none; + } -div.note-names a:not(:last-of-type) { - border-right: 1px solid #666; -} + div.note-names a.current { + font-weight: bold; + } + + div .note-names a:not(:last-of-type) { + border-right: 1px solid #666; + } textarea { width: 100%; @@ -69,17 +74,17 @@ textarea { border-radius: 5px 5px 0 0; } -.toast.show { - bottom: 0; -} + .toast.show { + bottom: 0; + } -.toast#saved-indicator { - background-color: green; -} + .toast#saved-indicator { + background-color: green; + } -.toast#update-indicator { - background-color: orangered; -} + .toast#update-indicator { + background-color: orangered; + } form input[type=password] { display: block;