feat: replace raw setInterval polling with shared Poller utility across six frontend modules
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import { Http } from "./Http.js";
|
||||
import { Toast } from "./Toast.js";
|
||||
|
||||
export class OptimisticAction {
|
||||
async submit(url, params, errorTarget, render) {
|
||||
try {
|
||||
const result = await Http.sendForm(url, params);
|
||||
if (render) render(result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("optimistic action failed", error);
|
||||
if (errorTarget) Toast.flash(errorTarget, "Error", 1500);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user