()
| 429 | } |
| 430 | |
| 431 | export function useRecentProjects() { |
| 432 | const currentUser = useOptionalCurrentUser(); |
| 433 | const isSaaS = useIsSaaSMode(); |
| 434 | const batchFetchProjects = useAppStore((state) => state.batchFetchProjects); |
| 435 | const projectsByName = useAppStore((state) => state.projectsByName); |
| 436 | const [projectNames, setProjectNames] = useState<string[]>([]); |
| 437 | |
| 438 | const scope = workspaceCacheScope(isSaaS, currentUser?.workspace ?? ""); |
| 439 | const refreshNames = useCallback(() => { |
| 440 | setProjectNames(readRecentProjectNames(scope, currentUser?.email ?? "")); |
| 441 | }, [scope, currentUser?.email]); |
| 442 | |
| 443 | useEffect(() => { |
| 444 | refreshNames(); |
| 445 | }, [refreshNames]); |
| 446 | |
| 447 | useEffect(() => { |
| 448 | if (projectNames.length > 0) { |
| 449 | void batchFetchProjects(projectNames); |
| 450 | } |
| 451 | }, [batchFetchProjects, projectNames]); |
| 452 | |
| 453 | const projects = useMemo(() => { |
| 454 | return projectNames |
| 455 | .map((name) => projectsByName[name]) |
| 456 | .filter((project): project is Project => Boolean(project)) |
| 457 | .filter((project) => !isDefaultProjectName(project.name)); |
| 458 | }, [projectNames, projectsByName]); |
| 459 | |
| 460 | return { projects, refresh: refreshNames }; |
| 461 | } |
| 462 | |
| 463 | export function useRecentVisit() { |
| 464 | useOptionalCurrentUser(); |
no test coverage detected