Skip to content

Commit

Permalink
Don't replace auth0 default avatar with our own (#4793)
Browse files Browse the repository at this point in the history
* Don't replace auth0 default avatar with our own

* use test id of ancestor component

---------

Co-authored-by: Berci Kormendy <[email protected]>
  • Loading branch information
gbalint and bkrmendy authored Jan 25, 2024
1 parent cf3c150 commit e1f98aa
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@
.lb-comment-avatar {
inline-size: var(--lb-comment-avatar-size);
flex: none;
visibility: hidden; /* we're rolling our own avatars, for now we just ignore the default LB ones */
}
.lb-comment-details-labels {
gap: calc(0.5 * var(--lb-spacing));
Expand Down
13 changes: 4 additions & 9 deletions editor/src/components/canvas/controls/comment-indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { ThreadData } from '@liveblocks/client'
import { Comment } from '@liveblocks/react-comments'
import type { CommentProps } from '@liveblocks/react-comments'
import { AnimatePresence, motion, useAnimate } from 'framer-motion'
import type { CSSProperties } from 'react'
import React from 'react'
import type { ThreadMetadata } from '../../../../liveblocks.config'
import type { ThreadMetadata, UserMeta } from '../../../../liveblocks.config'
import { useEditThreadMetadata, useStorage } from '../../../../liveblocks.config'
import {
getCollaboratorById,
Expand Down Expand Up @@ -37,7 +38,6 @@ import {
} from '../../../core/shared/multiplayer'
import { useMyUserId } from '../../../core/shared/multiplayer-hooks'
import { optionalMap } from '../../../core/shared/optional-utils'
import type { CommentWrapperProps } from '../../../utils/multiplayer-wrapper'
import { MultiplayerWrapper, baseMultiplayerAvatarStyle } from '../../../utils/multiplayer-wrapper'
import { when } from '../../../utils/react-conditionals'
import { UtopiaStyles, colorTheme } from '../../../uuiui'
Expand Down Expand Up @@ -567,9 +567,10 @@ function useHover() {

type CommentIndicatorWrapper = {
thread: ThreadData<ThreadMetadata>
user: UserMeta | null
expanded: boolean
forceDarkMode: boolean
} & CommentWrapperProps
} & CommentProps

const CommentIndicatorWrapper = React.memo((props: CommentIndicatorWrapper) => {
const { thread, expanded, user, forceDarkMode, ...commentProps } = props
Expand Down Expand Up @@ -654,9 +655,3 @@ const CommentIndicatorWrapper = React.memo((props: CommentIndicatorWrapper) => {
</div>
)
})

function getCanvasHeight(): number {
const canvasDiv = document.getElementById('canvas-root')
const canvasHeight = canvasDiv?.clientHeight ?? 0
return canvasHeight
}
14 changes: 4 additions & 10 deletions editor/src/components/canvas/controls/comment-popup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CommentData } from '@liveblocks/client'
import type { ComposerSubmitComment } from '@liveblocks/react-comments'
import { Composer } from '@liveblocks/react-comments'
import { Comment, Composer } from '@liveblocks/react-comments'
import { useAtom } from 'jotai'
import type { CSSProperties } from 'react'
import React, { useRef } from 'react'
Expand All @@ -22,7 +22,7 @@ import * as EP from '../../../core/shared/element-path'
import { emptyComments, jsExpressionValue } from '../../../core/shared/element-template'
import { create } from '../../../core/shared/property-path'
import { assertNever } from '../../../core/shared/utils'
import { CommentWrapper, MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'
import { MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'
import { when } from '../../../utils/react-conditionals'
import { Button, FlexRow, Icn, Tooltip, UtopiaStyles, colorTheme } from '../../../uuiui'
import {
Expand Down Expand Up @@ -376,11 +376,9 @@ const CommentThread = React.memo(({ comment }: CommentThreadProps) => {
onScroll={onScroll}
>
{thread.comments.map((c) => {
const user = getCollaboratorById(collabs, c.userId)
return (
<CommentWrapper
<Comment
key={c.id}
user={user}
comment={c}
onCommentDelete={onCommentDelete}
style={{ background: colorTheme.bg1.value }}
Expand Down Expand Up @@ -546,9 +544,6 @@ ListShadow.displayName = 'ListShadow'

const HeaderComment = React.memo(
({ comment, enabled }: { comment: CommentData; enabled: boolean }) => {
const collabs = useStorage((storage) => storage.collaborators)
const user = getCollaboratorById(collabs, comment.userId)

if (!enabled) {
return null
}
Expand All @@ -567,8 +562,7 @@ const HeaderComment = React.memo(
transform: 'scale(1.01)',
}}
>
<CommentWrapper
user={user}
<Comment
comment={comment}
style={{ background: colorTheme.bg1.value, color: colorTheme.fg1.value }}
/>
Expand Down
10 changes: 3 additions & 7 deletions editor/src/components/inspector/sections/comment-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
switchEditorMode,
} from '../../editor/actions/action-creators'
import { EditorModes, isCommentMode, isExistingComment } from '../../editor/editor-modes'
import { CommentWrapper, MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'
import { MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'
import { useRemixNavigationContext } from '../../canvas/remix/utopia-remix-root-component'
import {
useResolveThread,
Expand Down Expand Up @@ -45,6 +45,7 @@ import { CommentRepliesCounter } from '../../canvas/controls/comment-replies-cou
import type { SelectOption } from '../controls/select-control'
import { assertNever } from '../../../core/shared/utils'
import { pluck } from '../../../core/shared/array-utils'
import { Comment } from '@liveblocks/react-comments'

export type CommentFilterMode = 'all' | 'all-including-resolved' | 'unread-only'

Expand Down Expand Up @@ -319,12 +320,7 @@ const ThreadPreview = React.memo(({ thread }: ThreadPreviewProps) => {
filter: thread.metadata.resolved ? 'grayscale()' : undefined,
}}
>
<CommentWrapper
user={user}
comment={comment}
showActions={false}
style={{ backgroundColor: 'transparent' }}
/>
<Comment comment={comment} showActions={false} style={{ backgroundColor: 'transparent' }} />
{when(
remixLocationRouteLabel != null,
<div
Expand Down
9 changes: 2 additions & 7 deletions editor/src/components/user-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
canFollowTarget,
excludeMyConnection,
followTarget,
isDefaultAuth0AvatarURL,
multiplayerColorFromIndex,
multiplayerInitialsFromName,
normalizeMultiplayerName,
Expand Down Expand Up @@ -344,9 +343,7 @@ export type MultiplayerAvatarProps = {
}

export const MultiplayerAvatar = React.memo((props: MultiplayerAvatarProps) => {
const picture = React.useMemo(() => {
return isDefaultAuth0AvatarURL(props.picture ?? null) ? null : props.picture
}, [props.picture])
const { picture } = props

const tooltipText = <strong>{props.tooltip?.text}</strong>
const tooltipSubtext =
Expand Down Expand Up @@ -447,9 +444,7 @@ interface AvatarPictureProps {
}

const AvatarPicture = React.memo((props: AvatarPictureProps) => {
const url = React.useMemo(() => {
return isDefaultAuth0AvatarURL(props.url ?? null) ? null : props.url
}, [props.url])
const { url } = props

const { initials, size } = props

Expand Down
10 changes: 0 additions & 10 deletions editor/src/core/shared/multiplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ export function excludeMyConnection(
})
}

const reAuth0DefaultAvatarURLEncoded = /https%3A%2F%2Fcdn\.auth0\.com%2Favatars%2F.{2}\.png$/
const reAuth0DefaultAvatar = /https:\/\/cdn\.auth0\.com\/avatars\/.{2}\.png$/

export function isDefaultAuth0AvatarURL(s: string | null): boolean {
return (
s != null &&
(s.match(reAuth0DefaultAvatarURLEncoded) != null || s.match(reAuth0DefaultAvatar) != null)
)
}

export type FollowTarget = {
playerId: string
connectionId: number
Expand Down
25 changes: 0 additions & 25 deletions editor/src/utils/multiplayer-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,3 @@ export const baseMultiplayerAvatarStyle: CSSProperties = {
width: 25.5, // matching the size of the liveblocks component
height: 25.5, // matching the size of the liveblocks component
}

export type CommentWrapperProps = {
user: UserMeta | null
} & CommentProps

export const CommentWrapper = React.memo((props: CommentWrapperProps) => {
const { user, ...commentProps } = props

if (user == null) {
return <Comment {...commentProps} />
}

return (
<div data-testid='comment-wrapper' style={{ position: 'relative' }}>
<MultiplayerAvatar
name={multiplayerInitialsFromName(normalizeMultiplayerName(user.name))}
color={multiplayerColorFromIndex(null)}
style={baseMultiplayerAvatarStyle}
picture={user.avatar}
/>
<Comment {...commentProps} />
</div>
)
})
CommentWrapper.displayName = 'CommentWrapper'
2 changes: 1 addition & 1 deletion puppeteer-tests/src/comments/commenting.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Comments test', () => {
expect(popupAfterClose).toHaveLength(0)

// Open the comment popup again
const comment = await page.waitForSelector('div[data-testid="comment-wrapper"]')
const comment = await page.waitForSelector('div[data-testid="comment-indicator-wrapper"]')
await comment!.click({ offset: { x: 10, y: 10 } })

// Check that the comment popup is open
Expand Down

0 comments on commit e1f98aa

Please sign in to comment.