From a42ca7957cbfb9fa7da5651a352b1aac94a0b686 Mon Sep 17 00:00:00 2001 From: Raghunandan Date: Tue, 2 Jun 2020 19:16:33 +0200 Subject: [PATCH] Minor styling fixes --- .../src/layout/Sidebar/LoggedUserBadge.tsx | 267 ++++++++++-------- 1 file changed, 149 insertions(+), 118 deletions(-) diff --git a/packages/core/src/layout/Sidebar/LoggedUserBadge.tsx b/packages/core/src/layout/Sidebar/LoggedUserBadge.tsx index 9f1fe1d3f7..42fdb6a05f 100644 --- a/packages/core/src/layout/Sidebar/LoggedUserBadge.tsx +++ b/packages/core/src/layout/Sidebar/LoggedUserBadge.tsx @@ -58,9 +58,136 @@ const useStyles = makeStyles(theme => { color: theme.palette.getContrastText(blueGrey[500]), backgroundColor: blueGrey[500], }, + listItemText: { + overflow: 'hidden', + textOverflow: 'ellipsis', + }, }; }); +const SessionListItem: FC<{ + classes: any; + loading: boolean; + title: string; + icon: any; + user: any; + onSignIn: Function; + onSignOut: Function; +}> = ({ + classes, + loading, + title, + icon, + user, + onSignIn, + onSignOut, + ...props +}) => { + if (loading) { + return ( + + + + + } + secondary={} + /> + + + + + + + ); + } + + if (!user) { + return ( + + {icon} + + + + onSignIn()}> + + + + + + ); + } + + const { id, avatarUrl, avatarAlt } = user; + + return ( + + + + {avatarAlt && avatarAlt[0].toUpperCase()} + + + + + + onSignOut()}> + + + + + + ); +}; + +const useGoogleLoginState = (open: boolean) => { + const googleAuth = useApi(googleAuthApiRef); + const [loading, setLoading] = useState(true); + const [profile, setProfile] = useState(); + + useEffect(() => { + if (!open) { + return; + } + + let didCancel = false; + + googleAuth.getProfile().then(profile => { + if (didCancel) { + return; + } + + setProfile(profile); + setLoading(false); + }); + + return () => { + didCancel = true; + }; + }, [open]); + + if (loading) { + return { loading: true }; + } + return { loading: false, isLoggedIn: !!profile, profile }; +}; + type Props = { email: string; imageUrl?: string; @@ -117,21 +244,28 @@ export const LoggedUserBadge: FC = ({ return ( <> - - - {imageUrl ? ( - - ) : ( - - {avatarFallback[0]} - + + + + {imageUrl ? ( + + ) : ( + + {avatarFallback[0]} + + )} + + {!collapsedMode && ( + )} - - {!collapsedMode && } - + + = ({ > = ({ ); }; - -const SessionListItem: FC<{ - loading: boolean; - title: string; - icon: any; - user: any; - onSignIn: Function; - onSignOut: Function; -}> = ({ loading, title, icon, user, onSignIn, onSignOut, ...props }) => { - if (loading) { - return ( - - - - - } - secondary={} - /> - - - - - - - ); - } - - if (!user) { - return ( - - {icon} - - - - onSignIn()}> - - - - - - ); - } - - const { id, avatarUrl, avatarAlt } = user; - - return ( - - - - {avatarAlt && avatarAlt[0].toUpperCase()} - - - - - - onSignOut()}> - - - - - - ); -}; - -const useGoogleLoginState = (open: boolean) => { - const googleAuth = useApi(googleAuthApiRef); - const [loading, setLoading] = useState(true); - const [profile, setProfile] = useState(); - - useEffect(() => { - if (!open) { - return; - } - - let didCancel = false; - - googleAuth.getProfile().then(profile => { - if (didCancel) { - return; - } - - setProfile(profile); - setLoading(false); - }); - - return () => { - didCancel = true; - }; - }, [open]); - - if (loading) { - return { loading: true }; - } - return { loading: false, isLoggedIn: !!profile, profile }; -};