24 lines
805 B
TypeScript
24 lines
805 B
TypeScript
import { useState } from "react";
|
|
import { toast } from "react-toastify";
|
|
import { exportRecipesPdf } from "./recipePdf";
|
|
|
|
/** Export receptů do PDF s příznakem probíhajícího exportu a hláškou při chybě. */
|
|
export const useRecipeExport = () => {
|
|
const [exporting, setExporting] = useState(false);
|
|
|
|
const exportRecipes = async (itemList: Parameters<typeof exportRecipesPdf>[0]) => {
|
|
if (exporting || !itemList.length) return;
|
|
setExporting(true);
|
|
try {
|
|
await exportRecipesPdf(itemList);
|
|
} catch (error) {
|
|
console.error('Export receptů do PDF selhal', error);
|
|
toast.error('PDF se nepodařilo vytvořit.');
|
|
} finally {
|
|
setExporting(false);
|
|
}
|
|
};
|
|
|
|
return { exporting, exportRecipes };
|
|
};
|