Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Hussein committed Aug 26, 2024
1 parent ef9dbaa commit 39e3221
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
13 changes: 8 additions & 5 deletions src/components/dls/Toast/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/no-multi-comp */
import { useContext } from 'react';
import { useCallback, useContext } from 'react';

import classNames from 'classnames';
import {
Expand Down Expand Up @@ -86,8 +86,11 @@ export const ToastContainer = () => {
export const useToast = () => {
const setShouldRenderToast = useContext(ToastContext);

return (content: React.ReactNode, options: Options = {}) => {
setShouldRenderToast(true);
toast(content, options);
};
return useCallback(
(content: React.ReactNode, options: Options = {}) => {
setShouldRenderToast(true);
toast(content, options);
},
[setShouldRenderToast],
);
};
20 changes: 12 additions & 8 deletions src/pages/quran-media-maker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,14 @@ const MediaMaker: NextPage<MediaMaker> = ({
chapterEnglishName,
]);

const method = isSafari() ? 'base64' : 'blob-url';

useEffect(() => {
setVideoFileReady(false);
// {@see https://www.remotion.dev/docs/troubleshooting/player-flicker#option-6-prefetching-as-base64-to-avoid-network-request-and-local-http-server}
const { waitUntilDone: waitUntilVideoDone } = prefetch(
staticFile(`/publicMin${inputProps.video.videoSrc}`),
{ method: isSafari() ? 'base64' : 'blob-url' },
{ method },
);

waitUntilVideoDone()
Expand All @@ -311,17 +313,18 @@ const MediaMaker: NextPage<MediaMaker> = ({
continueRender(handleVideo);
})
.catch((e) => {
toast(`${e}`);
toast(t('common:error.general'), {
status: ToastStatus.Error,
});
cancelRender(e);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inputProps.video.videoSrc]);
}, [inputProps.video.videoSrc, method, handleVideo, toast, t]);

useEffect(() => {
setAudioFileReady(false);
// {@see https://www.remotion.dev/docs/troubleshooting/player-flicker#option-6-prefetching-as-base64-to-avoid-network-request-and-local-http-server}
const { waitUntilDone: waitUntilAudioDone } = prefetch(inputProps.audio.audioUrl, {
method: isSafari() ? 'base64' : 'blob-url',
method,
});

waitUntilAudioDone()
Expand All @@ -330,11 +333,12 @@ const MediaMaker: NextPage<MediaMaker> = ({
continueRender(handleAudio);
})
.catch((e) => {
toast(`${e}`);
toast(t('common:error.general'), {
status: ToastStatus.Error,
});
cancelRender(e);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inputProps.audio.audioUrl]);
}, [inputProps.audio.audioUrl, method, handleAudio, toast, t]);

const renderPoster: RenderPoster = useCallback(() => {
const video = getBackgroundVideoById(videoId);
Expand Down

0 comments on commit 39e3221

Please sign in to comment.