Skip to content

Commit

Permalink
[default-layout] Use UserAvatar for current user avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Oct 6, 2020
1 parent 072099d commit 76d7674
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 54 deletions.
4 changes: 4 additions & 0 deletions packages/@sanity/default-layout/src/@types/parts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ declare module 'part:@sanity/base/chevron-down-icon' {
export default Icon
}

declare module 'part:@sanity/components/avatar' {
export const Avatar: any
}

declare module 'part:@sanity/components/menus/default' {
const DefaultMenu: React.ComponentType<{
items: {action: string; icon: React.ComponentType<{}>; title: string}[]
Expand Down
1 change: 0 additions & 1 deletion packages/@sanity/default-layout/src/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class DefaultLayout extends React.PureComponent<Props, State> {
onToggleMenu={this.handleToggleMenu}
onSwitchTool={this.handleSwitchTool}
router={router}
user={this.state.user}
searchIsOpen={searchIsOpen}
/* eslint-disable-next-line react/jsx-handler-names */
onUserLogout={userStore.actions.logout}
Expand Down
13 changes: 2 additions & 11 deletions packages/@sanity/default-layout/src/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {StateLink} from 'part:@sanity/base/router'
import {Tooltip} from 'part:@sanity/components/tooltip'
import * as sidecar from 'part:@sanity/default-layout/sidecar?'
import {HAS_SPACES} from '../util/spaces'
import {Router, Tool, User} from '../types'
import {Router, Tool} from '../types'
import Branding from './branding/Branding'
import LoginStatus from './loginStatus/LoginStatus'
import SanityStatusContainer from './studioStatus/SanityStatusContainer'
Expand All @@ -32,7 +32,6 @@ interface Props {
showLabel: boolean
showToolSwitcher: boolean
tools: Tool[]
user?: User
}

const TOUCH_DEVICE = 'ontouchstart' in document.documentElement
Expand All @@ -57,7 +56,6 @@ function Navbar(props: Props) {
onSetSearchElement,
router,
tools,
user,
showLabel,
showToolSwitcher
} = props
Expand Down Expand Up @@ -138,7 +136,7 @@ function Navbar(props: Props) {
</div>
)}
<div className={styles.loginStatus} ref={onSetLoginStatusElement}>
<LoginStatus onLogout={onUserLogout} user={user} />
<LoginStatus onLogout={onUserLogout} />
</div>
<button className={styles.searchButton} onClick={onSearchOpen} type="button">
<div className={styles.searchButtonInner} tabIndex={-1}>
Expand All @@ -152,11 +150,4 @@ function Navbar(props: Props) {
)
}

Navbar.defaultProps = {
showLabel: true,
showToolSwitcher: true,
onSetLoginStatusElement: undefined,
onSetSearchElement: undefined
}

export default Navbar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import {Router, Tool} from '../types'
import Navbar from './Navbar'
import {Router, Tool, User} from '../types'

interface Props {
onCreateButtonClick: () => void
Expand All @@ -12,7 +12,6 @@ interface Props {
router: Router
searchIsOpen: boolean
tools: Tool[]
user?: User
}

interface NextState {
Expand Down Expand Up @@ -171,8 +170,7 @@ class NavbarContainer extends React.PureComponent<Props, State> {
onUserLogout,
router,
searchIsOpen,
tools,
user
tools
} = this.props
const {showLabel, showToolSwitcher} = this.state

Expand All @@ -191,7 +189,6 @@ class NavbarContainer extends React.PureComponent<Props, State> {
showLabel={showLabel}
showToolSwitcher={showToolSwitcher}
tools={tools}
user={user}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,9 @@
}

.inner {
padding: 0.5em;
padding: var(--small-padding) var(--medium-padding) var(--small-padding) var(--small-padding);
position: relative;
outline: none;

@nest &::after {
content: '';
position: absolute;
display: block;
box-sizing: border-box;
top: 0.5em;
left: 1em;
right: 1em;
bottom: 0.5em;
border: 1px solid color(var(--white) alpha(15%));
border-radius: 50%;
}
}

.userImage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from 'classnames'
import React from 'react'
import enhanceClickOutside from 'react-click-outside'
import {UserAvatar} from '@sanity/base/components'
import Menu from 'part:@sanity/components/menus/default'
import {Popover} from 'part:@sanity/components/popover'
import IconSignOut from 'part:@sanity/base/sign-out-icon'
Expand All @@ -9,11 +10,6 @@ import styles from './LoginStatus.css'
interface Props {
className: string
onLogout: () => void
user: {
email: string
name?: string
profileImage?: string
}
}

interface State {
Expand All @@ -23,8 +19,7 @@ interface State {
class LoginStatus extends React.PureComponent<Props, State> {
static defaultProps = {
className: undefined,
onLogout: undefined,
user: undefined
onLogout: undefined
}

state = {isOpen: false}
Expand All @@ -48,10 +43,6 @@ class LoginStatus extends React.PureComponent<Props, State> {
}

render() {
const {user} = this.props

if (!user) return null

return (
<div className={classNames(styles.root, this.props.className)}>
<Popover
Expand Down Expand Up @@ -81,18 +72,7 @@ class LoginStatus extends React.PureComponent<Props, State> {
type="button"
>
<div className={styles.inner} tabIndex={-1}>
{user.profileImage ? (
<img
src={user.profileImage}
className={styles.userImage}
alt={`${user.name}'s profile image`}
data-initials={(user.name || user.email || '?').charAt(0)}
/>
) : (
<div className={styles.userImageMissing}>
{user.name ? user.name.charAt(0) : user.email.charAt(0)}
</div>
)}
<UserAvatar size="medium" tone="navbar" userId="me" />
</div>
</button>
</Popover>
Expand Down

0 comments on commit 76d7674

Please sign in to comment.