polling demo
This commit is contained in:
parent
2caa82b8f4
commit
4673220624
@ -14,6 +14,10 @@ public class ApiController : ControllerBase
|
||||
this.noteService = noteService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("get")]
|
||||
public string Get() => noteService.Get();
|
||||
|
||||
[HttpPost]
|
||||
[Route("save")]
|
||||
public async Task<bool> Save()
|
||||
|
@ -20,6 +20,18 @@
|
||||
});
|
||||
};
|
||||
|
||||
var poller = null;
|
||||
|
||||
let pollJob = function () {
|
||||
|
||||
poller = setInterval(function () {
|
||||
|
||||
$.get('/api/get', function (content) {
|
||||
$('textarea').val(content);
|
||||
});
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
// set dark mode
|
||||
@ -28,18 +40,26 @@ $(function () {
|
||||
}
|
||||
|
||||
var timer = null;
|
||||
|
||||
let ignoredKeyCodes = [17, 18, 20, 27, 37, 38, 39, 40, 91];
|
||||
|
||||
// start polling
|
||||
pollJob();
|
||||
|
||||
// save after half-second delay after typing
|
||||
$('textarea').keyup(function (e) {
|
||||
|
||||
clearTimeout(timer);
|
||||
clearInterval(poller);
|
||||
|
||||
// only set timer if key isn't ignored
|
||||
if (!ignoredKeyCodes.includes(e.keyCode)) {
|
||||
|
||||
timer = setTimeout(function () {
|
||||
saveContent();
|
||||
}, 1000);
|
||||
|
||||
pollJob();
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user