-
Notifications
You must be signed in to change notification settings - Fork 2
Description
In the useCdaBlob callback it only handles text or json.
groundwork-water/lib/components/data/hooks/useCdaBlob.ts
Lines 27 to 31 in f455ee1
| if (contentType && contentType.includes("application/json")) { | |
| return await response.raw.json(); | |
| } else { | |
| return await response.raw.text(); | |
| } |
This means PDF/images will return a URL encoded response that will not be directly usable in a param URL.
I intended users would directly query for these resources i.e.
<img src="/cwms-data/blobs/EUFA.PLOT.PNG?office=SWT" />However, with some tweaks useCdaBlob could be made to return all data types.
One issue I forsee is that we would need utility hooks to handle converting to raw response to an ObjectURL. Which has its own issues with lifecycle vs the caching React does.
Something like this could resolve the ObjectURL issue.
export function useObjectUrl(blob?: Blob | null) {
const [url, setUrl] = useState<string | null>(null);
useEffect(() => {
if (!blob) {
setUrl(null);
return;
}
const next = URL.createObjectURL(blob);
setUrl(next);
return () => {
URL.revokeObjectURL(next);
};
}, [blob]);
return url;
}Perhaps?
Side note: I'm using blobraw because the current swagger spec cwmsjs was built on returned null for the Blob type on the promise. Also needing the response object to determine the type.