Skip to content

Commit

Permalink
fix: useGif crashing renderer when no valid url was given
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Rohloff committed Sep 18, 2024
1 parent 70be4c7 commit 71a981e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/renderer/hooks/useGif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ export default function useGif(url: string): TenorGif | null {
const [gif, setGif] = useState<TenorGif | null>(null);

useEffect(() => {
const uri = new URL(url);
try {
const uri = new URL(url);

if (allowedHosts.includes(uri.host.toLowerCase())) {
if (allowedHosts.includes(uri.host.toLowerCase())) {
setGif(null);
return;
}

window.electron.ipcRenderer
.invoke('tenor:fetch-gif', url)
.then((result: TenorFetchResult) => {
setGif(result.gif);
return true;
})
.catch((err) => console.error(err));
} catch {
setGif(null);
return;
}

window.electron.ipcRenderer
.invoke('tenor:fetch-gif', url)
.then((result: TenorFetchResult) => {
setGif(result.gif);
return true;
})
.catch((err) => console.error(err));
}, [url]);

return gif;
Expand Down

0 comments on commit 71a981e

Please sign in to comment.