diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs new file mode 100644 index 0000000..2112ea0 --- /dev/null +++ b/Controllers/ApiController.cs @@ -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(); + } +} diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 6aa913e..febc9f0 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -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');