From def48e53f4ae206a10d0973439efdd7769e91100 Mon Sep 17 00:00:00 2001 From: ludovicm67 Date: Thu, 23 Jan 2020 23:37:59 +0100 Subject: webui: display current identity in the AppBar --- webui/src/CurrentIdentity.js | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 webui/src/CurrentIdentity.js (limited to 'webui/src/CurrentIdentity.js') diff --git a/webui/src/CurrentIdentity.js b/webui/src/CurrentIdentity.js new file mode 100644 index 00000000..c8afc531 --- /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; -- cgit