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 From 70354165ff1956dd0598ff69736fb0436612003c Mon Sep 17 00:00:00 2001 From: ludovicm67 Date: Fri, 24 Jan 2020 00:43:12 +0100 Subject: webui: remove useless conditions --- webui/src/CurrentIdentity.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'webui/src/CurrentIdentity.js') diff --git a/webui/src/CurrentIdentity.js b/webui/src/CurrentIdentity.js index c8afc531..451979fb 100644 --- a/webui/src/CurrentIdentity.js +++ b/webui/src/CurrentIdentity.js @@ -25,22 +25,16 @@ 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; + {({ loading, error, data }) => { + if (error || loading || !data.defaultRepository.userIdentity) + return null; + const user = data.defaultRepository.userIdentity; return ( <> - {displayName.charAt(0).toUpperCase()} -
{displayName}
+ + {user.displayName.charAt(0).toUpperCase()} + +
{user.displayName}
); }} -- cgit