working nicely

This commit is contained in:
Ryan Peters 2023-05-17 21:44:41 -04:00
parent 8e7b9c9622
commit 400f20e916
10 changed files with 44 additions and 37 deletions

View File

@ -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()
};

View File

@ -2,6 +2,7 @@ namespace BinaryDad.Notes.Models;
public class ContentModel
{
public string CurrentNote { get; set; } = string.Empty;
public ICollection<string> NoteNames { get; set; } = new List<string>();
public string Text { get; set; } = string.Empty;
}

View File

@ -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);

View File

@ -3,8 +3,8 @@
public interface INoteService
{
ICollection<string> 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);
}
}

View File

@ -3,9 +3,11 @@
<textarea id="content" name="content" spellcheck="false">@Model.Text</textarea>
<div class="note-names">
@foreach (var note in Model.NoteNames)
@foreach (var note in Model.NoteNames.Order())
{
<a href="@note">@note</a>
var css = note.Equals(Model.CurrentNote, StringComparison.OrdinalIgnoreCase) ? "current" : null;
<a href="@note" class="@css">@note</a>
}
</div>

View File

@ -6,6 +6,7 @@
}
},
"AllowedHosts": "*",
"DefaultContentFileName": "content",
"ContentFilePath": "notes"
"FileNoteService": {
"ContentFilePath": "notes"
}
}

1
notes/birds Normal file
View File

@ -0,0 +1 @@
some bird stufffg hfghf

1
notes/default Normal file
View File

@ -0,0 +1 @@
default tesxtg dg

1
notes/sdfsds Normal file
View File

@ -0,0 +1 @@
Hi! Feel free to start typing. Every

View File

@ -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;