Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Fix first time visit modal issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Aug 14, 2020
1 parent c0fdb9b commit c39de50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function Home() {
const [showLeftPanel, setShowLeftPanel] = useState(!isMobile);
const [loginModalOpenNext, setLoginModalOpenNext] = useState(null);
const isNewVisitor = useIsNewVisitor();
const [displayExtensionBanner, closeExtensionBanner] = useDisplayExtensionBanner();
const [displayExtensionBanner, closeExtensionBanner, checkForExtension] = useDisplayExtensionBanner();
const [isWelcomeModalOpen, setIsWelcomeModalOpen] = useState(true);
const [newPreprints, setNewPreprints] = useNewPreprints();

Expand Down Expand Up @@ -120,6 +120,7 @@ export default function Home() {
<WelcomeModal
onClose={() => {
setIsWelcomeModalOpen(false);
checkForExtension();
}}
/>
)}
Expand Down
14 changes: 9 additions & 5 deletions src/hooks/ui-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ export function usePrevious(value) {
export function useDisplayExtensionBanner() {
const [displayExtensionBanner, setDisplayExtensionBanner] = useState(false);

const checkForExtension = () => {
setTimeout(() => {
const shouldDisplayExtensionBanner = localStorage.getItem('displayExtensionBanner') !== 'false' && !document.getElementById(CSS_SCOPE_ID);
setDisplayExtensionBanner(shouldDisplayExtensionBanner);
},500);
}

useEffect(() => {
if(document.readyState === 'interactive' || document.readyState === 'complete'){
setTimeout(() => {
const shouldDisplayExtensionBanner = localStorage.getItem('displayExtensionBanner') !== 'false' && !document.getElementById(CSS_SCOPE_ID);
setDisplayExtensionBanner(shouldDisplayExtensionBanner);
},500)
checkForExtension();
}
}, []);

Expand All @@ -177,5 +181,5 @@ export function useDisplayExtensionBanner() {
setDisplayExtensionBanner(false);
}, []);

return [displayExtensionBanner, localSet];
return [displayExtensionBanner, localSet, checkForExtension];
}

0 comments on commit c39de50

Please sign in to comment.