mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-06-22 00:38:38 +00:00
9af2577c6e
Since the print cycle now loads all images not-yet-loaded (due to lazy loading), there can be a moment of time where it appears pressing Get PDF is doing nothing, depending on connection speed. To add a "loading" message, a custom event is fired at the start and end of the print cycle (before the print dialog comes up).
26 lines
913 B
React
26 lines
913 B
React
import React, { useState, useEffect } from 'react';
|
|
import Nav from './nav.jsx';
|
|
import { printCurrentBrew } from '@shared/helpers.js';
|
|
|
|
export default function(){
|
|
const [printing, setPrinting] = useState(false);
|
|
|
|
// listen for print cycle events to display "loading" message since it can take some time.
|
|
useEffect(()=>{
|
|
document.addEventListener('print:startprep', handlePrintStartPrep);
|
|
document.addEventListener('print:finishedprep', handlePrintPrepFinished);
|
|
return ()=>{
|
|
document.removeEventListener('print:startprep', handlePrintStartPrep);
|
|
document.removeEventListener('print:finishedprep', handlePrintPrepFinished);
|
|
}
|
|
}, []);
|
|
|
|
const handlePrintStartPrep = ()=>{ setPrinting(true); };
|
|
|
|
const handlePrintPrepFinished = ()=>{ setPrinting(false); };
|
|
|
|
return <Nav.item onClick={printCurrentBrew} color='purple' icon='far fa-file-pdf'>
|
|
{printing ? 'loading' : 'get PDF'}
|
|
</Nav.item>;
|
|
};
|