From def48e53f4ae206a10d0973439efdd7769e91100 Mon Sep 17 00:00:00 2001 From: ludovicm67 Date: Thu, 23 Jan 2020 23:37:59 +0100 Subject: [PATCH] webui: display current identity in the AppBar --- webui/src/App.js | 12 ++++++--- webui/src/CurrentIdentity.js | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 webui/src/CurrentIdentity.js diff --git a/webui/src/App.js b/webui/src/App.js index 145cd90da215528ade5d6899bd4f18ac335af480..357782682f95d60fa87c62967d42f763d16b6303 100644 --- a/webui/src/App.js +++ b/webui/src/App.js @@ -9,6 +9,7 @@ import { Link } from 'react-router-dom'; import BugQuery from './bug/BugQuery'; import ListQuery from './list/ListQuery'; +import CurrentIdentity from './CurrentIdentity'; const theme = createMuiTheme({ palette: { @@ -24,6 +25,8 @@ const useStyles = makeStyles(theme => ({ ...theme.typography.h6, color: 'white', textDecoration: 'none', + }, + headerLeft: { flexGrow: 1, }, })); @@ -36,9 +39,12 @@ export default function App() { - - git-bug webui - +
+ + git-bug webui + +
+
diff --git a/webui/src/CurrentIdentity.js b/webui/src/CurrentIdentity.js new file mode 100644 index 0000000000000000000000000000000000000000..c8afc531559e7b4d2059ece0987a73845a1ddafb --- /dev/null +++ b/webui/src/CurrentIdentity.js @@ -0,0 +1,51 @@ +import React from 'react'; +import gql from 'graphql-tag'; +import { Query } from 'react-apollo'; +import Avatar from '@material-ui/core/Avatar'; +import { makeStyles } from '@material-ui/styles'; + +const useStyles = makeStyles(theme => ({ + displayName: { + marginLeft: theme.spacing(2), + }, +})); + +const QUERY = gql` + { + defaultRepository { + userIdentity { + displayName + avatarUrl + } + } + } +`; + +const CurrentIdentity = () => { + const classes = useStyles(); + return ( + + {({ error, data }) => { + if ( + error || + !data || + !data.defaultRepository || + !data.defaultRepository.userIdentity || + !data.defaultRepository.userIdentity.displayName + ) + return <>; + const displayName = + data.defaultRepository.userIdentity.displayName || ''; + const avatar = data.defaultRepository.userIdentity.avatarUrl; + return ( + <> + {displayName.charAt(0).toUpperCase()} +
{displayName}
+ + ); + }} +
+ ); +}; + +export default CurrentIdentity;