refactor: consolidate shared application helpers
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { registerPendingSave } from "@/lib/admin-form-save-bridge";
|
||||
|
||||
export type AutoSaveStatus = "clean" | "dirty" | "saving" | "saved" | "error";
|
||||
|
||||
type FlushSave = () => Promise<void>;
|
||||
|
||||
const pendingSaves = new Set<FlushSave>();
|
||||
|
||||
export function registerPendingSave(flush: FlushSave) {
|
||||
pendingSaves.add(flush);
|
||||
return () => {
|
||||
pendingSaves.delete(flush);
|
||||
};
|
||||
}
|
||||
|
||||
export async function flushPendingSaves() {
|
||||
await Promise.all([...pendingSaves].map((flush) => flush()));
|
||||
}
|
||||
|
||||
export function useDebouncedAutoSave({
|
||||
save,
|
||||
delay = 1000,
|
||||
|
||||
Reference in New Issue
Block a user