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

Commit

Permalink
Merge pull request #168 from ChaituVR/add-extension-banner
Browse files Browse the repository at this point in the history
Add banner calling for users to install extension to the hompage
  • Loading branch information
harumhelmy authored Aug 26, 2020
2 parents 25bc87a + fe820dd commit cd38dad
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
41 changes: 40 additions & 1 deletion src/components/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
flex: 0 0 var(--middle-column-default-width);
width: var(--middle-column-default-width);
max-width: calc(100vw - var(--left-panel-min-width));

margin-bottom: 60px;
position: relative;
box-sizing: border-box;
@media (--narrow-screen) {
Expand Down Expand Up @@ -103,4 +103,43 @@
margin: var(--xsgrd);
}
}

& .home__extention-banner {
position: fixed;
text-align: center;
font: var(--ui-basic-font);
font-size: medium;
line-height: 1.25em;
background-color: var(--prereview-red);
color: white;
flex: 0 0 var(--middle-column-default-width);
text-shadow: 0px 0px 10px #eb0000;
left: var(--left-panel-min-width);
bottom: 0;
width: var(--middle-column-default-width);
max-width: calc(80vw - var(--left-panel-min-width));
padding: var(--xsgrd) var(--xlgrd);
margin: var(--mgrd) var(--sgrd) 0;
border-top-left-radius: var(--xsgrd);
border-top-right-radius: var(--xsgrd);
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
z-index: 1000;
@media (--narrow-screen) {
left: 0;
font-size: inherit;
max-width: calc(100vw - 130px);
}
@media (--mobile) {
display: none;
}
& .home-extension-banner__close-button {
position: absolute;
right: 0;
top: 0;
color: inherit;
}
& :any-link {
color: white;
}
}
}
27 changes: 26 additions & 1 deletion src/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { usePreprintSearchResults } from '../hooks/api-hooks';
import {
useIsNewVisitor,
useIsMobile,
useNewPreprints
useNewPreprints,
useDisplayExtensionBanner
} from '../hooks/ui-hooks';
import { useUser } from '../contexts/user-context';
import { unprefix, getId } from '../utils/jsonld';
Expand All @@ -26,6 +27,9 @@ import { createPreprintQs, apifyPreprintQs } from '../utils/search';
import WelcomeModal from './welcome-modal';
import XLink from './xlink';
import AddButton from './add-button';
import IconButton from './icon-button';
import VisuallyHidden from '@reach/visually-hidden';
import { MdClose } from 'react-icons/md';
import { ORG } from '../constants';
import Banner from './banner';

Expand All @@ -38,6 +42,7 @@ export default function Home() {
const [showLeftPanel, setShowLeftPanel] = useState(!isMobile);
const [loginModalOpenNext, setLoginModalOpenNext] = useState(null);
const isNewVisitor = useIsNewVisitor();
const [displayExtensionBanner, closeExtensionBanner, checkForExtension] = useDisplayExtensionBanner();
const [isWelcomeModalOpen, setIsWelcomeModalOpen] = useState(true);
const [newPreprints, setNewPreprints] = useNewPreprints();

Expand Down Expand Up @@ -115,6 +120,7 @@ export default function Home() {
<WelcomeModal
onClose={() => {
setIsWelcomeModalOpen(false);
checkForExtension();
}}
/>
)}
Expand Down Expand Up @@ -323,6 +329,25 @@ export default function Home() {
</div>

<div className="home__main__right"></div>
{
displayExtensionBanner && (<div className="home__extention-banner">
You have not yet installed the Outbreak Science Rapid PREreivew browser extension to enable requesting, adding and/or reading rapid reviews on other websites. Install it&nbsp;
<a
href="https://outbreaksci.prereview.org/extension"
target="_blank"
rel="noopener noreferrer"
>
here
</a>!
<IconButton
className="home-extension-banner__close-button"
onClick={closeExtensionBanner}
>
<VisuallyHidden>Close</VisuallyHidden>
<MdClose className="home-extension-banner_close-button__icon" />
</IconButton>
</div>)
}
</div>
</div>
);
Expand Down
27 changes: 27 additions & 0 deletions src/hooks/ui-hooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useState, useEffect, useCallback, useRef } from 'react';
import {
CSS_SCOPE_ID
} from '../constants';
import { useStores } from '../contexts/store-context';

/**
Expand Down Expand Up @@ -156,3 +159,27 @@ export function usePrevious(value) {
// Return previous value (happens before update in useEffect above)
return ref.current;
}

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'){
checkForExtension();
}
}, []);

const localSet = useCallback(() => {
localStorage.setItem('displayExtensionBanner', 'false');
setDisplayExtensionBanner(false);
}, []);

return [displayExtensionBanner, localSet, checkForExtension];
}

0 comments on commit cd38dad

Please sign in to comment.