mirror of
https://github.com/suitenumerique/meet.git
synced 2026-11-17 05:12:40 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56c92a270f | |||
| 9ee68d9ddf |
@@ -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
|
||||
|
||||
|
||||
@@ -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'
|
||||
@@ -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',
|
||||
@@ -70,8 +66,7 @@ export function FloatingReaction({
|
||||
})}
|
||||
style={{
|
||||
left: left,
|
||||
bottom: INITIAL_POSITION + deltaY,
|
||||
opacity: opacity,
|
||||
bottom: INITIAL_POSITION,
|
||||
}}
|
||||
>
|
||||
<img
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
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'
|
||||
@@ -5,6 +7,21 @@ 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user