mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 14:17:42 +00:00
* feat(webui): add mobile friendly file detail and public share view * fix(webui): address review feedback for mobile file detail and public share view * fix(webui): use dynamic viewport and flex column layout for mobile file viewer * fix(webui): support iOS WebKit video fullscreen and guard requestFullscreen * fix(webui): compact page indicator and layout in mobile PDF control bar
210 lines
6.7 KiB
TypeScript
210 lines
6.7 KiB
TypeScript
import { client } from '@/ui/api/client'
|
|
import { DualSidebar, DualSidebarItem } from '@/ui/components/dual-sidebar'
|
|
import { FolderTree } from '@/ui/components/folder-tree'
|
|
import { NotificationList } from '@/ui/components/notification-list'
|
|
import { TopNav } from '@/ui/components/top-nav'
|
|
import {
|
|
DashboardFillIcon,
|
|
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 { useTopNavStore } from '@/ui/stores/top-nav'
|
|
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 { projectState } = useTopNavStore()
|
|
|
|
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
|
|
|
|
const isKanbanActive = pathname.includes('/kanban')
|
|
const isDashboardActive = pathname.includes('/dashboard')
|
|
|
|
return (
|
|
<div className="flex h-[100dvh] w-full bg-background overflow-hidden">
|
|
<Toaster />
|
|
<DualSidebar
|
|
hideMobileButton={true}
|
|
defaultMobileContent={
|
|
projectState?.projectId
|
|
? {
|
|
label: m.folder_tree_assets(),
|
|
children: (
|
|
<FolderTree
|
|
teamId={projectState.teamId}
|
|
projectId={projectState.projectId}
|
|
projectName={projectState.projectName}
|
|
rootFolderId={projectState.rootFolderId || ''}
|
|
ancestorFolders={projectState.ancestorFolders}
|
|
/>
|
|
),
|
|
}
|
|
: undefined
|
|
}
|
|
>
|
|
<DualSidebarItem
|
|
icon={<HomeIcon />}
|
|
label={m.home()}
|
|
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()}
|
|
active={isKanbanActive}
|
|
onItemClick={() => {
|
|
if (storedTeamId) {
|
|
navigate({
|
|
to: '/teams/$teamId/kanban',
|
|
params: { teamId: storedTeamId },
|
|
})
|
|
}
|
|
}}
|
|
/>
|
|
{me?.role?.toLowerCase() === 'owner' && (
|
|
<DualSidebarItem
|
|
icon={<DashboardFillIcon />}
|
|
label={m.dashboard()}
|
|
active={isDashboardActive}
|
|
onItemClick={() => {
|
|
if (storedTeamId) {
|
|
navigate({
|
|
to: '/teams/$teamId/dashboard',
|
|
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,
|
|
})
|