fix(ui): improve project card interactions and layout consistency

This PR addresses two main issues on the projects page:
1. Double-click bleed-through: Accidental double-clicks on project cards would previously trigger unintended interactions on the following file list page. A 200ms navigation delay and click debouncing now prevent this.
2. Layout inconsistency: The 'Create Project' card now matches the height and structure of existing project cards, ensuring a stable grid layout even when no projects are present.
3. Tactile feedback: Added a 'shrink-and-restore' scale animation to all project cards for better visual confirmation of clicks.
This commit is contained in:
yiling
2026-05-23 14:12:12 +08:00
parent 94ad695728
commit 034f2ef5ff
+58 -19
View File
@@ -17,7 +17,6 @@ import {
} from '@/ui/components/ui/alert-dialog' } from '@/ui/components/ui/alert-dialog'
import { Avatar, AvatarFallback } from '@/ui/components/ui/avatar' import { Avatar, AvatarFallback } from '@/ui/components/ui/avatar'
import { Button } from '@/ui/components/ui/button' import { Button } from '@/ui/components/ui/button'
import { Card } from '@/ui/components/ui/card'
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
@@ -26,6 +25,7 @@ import {
} from '@/ui/components/ui/dropdown-menu' } from '@/ui/components/ui/dropdown-menu'
import { ShumaiLogo } from '@/ui/components/ui/icons' import { ShumaiLogo } from '@/ui/components/ui/icons'
import { formatDateAgo } from '@/ui/lib/time' import { formatDateAgo } from '@/ui/lib/time'
import { cn } from '@/ui/lib/utils'
import { useQuery, useSuspenseQuery } from '@tanstack/react-query' import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
import { createFileRoute, useNavigate } from '@tanstack/react-router' import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { MoreHorizontal, PlusIcon } from 'lucide-react' import { MoreHorizontal, PlusIcon } from 'lucide-react'
@@ -35,6 +35,9 @@ function TeamPage() {
const { teamId } = Route.useParams() const { teamId } = Route.useParams()
const navigate = useNavigate() const navigate = useNavigate()
// State for clicked project for animation
const [clickedProjectId, setClickedProjectId] = useState<string | null>(null)
// State for Project Dialog // State for Project Dialog
const [isProjectDialogOpen, setIsProjectDialogOpen] = useState(false) const [isProjectDialogOpen, setIsProjectDialogOpen] = useState(false)
const [projectDialogMode, setProjectDialogMode] = useState<'create' | 'edit'>('create') const [projectDialogMode, setProjectDialogMode] = useState<'create' | 'edit'>('create')
@@ -108,6 +111,17 @@ function TeamPage() {
setIsProjectDialogOpen(true) setIsProjectDialogOpen(true)
} }
const handleCreateCardClick = () => {
setClickedProjectId('create')
setTimeout(() => {
setClickedProjectId(null)
}, 100)
setTimeout(() => {
handleCreateProjectClick()
}, 200)
}
const handleEditProjectClick = (project: ProjectInfo) => { const handleEditProjectClick = (project: ProjectInfo) => {
setProjectDialogMode('edit') setProjectDialogMode('edit')
setSelectedProject(project) setSelectedProject(project)
@@ -126,11 +140,23 @@ function TeamPage() {
setIsDeleteDialogOpen(false) setIsDeleteDialogOpen(false)
} }
const handleCardClick = (projectId: string) => { const handleCardClick = (projectId: string, e: React.MouseEvent) => {
navigate({ if (e.detail > 1) return
to: '/projects/$projectId',
params: { projectId }, setClickedProjectId(projectId)
})
// Restore scale after 100ms for "shrink and restore" effect
setTimeout(() => {
setClickedProjectId(null)
}, 100)
// Navigate after 200ms
setTimeout(() => {
navigate({
to: '/projects/$projectId',
params: { projectId },
})
}, 200)
} }
const handleInvite = async (role: 'editor' | 'reviewer') => { const handleInvite = async (role: 'editor' | 'reviewer') => {
@@ -200,11 +226,15 @@ function TeamPage() {
</div> </div>
<div className="grid grid-cols-1 sm:grid-cols-3 md:grid-cols-5 lg:grid-cols-7 gap-4"> <div className="grid grid-cols-1 sm:grid-cols-3 md:grid-cols-5 lg:grid-cols-7 gap-4">
{projects.data?.map((project: ProjectInfo) => ( {projects.data?.map((project: ProjectInfo) => (
<div key={project.id} className="shadow-md relative border rounded-xl overflow-hidden"> <div
<div key={project.id}
className="cursor-pointer flex flex-col" className={cn(
onClick={() => handleCardClick(project.id!)} 'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out',
> clickedProjectId === project.id ? 'scale-95' : 'scale-100',
)}
onClick={(e) => handleCardClick(project.id!, e)}
>
<div className="flex flex-col">
<div className="relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20"> <div className="relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20">
{project.coverImage ? ( {project.coverImage ? (
<img <img
@@ -224,7 +254,7 @@ function TeamPage() {
<p className="truncate pr-1 text-xs text-muted-foreground"> <p className="truncate pr-1 text-xs text-muted-foreground">
Updated {formatDateAgo((project.updatedAt as string) ?? '')} Updated {formatDateAgo((project.updatedAt as string) ?? '')}
</p> </p>
<div> <div onClick={(e) => e.stopPropagation()}>
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<button className="hover:bg-muted outline-none flex px-1"> <button className="hover:bg-muted outline-none flex px-1">
@@ -253,15 +283,24 @@ function TeamPage() {
</div> </div>
</div> </div>
))} ))}
<Card <div
className="flex items-center justify-center hover:shadow-lg transition-shadow cursor-pointer" className={cn(
onClick={handleCreateProjectClick} 'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group',
clickedProjectId === 'create' ? 'scale-95' : 'scale-100',
)}
onClick={handleCreateCardClick}
> >
<div className="text-center"> <div className="flex flex-col">
<PlusIcon className="w-8 h-8 mx-auto text-muted-foreground" /> <div className="relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors">
<p className="mt-2 text-sm text-muted-foreground">Create Project</p> <PlusIcon className="w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors" />
</div>
<div className="px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors">
<p className="text-sm text-muted-foreground group-hover:text-orange-600 transition-colors">
Create Project
</p>
</div>
</div> </div>
</Card> </div>
</div> </div>
<ProjectDialog <ProjectDialog