45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import React, { useEffect, useState } from 'react'
|
|
import { Link, useLocation } from 'react-router-dom'
|
|
import clsx from 'clsx'
|
|
import { getProjects, subscribeProjectsStore } from '@/pages/projects/projectData'
|
|
|
|
export const RecentProjects: React.FC<{ isProjectWorkspace?: boolean }> = ({ isProjectWorkspace = false }) => {
|
|
const location = useLocation()
|
|
const [recentProjects, setRecentProjects] = useState(() => getProjects().slice(0, 3))
|
|
|
|
useEffect(() => subscribeProjectsStore(() => setRecentProjects(getProjects().slice(0, 3))), [])
|
|
|
|
return (
|
|
<div>
|
|
<div className={`px-2 mb-2 text-[9px] font-semibold text-slate-500 ${isProjectWorkspace ? 'tracking-normal text-[#332926]' : 'uppercase tracking-wider'}`}>
|
|
DỰ ÁN GẦN ĐÂY
|
|
</div>
|
|
<div className="space-y-0.5">
|
|
{recentProjects.map((project) => {
|
|
const projectPath = `/projects/${project.id}`
|
|
const isCurrent = location.pathname.startsWith(projectPath)
|
|
return (
|
|
<Link
|
|
key={project.id}
|
|
to={projectPath}
|
|
className={clsx(
|
|
'flex items-center transition-colors',
|
|
isProjectWorkspace
|
|
? 'gap-2 px-2.5 py-0.5 text-[11px] font-normal leading-[17px] text-[var(--project-heading)]'
|
|
: 'gap-2.5 rounded-lg px-2.5 py-2 text-xs font-medium',
|
|
isProjectWorkspace
|
|
? 'text-[var(--project-heading)]'
|
|
: isCurrent
|
|
? 'bg-slate-100 text-slate-900 font-semibold'
|
|
: 'text-slate-600 hover:bg-slate-50 hover:text-slate-900'
|
|
)}
|
|
>
|
|
<span className={`h-[5px] w-[5px] shrink-0 rounded-full ${isProjectWorkspace ? 'bg-[var(--project-accent-dot)]' : 'bg-indigo-500'}`} />
|
|
<span className="truncate">{project.name}</span>
|
|
</Link>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|