Files
shumai/packages/webui/components/notification-card.tsx
T
Yiling-J 43a2eced75 feat(transcode): add 3D asset support and turntable viewer (#454)
* feat(transcode): add 3D asset support and turntable viewer

* perf(turntable): stream file via Bun.file and increase upload timeout

* feat(turntable): increase upload timeout to 15m to support 5GB uploads

* fix(webui): align 3D model viewer layout and full-width control bar with video viewer

* feat(webui): unify 3D viewer bottom bar and redesign cyclic ruler slider

- Place RulerSlider in single row with playback and zoom controls, centered with max 320px width
- Flank RulerSlider with minus and plus buttons to step angle by 15°
- Redesign RulerSlider with fixed center indicator and moving cyclic track with continuous 360° wrapping
- Render major ticks longer at 60° intervals without numeric text labels on track
- Display floating degree tooltip above center indicator only during dragging

* fix(webui): prevent RulerSlider from collapsing to 0px width in control bar

- Use flex layout with flex-1 on left and right clusters to preserve center cluster width
- Enforce min-w-[140px] and w-full on RulerSlider
- Fix tooltip positioning and remove outer overflow-hidden

* feat(webui): snap RulerSlider track directly to discrete 15° ticks during drag

* fix(webui): prevent ruler snap-back caused by floating point second truncation

- Use Math.round instead of Math.floor in secondToDegree to avoid 0.999996 dropping to previous frame
- Ensure final dragDegree is committed on pointer up

* fix(webui): fix arrow key frame rounding and duplicate event bubbling

- Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer
- Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener

* feat(webui): redesign RulerSlider with encapsulated step buttons and capsule pill track

* feat(webui): make RulerSlider responsive on mobile and remove bottom bar reset button

* fix(webui): load 3d video directly without poster and invert drag rotation to counterclockwise

* fix(webui): fix 3d asset viewer frame seeking and drag jitter

* feat(transcode): show 3D asset poster preview immediately after render start

* fix(viewer): synchronize 3D turntable playback via frame callback to prevent skipped degrees

* fix(viewer): handle touchpad zoom gestures and prevent page zoom in 3D viewer

* fix(viewer): eliminate 3D model rotation jitter at 345 degrees

* fix(share): watermark 3D asset turntable video on share links

* fix(share): preserve video transcode resolution on watermarked share links

* fix(viewer): download original 3D model file instead of rendered turntable MP4
2026-10-11 21:32:28 +08:00

192 lines
6.6 KiB
TypeScript

import type { NotificationInfo } from '@shumai/dtos'
import { formatTimeAgo } from '@/ui/lib/time'
import { cn } from '@/ui/lib/utils'
import { SpriteScrubber } from './sprite-scrubber'
import { m } from '@/ui/paraglide/messages.js'
import React from 'react'
import { useNavigate } from '@tanstack/react-router'
interface NotificationCardProps {
notification: NotificationInfo
}
const renderNotification = (
messageTemplate: string,
placeholders: Record<string, React.ReactNode>,
) => {
const regex = new RegExp(
`(${Object.keys(placeholders)
.map((k) => `\\{${k}\\}`)
.join('|')})`,
'g',
)
return (
<span>
{messageTemplate.split(regex).map((part, index) => {
const match = part.match(/^\{(.+)\}$/)
if (match && placeholders[match[1]]) {
return <React.Fragment key={index}>{placeholders[match[1]]}</React.Fragment>
}
return part
})}
</span>
)
}
export const NotificationCard = ({ notification }: NotificationCardProps) => {
const navigate = useNavigate()
const { creator, createdAt, isRead, type, asset, project, team, user, kanbanTask } = notification
const message = (() => {
const creatorName = creator?.name || m.unknown_user()
const assetName = asset?.name || m.unknown_asset()
const taskTitle = kanbanTask?.title || m.unknown_task()
const projectName = project?.name || m.unknown_project()
const teamName = team?.name || m.unknown_team()
const targetUserName = user?.name || m.unknown_user()
const placeholders = {
creator: <span className="font-semibold">{creatorName}</span>,
asset: <span className="font-semibold">{assetName}</span>,
task: <span className="font-semibold">{taskTitle}</span>,
project: <span className="font-semibold">{projectName}</span>,
team: <span className="font-semibold">{teamName}</span>,
user: <span className="font-semibold">{targetUserName}</span>,
}
switch (type) {
case 'comment_created':
return renderNotification(
m.notification_commented_on({ creator: '{creator}', asset: '{asset}' }),
placeholders,
)
case 'reply_created':
return renderNotification(
m.notification_replied_to({ creator: '{creator}', asset: '{asset}' }),
placeholders,
)
case 'mention':
return renderNotification(
kanbanTask
? m.notification_mentioned_you_in_task({ creator: '{creator}', task: '{task}' })
: m.notification_mentioned_you({ creator: '{creator}', asset: '{asset}' }),
placeholders,
)
case 'successful_file_uploaded':
return renderNotification(
m.notification_uploaded({ creator: '{creator}', asset: '{asset}', project: '{project}' }),
placeholders,
)
case 'metadata_field_updated_status':
return renderNotification(
m.notification_status_updated({ creator: '{creator}', asset: '{asset}' }),
placeholders,
)
case 'new_user_join_team':
return renderNotification(
m.notification_joined_team({ user: '{user}', team: '{team}' }),
placeholders,
)
case 'new_user_join_project':
return renderNotification(
m.notification_joined_project({ user: '{user}', project: '{project}' }),
placeholders,
)
case 'kanban_task_created':
return renderNotification(
m.notification_kanban_task_created({ creator: '{creator}', task: '{task}' }),
placeholders,
)
case 'kanban_task_assigned':
return renderNotification(
m.notification_kanban_task_assigned({ creator: '{creator}', task: '{task}' }),
placeholders,
)
case 'kanban_task_status_updated':
return renderNotification(
m.notification_kanban_task_status_updated({ creator: '{creator}', task: '{task}' }),
placeholders,
)
case 'kanban_task_updated':
return renderNotification(
m.notification_kanban_task_updated({ creator: '{creator}', task: '{task}' }),
placeholders,
)
case 'kanban_task_deleted':
return renderNotification(
m.notification_kanban_task_deleted({ creator: '{creator}', task: '{task}' }),
placeholders,
)
case 'kanban_task_comment_created':
return renderNotification(
m.notification_kanban_task_comment_created({ creator: '{creator}', task: '{task}' }),
placeholders,
)
default:
return renderNotification(m.notification_generic({ creator: '{creator}' }), placeholders)
}
})()
const isVideoWithSprite =
asset?.proxyType === 'video' &&
asset.preview &&
asset.thumbnailUrl &&
asset.originalWidth &&
asset.originalHeight
const hasPreview = asset?.preview && (asset.proxyType === 'image' || asset.proxyType === 'video')
const handleClick = () => {
if (kanbanTask?.id && team?.id) {
navigate({
to: '/teams/$teamId/kanban',
params: { teamId: team.id },
search: { taskId: kanbanTask.id },
})
} else if (project?.id && asset?.id) {
//TODO: Perhaps it should be marked as read too when redirecting to it.
navigate({
to: '/projects/$projectId/files/$fileId',
params: { projectId: project.id, fileId: asset.id },
})
}
}
return (
<div
onClick={handleClick}
className="flex py-2 cursor-pointer group border border-transparent items-center justify-center hover:bg-muted/50 rounded-md px-1 transition-colors"
>
{/* Unread Indicator */}
<div
className={cn(
'w-1.5 h-1.5 rounded-full shadow-xs',
isRead ? 'bg-transparent' : 'bg-destructive',
)}
/>
<div className="flex-1 min-w-0 flex flex-col justify-center pl-2">
<div className="text-sm text-foreground break-all leading-snug">{message}</div>
<div className="text-[11px] text-muted-foreground mt-1">
{formatTimeAgo(createdAt || '')}
</div>
</div>
{hasPreview && (
<div className="w-18 h-18 ml-2 rounded-md overflow-hidden flex-shrink-0 bg-muted border border-border flex items-center justify-center mt-0.5">
{isVideoWithSprite ? (
<SpriteScrubber
spriteUrl={asset.preview!}
thumbnailUrl={asset.thumbnailUrl!}
videoWidth={asset.originalWidth!}
videoHeight={asset.originalHeight!}
/>
) : (
<img src={asset!.preview} alt={asset!.name} className="w-full h-full object-cover" />
)}
</div>
)}
</div>
)
}