| 1 |
import { fetchImageCredits } from '@shared/api/DataApi'; |
| 2 |
import { useImageGenerationStore } from '@shared/state/generate-images'; |
| 3 |
import { useEffect } from '@wordpress/element'; |
| 4 |
|
| 5 |
// The local count is a guess between generations, so ask the server on open. |
| 6 |
export const useImageCreditsSync = () => { |
| 7 |
const updateImageCredits = useImageGenerationStore( |
| 8 |
(state) => state.updateImageCredits, |
| 9 |
); |
| 10 |
|
| 11 |
useEffect(() => { |
| 12 |
fetchImageCredits() |
| 13 |
.then(updateImageCredits) |
| 14 |
// A failed peek leaves the last known count in place. |
| 15 |
.catch(() => {}); |
| 16 |
}, [updateImageCredits]); |
| 17 |
}; |
| 18 |
|