support reconnecting and refreshing note content

This commit is contained in:
Ryan Peters 2023-06-05 11:45:20 -04:00
parent 34d389cf6e
commit 77f17b9f67
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using BinaryDad.Notes.Services;
namespace BinaryDad.Notes.Controllers
{
public class ApiController : ControllerBase
{
private readonly INoteService noteService;
public ApiController(INoteService noteService)
{
this.noteService = noteService;
}
public string Note() => noteService.Get();
}
}

View File

@ -53,6 +53,15 @@ $(function () {
showToast('#update-indicator');
});
// update content after reconnected
connection.onreconnected(function() {
$.get('api/note', function(content) {
$textarea.val(content);
showToast('#update-indicator');
console.log('Refreshed after disconnect');
});
});
// set dark mode
if (window.location.hash == '#dark') {
$('body').addClass('dark');