refactor(monorepo): decouple api and webui into workspaces packages

This commit is contained in:
yiling
2026-06-01 23:35:00 +08:00
parent e3f4fa219e
commit 1f341c15d0
288 changed files with 18024 additions and 21178 deletions
+19
View File
@@ -0,0 +1,19 @@
import * as React from 'react'
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
}
mql.addEventListener('change', onChange)
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
return () => mql.removeEventListener('change', onChange)
}, [])
return !!isMobile
}
+50
View File
@@ -0,0 +1,50 @@
import { client } from '@/ui/api/client'
import { useQuery } from '@tanstack/react-query'
import { useRouterState } from '@tanstack/react-router'
import { useEffect, useState } from 'react'
function getIdsFromPathname(pathname: string): {
teamId?: string
projectId?: string
} {
const teamMatch = pathname.match(/teams\/([^/]+)/)
if (teamMatch) {
return { teamId: teamMatch[1] }
}
const projectMatch = pathname.match(/projects\/([^/]+)/)
if (projectMatch) {
return { projectId: projectMatch[1] }
}
return {}
}
export function useTeamId() {
const [teamId, setTeamId] = useState<string | undefined>()
const pathname = useRouterState({ select: (s) => s.location.pathname })
const { teamId: paramsTeamId, projectId: paramsProjectId } = getIdsFromPathname(pathname)
const { data: projectTeam } = useQuery({
queryKey: ['projects', paramsProjectId, 'team'],
queryFn: async () => {
const res = await client.api.projects[':projectId'].team.$get({
param: { projectId: paramsProjectId! },
})
if (!res.ok) throw new Error('failed to fetch project team')
return await res.json()
},
enabled: !!paramsProjectId,
})
useEffect(() => {
if (paramsTeamId) {
setTeamId(paramsTeamId)
} else if (projectTeam?.teamId) {
setTeamId(projectTeam.teamId)
}
}, [paramsTeamId, projectTeam])
return teamId
}
+27
View File
@@ -0,0 +1,27 @@
import { useLayoutEffect, useState } from 'react'
type ScreenSize = {
width: number
height: number
}
export function useScreenSize(): ScreenSize {
const [size, setSize] = useState<ScreenSize>({
width: window.innerWidth,
height: window.innerHeight,
})
useLayoutEffect(() => {
function handleResize() {
setSize({
width: window.innerWidth,
height: window.innerHeight,
})
}
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}, [])
return size
}