forked from opentargets/ot-ui-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to show top bar with logo and username (#1)
Co-authored-by: Fedde Schaeffer <[email protected]>
- Loading branch information
Showing
8 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as Footer } from "./src/Footer"; | ||
export { default as ThemeProvider } from "./src/ThemeProvider/ThemeProvider"; | ||
export { default as LoadingBackdrop } from "./src/LoadingBackdrop"; | ||
export { default as TopBar } from "./src/TopBar"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import AppBar from '@material-ui/core/AppBar'; | ||
import useScrollTrigger from '@material-ui/core/useScrollTrigger'; | ||
import { Typography } from '@material-ui/core'; | ||
|
||
|
||
/** | ||
* Shadows the AppBar to hint at content scrolling up. | ||
* | ||
* @see {@link https://mui.com/material-ui/react-app-bar/#elevate-app-bar} | ||
*/ | ||
function ElevationScroll({children}) { | ||
const trigger = useScrollTrigger({ | ||
disableHysteresis: true, | ||
threshold: 0, | ||
}); | ||
return React.cloneElement(children, { | ||
elevation: trigger ? 4 : 0, | ||
}); | ||
} | ||
|
||
export default function TopBar() { | ||
const [username, setUsername] = useState(''); | ||
useEffect(() => { | ||
let isCurrent = true; | ||
|
||
async function displayLoggedInUser() { | ||
const userFunction = window.getLoggedInUser || (() => Promise.resolve('')); | ||
const username = await resolveWithNameOrErrorMessage(userFunction()); | ||
if (isCurrent) { | ||
setUsername(username) | ||
} | ||
} | ||
async function resolveWithNameOrErrorMessage(userPromise) { | ||
try { | ||
return await userPromise; | ||
} catch { | ||
return 'Unidentified user'; | ||
} | ||
} | ||
displayLoggedInUser(); | ||
|
||
return () => { | ||
isCurrent = false; | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<ElevationScroll> | ||
<AppBar | ||
id="ot-org-top-bar" | ||
style={{ | ||
display: 'block', | ||
position: 'fixed', | ||
backgroundColor: '#005284', | ||
zIndex: 2000000, | ||
height: '50px', | ||
width: '100%', | ||
}} | ||
> | ||
<img | ||
src="/assets/img/logo-org.png" | ||
title="Logo" | ||
alt="Logo" | ||
style={{ | ||
float: 'left', | ||
marginLeft: '20px', | ||
marginTop: '5px', | ||
height: '40px', | ||
}} | ||
/> | ||
<Typography | ||
title="Logged-in user" | ||
style={{ | ||
float: 'right', | ||
marginRight: '20px', | ||
marginTop: '15px', | ||
color: 'white', | ||
fontFamily: 'Inter, serif', | ||
fontStyle: 'italic', | ||
}} | ||
> | ||
{username} | ||
</Typography> | ||
</AppBar> | ||
</ElevationScroll> | ||
); | ||
} |