Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ and this project adheres to
- ♿️(frontend) show the focus ring on connection test detail cards
- ♿️(frontend) use a heading for every connection test card title
- ♿️(frontend) put the ProConnect link label inside the link
- ⚡️(frontend) animate floating reactions without rendering each frame
- 🐛(frontend) subscribe useRoomData to the query cache

## [1.37.0] - 2026-11-01

Expand Down
47 changes: 21 additions & 26 deletions src/frontend/src/features/reactions/components/ReactionPortals.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createPortal } from 'react-dom'
import { useState, useEffect } from 'react'
import { useState, useEffect, useRef } from 'react'
import { Text } from '@/primitives'
import { css } from '@/styled-system/css'
import { useSnapshot } from 'valtio'
Expand Down Expand Up @@ -29,39 +29,35 @@ export function FloatingReaction({
speed = 1,
scale = 1,
}: FloatingReactionProps) {
const [deltaY, setDeltaY] = useState(0)
const [opacity, setOpacity] = useState(1)
const elementRef = useRef<HTMLDivElement>(null)

const [left] = useState(
() => Math.random() * window.innerWidth * REACTION_SPAWN_WIDTH_RATIO
)

useEffect(() => {
let start: number | null = null
function animate(timestamp: number) {
if (start === null) start = timestamp
const elapsed = timestamp - start
if (elapsed < 0) {
setOpacity(0)
} else {
const progress = Math.min(elapsed / ANIMATION_DURATION, 1)
const distance = ANIMATION_DISTANCE * speed
const newY = progress * distance
setDeltaY(newY)
if (progress > FADE_OUT_THRESHOLD) {
setOpacity(1 - (progress - FADE_OUT_THRESHOLD) / 0.3)
}
}
if (elapsed < ANIMATION_DURATION) {
requestAnimationFrame(animate)
}
}
const req = requestAnimationFrame(animate)
return () => cancelAnimationFrame(req)
const element = elementRef.current
if (!element) return

const distance = ANIMATION_DISTANCE * speed
const animation = element.animate(
[
{ transform: 'translateY(0)', opacity: 1 },
{
transform: `translateY(${-distance * FADE_OUT_THRESHOLD}px)`,
opacity: 1,
offset: FADE_OUT_THRESHOLD,
},
{ transform: `translateY(${-distance}px)`, opacity: 0 },
],
{ duration: ANIMATION_DURATION, easing: 'linear', fill: 'forwards' }
)
return () => animation.cancel()
}, [speed])

return (
<div
ref={elementRef}
className={css({
position: 'absolute',
display: 'flex',
Expand All @@ -70,8 +66,7 @@ export function FloatingReaction({
})}
style={{
left: left,
bottom: INITIAL_POSITION + deltaY,
opacity: opacity,
bottom: INITIAL_POSITION,
}}
>
<img
Expand Down
21 changes: 19 additions & 2 deletions src/frontend/src/features/rooms/livekit/hooks/useRoomData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { useCallback, useSyncExternalStore } from 'react'
import { hashKey } from '@tanstack/react-query'
import type { ApiRoom } from '@/features/rooms/api/ApiRoom'
import { useParams } from 'wouter'
import { keys } from '@/api/queryKeys'
import { queryClient } from '@/api/queryClient'

export const useRoomData = (): ApiRoom | undefined => {
const { roomId } = useParams()
const queryKey = [keys.room, roomId]
return queryClient.getQueryData<ApiRoom>(queryKey)

const subscribe = useCallback(
(onStoreChange: () => void) => {
const queryHash = hashKey([keys.room, roomId])
return queryClient.getQueryCache().subscribe((event) => {
if (event.query.queryHash === queryHash) onStoreChange()
})
},
[roomId]
)

const getSnapshot = useCallback(
() => queryClient.getQueryData<ApiRoom>([keys.room, roomId]),
[roomId]
)

return useSyncExternalStore(subscribe, getSnapshot)
}
Loading