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

Commit

Permalink
Add extension banner to the hompage
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Aug 14, 2020
1 parent 61d83f5 commit c0fdb9b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/components/header-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
border-top-left-radius: var(--xsgrd);
border-bottom-left-radius: var(--xsgrd);
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
@media (--narrow-screen) {
bottom: calc(var(--xlgrd) + 50px);
}
@media (--mobile) {
bottom: var(--xlgrd);
}
& :any-link {
color: white;
text-decoration: none;
Expand Down
45 changes: 44 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,47 @@
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;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
}
26 changes: 25 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] = useDisplayExtensionBanner();
const [isWelcomeModalOpen, setIsWelcomeModalOpen] = useState(true);
const [newPreprints, setNewPreprints] = useNewPreprints();

Expand Down Expand Up @@ -323,6 +328,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
23 changes: 23 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,23 @@ export function usePrevious(value) {
// Return previous value (happens before update in useEffect above)
return ref.current;
}

export function useDisplayExtensionBanner() {
const [displayExtensionBanner, setDisplayExtensionBanner] = useState(false);

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

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

return [displayExtensionBanner, localSet];
}

0 comments on commit c0fdb9b

Please sign in to comment.