lbry-desktop/ui/component/youtubeWelcome/view.jsx

25 lines
814 B
React
Raw Normal View History

2019-12-05 06:24:54 +01:00
// @flow
import * as MODALS from 'constants/modal_types';
import React from 'react';
import usePersistedState from 'effects/use-persisted-state';
type Props = { doOpenModal: string => void, user: ?User };
2019-12-05 06:24:54 +01:00
const YoutubeWelcome = (props: Props) => {
const { doOpenModal, user } = props;
2019-12-05 06:24:54 +01:00
const [hasBeenShownIntro, setHasBeenShownIntro] = usePersistedState('youtube-welcome', false);
const isYouTubeReferrer = document.referrer.includes('youtube.com');
const shouldShowWelcome = !hasBeenShownIntro && isYouTubeReferrer && user && !user.has_verified_email;
2019-12-05 06:24:54 +01:00
React.useEffect(() => {
if (shouldShowWelcome) {
doOpenModal(MODALS.YOUTUBE_WELCOME);
setHasBeenShownIntro(true);
}
}, [shouldShowWelcome, setHasBeenShownIntro, doOpenModal]);
return null;
};
export default YoutubeWelcome;