Skip to content

Commit

Permalink
Merge branch 'master' into fix/unused-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Jan 7, 2024
2 parents 28fce28 + 7fc0b7f commit e69a797
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 46 deletions.
12 changes: 3 additions & 9 deletions editor/src/components/canvas/controls/comment-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { canvasPointToWindowPoint } from '../dom-lookup'
import { useRemixNavigationContext } from '../remix/utopia-remix-root-component'
import { optionalMap } from '../../../core/shared/optional-utils'
import { setRightMenuTab } from '../../editor/actions/action-creators'
import { RightMenuTab, getCurrentTheme } from '../../editor/store/editor-state'
import { RightMenuTab } from '../../editor/store/editor-state'
import { when } from '../../../utils/react-conditionals'
import { CommentRepliesCounter } from './comment-replies-counter'

Expand Down Expand Up @@ -199,7 +199,6 @@ export const CommentIndicatorUI = React.memo<CommentIndicatorUIProps>((props) =>
position: 'fixed',
top: position.y + 3,
left: position.x - 3,
filter: resolved ? 'grayscale(1)' : undefined,
width: IndicatorSize,
height: IndicatorSize,
background: read ? colorTheme.bg1.value : colorTheme.primary.value,
Expand All @@ -208,6 +207,7 @@ export const CommentIndicatorUI = React.memo<CommentIndicatorUIProps>((props) =>
alignItems: 'center',
justifyContent: 'center',
boxShadow: UtopiaStyles.shadowStyles.mid.boxShadow,
opacity: resolved ? 0.6 : 'undefined',
}

const transform: Interpolation<Theme> = {
Expand Down Expand Up @@ -249,7 +249,7 @@ export const CommentIndicatorUI = React.memo<CommentIndicatorUIProps>((props) =>
justifyContent: 'center',
}}
>
<AvatarPicture url={avatarUrl} initials={avatarInitials} />
<AvatarPicture url={avatarUrl} initials={avatarInitials} resolved={resolved} />
</div>
</div>
)
Expand Down Expand Up @@ -363,11 +363,6 @@ const HoveredCommentIndicator = React.memo((props: HoveredCommentIndicatorProps)
const { thread, hidden, cancelHover, draggingCallback } = props

const dispatch = useDispatch()
const theme = useEditorState(
Substores.userState,
(store) => getCurrentTheme(store.userState),
'HoveredCommentIndicator theme',
)

const { location, scene: commentScene } = useCanvasLocationOfThread(thread)

Expand Down Expand Up @@ -461,7 +456,6 @@ const HoveredCommentIndicator = React.memo((props: HoveredCommentIndicatorProps)
overflow: 'auto',
background: 'transparent',
}}
data-theme={theme}
user={user}
comment={comment}
showActions={false}
Expand Down
28 changes: 2 additions & 26 deletions editor/src/components/canvas/controls/comment-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ import { create } from '../../../core/shared/property-path'
import { assertNever } from '../../../core/shared/utils'
import { CommentWrapper, MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'
import { when } from '../../../utils/react-conditionals'
import {
Button,
FlexColumn,
FlexRow,
Icn,
Tooltip,
UtopiaStyles,
colorTheme,
useColorTheme,
} from '../../../uuiui'
import { Button, FlexRow, Icn, Tooltip, UtopiaStyles, colorTheme } from '../../../uuiui'
import {
setProp_UNSAFE,
setRightMenuTab,
Expand All @@ -47,14 +38,13 @@ import {
isNewComment,
} from '../../editor/editor-modes'
import { useDispatch } from '../../editor/store/dispatch-context'
import { RightMenuTab, getCurrentTheme } from '../../editor/store/editor-state'
import { RightMenuTab } from '../../editor/store/editor-state'
import { Substores, useEditorState } from '../../editor/store/store-hook'
import { stopPropagation } from '../../inspector/common/inspector-utils'
import { canvasPointToWindowPoint } from '../dom-lookup'
import { RemixNavigationAtom } from '../remix/utopia-remix-root-component'
import { getIdOfScene } from './comment-mode/comment-mode-hooks'
import { motion, useAnimation } from 'framer-motion'
import { CSSCursor } from '../canvas-types'
import type { EditorDispatch } from '../../editor/action-types'

export const ComposerEditorClassName = 'lb-composer-editor'
Expand Down Expand Up @@ -147,12 +137,6 @@ const CommentThread = React.memo(({ comment }: CommentThreadProps) => {
}
}, [])

const theme = useEditorState(
Substores.userState,
(store) => getCurrentTheme(store.userState),
'CommentThread theme',
)

const onCreateThread = React.useCallback(
({ body }: ComposerSubmitComment, event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
Expand Down Expand Up @@ -406,7 +390,6 @@ const CommentThread = React.memo(({ comment }: CommentThreadProps) => {
</div>
<Composer
ref={composerRef}
data-theme={theme}
autoFocus
threadId={thread.id}
onComposerSubmit={onSubmitComment}
Expand All @@ -430,12 +413,6 @@ type NewCommentPopupProps = {
const NewCommentPopup = React.memo((props: NewCommentPopupProps) => {
const dispatch = useDispatch()

const theme = useEditorState(
Substores.userState,
(store) => getCurrentTheme(store.userState),
'NewCommentPopup theme',
)

const onNewCommentComposerKeyDown = React.useCallback(
(e: React.KeyboardEvent) => switchToBasicCommentModeOnEscape(e, dispatch),
[dispatch],
Expand Down Expand Up @@ -525,7 +502,6 @@ const NewCommentPopup = React.memo((props: NewCommentPopupProps) => {
</div>
<motion.div animate={newCommentComposerAnimation}>
<Composer
data-theme={theme}
autoFocus
onComposerSubmit={props.onComposerSubmit}
style={ComposerStyle}
Expand Down
3 changes: 3 additions & 0 deletions editor/src/components/editor/editor-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { isRoomId, projectIdToRoomId } from '../../core/shared/multiplayer'
import { useDisplayOwnershipWarning } from './project-owner-hooks'
import { EditorModes } from './editor-modes'
import { allowedToEditProject } from './store/collaborative-editing'
import { useDataThemeAttributeOnBody } from '../../core/commenting/comment-hooks'

const liveModeToastId = 'play-mode-toast'

Expand Down Expand Up @@ -534,6 +535,8 @@ export function EditorComponent(props: EditorProps) {

const dispatch = useDispatch()

useDataThemeAttributeOnBody()

const roomId = React.useMemo(
() => (projectId == null ? generateUUID() : projectIdToRoomId(projectId)),
[projectId],
Expand Down
3 changes: 2 additions & 1 deletion editor/src/components/user-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ interface AvatarPictureProps {
initials: string
size?: number
isOffline?: boolean
resolved?: boolean
}

export const AvatarPicture = React.memo((props: AvatarPictureProps) => {
Expand Down Expand Up @@ -370,7 +371,7 @@ export const AvatarPicture = React.memo((props: AvatarPictureProps) => {
width: size ?? '100%',
height: size ?? '100%',
borderRadius: '100%',
filter: props.isOffline ? 'grayscale(1)' : undefined,
filter: props.isOffline || props.resolved ? 'grayscale(1)' : undefined,
pointerEvents: 'none',
}}
src={url}
Expand Down
12 changes: 12 additions & 0 deletions editor/src/core/commenting/comment-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getIdOfScene } from '../../components/canvas/controls/comment-mode/comm
import type { ElementPath } from '../shared/project-file-types'
import type { ElementInstanceMetadata } from '../shared/element-template'
import * as EP from '../shared/element-path'
import { getCurrentTheme } from '../../components/editor/store/editor-state'

export function useCanvasCommentThreadAndLocation(comment: CommentId): {
location: CanvasPoint | null
Expand Down Expand Up @@ -357,3 +358,14 @@ export function useDeleteThreadReadStatus() {
}
}, [])
}

export function useDataThemeAttributeOnBody() {
const theme = useEditorState(
Substores.userState,
(store) => getCurrentTheme(store.userState),
'useDataThemeAttributeOnBody theme',
)
React.useEffect(() => {
document.body.setAttribute('data-theme', theme)
}, [theme])
}
12 changes: 2 additions & 10 deletions editor/src/utils/multiplayer-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
normalizeMultiplayerName,
} from '../core/shared/multiplayer'
import { ErrorBoundary } from './react-error-boundary'
import { Substores, useEditorState } from '../components/editor/store/store-hook'
import { getCurrentTheme } from '../components/editor/store/editor-state'

type Fallback = NonNullable<React.ReactNode> | null

Expand All @@ -30,14 +28,8 @@ MultiplayerWrapper.displayName = 'MultiplayerWrapper'

export const CommentWrapper = React.memo(
({ user, ...commentProps }: { user: UserMeta | null } & CommentProps) => {
const theme = useEditorState(
Substores.userState,
(store) => getCurrentTheme(store.userState),
'CommentWrapper theme',
)

if (user == null) {
return <Comment data-theme={theme} {...commentProps} />
return <Comment {...commentProps} />
}
return (
<div style={{ position: 'relative' }}>
Expand All @@ -54,7 +46,7 @@ export const CommentWrapper = React.memo(
}}
picture={user.avatar}
/>
<Comment data-theme={theme} {...commentProps} />
<Comment {...commentProps} />
</div>
)
},
Expand Down

0 comments on commit e69a797

Please sign in to comment.