Files
shumai/packages/webui/routes/__root.tsx
T
Yiling-J 1f2bdc8c9e feat(agentic kanban): phase 1 not-agentic kanban board (#330)
* feat(kanban): implement AI-native kanban database models, services, and REST APIs

* feat(webui): implement team kanban board and task management

* style(webui): increase kanban dialog widths and form container

* fix(webui): ensure kanban dialogs override sm:max-w-lg base class

* style(webui): set edit task dialog max width to 5xl

* chore: untrack kanban plan markdown files

* feat(webui): update kanban page layout to 2 columns and refine task activity UI

* fix(webui): constrain kanban column and board heights for vertical scrolling

* feat(kanban): unify task status transition into updateTask API and allow unconstrained human task transitions

* fix(webui): add optimistic updates to kanban drag-and-drop to eliminate flash

* refactor(webui): remove client-side search box from kanban header

* feat(kanban): redesign task dialog comments area and add attachment support

* refactor(webui): remove top status action bar from task info dialog

* fix(webui): narrow query cache predicate and add defensive guards for kanban drag optimistic update

* feat(kanban): add drag-and-drop task reordering with fractional indexing (#331)

* feat(kanban): add drag-and-drop task reordering with fractional indexing

* fix(kanban): improve card drop zones, snap indicators, and column highlight

* fix(kanban): enable card droppables only during active drag

* fix(kanban): refine hover styles and drop indicators for column boundaries

* fix(kanban): unify bottom drop indicator and fix top indicator clipping

* fix(kanban): ensure full column highlight and full coverage drop target

* minor change

* feat(kanban): allow agent tasks free drag-and-drop and enforce status change permissions (#332)

* refactor(kanban): rename task_type_agentic translation keys to task_type_agent

* feat(kanban): refactor task type enum to isAgentTask boolean (#333)

* refactor(kanban): remove phase 2 agent execution logic and streamline phase 1 kanban

* feat(kanban): add notifications and audit logging for kanban (#334)

* feat(kanban): redesign config area layout and add parent tasks multi-selector (#335)

* feat(webui): redesign kanban task dialog config area

* feat(kanban): simplify task dependencies with parent tasks multi-selector

* refactor(kanban): remove unused links routes and legacy dependency methods

* feat(kanban): connect assets and kanban tasks with many-to-many relationship (#336)

* feat(kanban): connect assets and kanban tasks with many-to-many relationship

* feat(kanban): improve asset picker layout, infinite scrolling, and breadcrumb icon styling

* fix(kanban): ensure asset picker scrollarea is scrollable with min-h-0 and shrink-0 flex styling

* fix(kanban): hide recently deleted in folder tree picker and adjust header padding

* fix(kanban): use lucide files icon instead of paperclip for linked assets

* feat(kanban): improve task deletion, goal sidebar interaction, and card styling (#337)

* feat(kanban): improve task deletion, goal sidebar interaction, and card styling

* feat(kanban): move agent task badge after priority and update to orange style

* feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions (#338)

* feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions

* style(kanban): rotate kanban icon 180 degrees in sidebar and top nav

* style(kanban): remove rotate-180 from SquareKanban icons

* feat(kanban): add unassigned goal record and fix all tasks count (#339)

* feat(kanban): add unassigned goal record and fix all tasks count

* feat(kanban): toggle task count with three-dot action button on goal card hover

* fix(ci): pin bun version to 1.3.14 across CI and Docker (#340)

* fix(webui): truncate goal name to max 2 lines in kanban sidebar (#341)
2026-08-23 10:28:56 +08:00

169 lines
5.3 KiB
TypeScript

import { client } from '@/ui/api/client'
import { DualSidebar, DualSidebarItem } from '@/ui/components/dual-sidebar'
import { NotificationList } from '@/ui/components/notification-list'
import { TopNav } from '@/ui/components/top-nav'
import {
HomeIcon,
KanbanFillIcon,
NotificationFillIcon,
UploadCloudIcon,
} from '@/ui/components/ui/icons'
import { Toaster } from '@/ui/components/ui/sonner'
import { UploadTasks } from '@/ui/components/upload-tasks'
import { m } from '@/ui/paraglide/messages.js'
import { getLocale, setLocale } from '@/ui/paraglide/runtime.js'
import { useAuthStore } from '@/ui/stores/auth'
import { useTeamContextStore } from '@/ui/stores/team-context'
import { useUploadStore } from '@/ui/stores/upload'
import { useUserMetadataStore } from '@/ui/stores/user-metadata'
import { useQuery } from '@tanstack/react-query'
import {
createRootRouteWithContext,
Outlet,
useNavigate,
useRouterState,
} from '@tanstack/react-router'
import { useEffect } from 'react'
async function resolveTeamIdFromPath(pathname: string): Promise<string | null> {
const teamIdMatch = pathname.match(/^\/teams\/([^/]+)/)
const teamId = teamIdMatch ? teamIdMatch[1] : null
if (teamId) return teamId
const projectIdMatch = pathname.match(/^\/projects\/([^/]+)/)
const projectId = projectIdMatch ? projectIdMatch[1] : null
if (projectId) {
const { ensureTeamIdForProject } = useTeamContextStore.getState()
return await ensureTeamIdForProject(projectId)
}
return null
}
function RootComponent() {
const user = useAuthStore((state) => state.user)
const { uploading } = useUploadStore()
const pathname = useRouterState({ select: (s) => s.location.pathname })
const navigate = useNavigate()
const { teamId: storedTeamId, setTeamId } = useTeamContextStore()
const showSidebar = user && (pathname.startsWith('/teams/') || pathname.startsWith('/projects/'))
useEffect(() => {
resolveTeamIdFromPath(pathname).then((resolvedTeamId) => {
if (resolvedTeamId && resolvedTeamId !== storedTeamId) {
setTeamId(resolvedTeamId)
}
})
}, [pathname, storedTeamId, setTeamId])
const { data: me } = useQuery({
queryKey: ['teams', storedTeamId, 'me'],
queryFn: async () => {
if (!storedTeamId) return null
const res = await client.api.teams[':teamId'].me.$get({
param: { teamId: storedTeamId },
})
if (!res.ok) throw new Error('Failed to fetch me')
return await res.json()
},
enabled: !!storedTeamId,
})
if (!showSidebar) {
return <Outlet />
}
const unreadCount = me?.unreadNotificationCount ?? 0
const displayCount = unreadCount > 99 ? '99+' : unreadCount
const badge =
unreadCount > 0 ? (
<span className="absolute justify-center top-0 -right-1 mt-1 inline-flex items-center px-1.5 py-0.5 rounded-full text-xs leading-4 bg-red-400 dark:bg-red-500 text-white pointer-events-none h-5 min-w-5">
{displayCount}
</span>
) : null
return (
<div className="flex h-screen w-full bg-background overflow-hidden">
<Toaster />
<DualSidebar>
<DualSidebarItem
icon={<HomeIcon />}
label={m.dashboard()}
onItemClick={() => {
if (storedTeamId) {
navigate({
to: '/teams/$teamId',
params: { teamId: storedTeamId },
})
}
}}
/>
<DualSidebarItem icon={<NotificationFillIcon />} label={m.notifications()} badge={badge}>
<NotificationList />
</DualSidebarItem>
<DualSidebarItem
icon={
<UploadCloudIcon
uploading={uploading > 0}
className={uploading > 0 ? 'text-blue-500' : ''}
/>
}
label={m.uploads()}
>
<UploadTasks />
</DualSidebarItem>
<DualSidebarItem
icon={<KanbanFillIcon />}
label={m.kanban()}
onItemClick={() => {
if (storedTeamId) {
navigate({
to: '/teams/$teamId/kanban',
params: { teamId: storedTeamId },
})
}
}}
/>
</DualSidebar>
<div className="flex flex-col flex-1 md:pl-16 overflow-hidden relative">
<TopNav />
<main className="flex-1 overflow-hidden relative flex flex-col">
<Outlet />
</main>
</div>
</div>
)
}
import { QueryClient } from '@tanstack/react-query'
interface MyRouterContext {
queryClient: QueryClient
}
export const Route = createRootRouteWithContext<MyRouterContext>()({
beforeLoad: async ({ location }) => {
if (typeof window !== 'undefined') {
const pathname = location.pathname
const teamId = await resolveTeamIdFromPath(pathname)
if (teamId) {
const { fetchMetadata, getMetadata } = useUserMetadataStore.getState()
try {
await fetchMetadata(teamId)
const savedLocale = getMetadata<string>('locale')
if ((savedLocale === 'en' || savedLocale === 'zh') && savedLocale !== getLocale()) {
setLocale(savedLocale, { reload: false })
}
} catch (e) {
console.error('Failed to load user locale metadata:', e)
}
}
document.documentElement.setAttribute('lang', getLocale())
}
},
component: RootComponent,
})