mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(sessions): address PR #403 review findings
- fetch picker sessions only while the dialog is open - list all-projects sessions with one request per page - block infinite-scroll paging while a search is pending - memoize picker rows with stable callbacks - remove deleted sessions from list caches instead of refetching - keep the repo tab when the open session is deleted - reuse useSessionSearch in the sidebar session tree - drop dead activeSessionID/isActive and share delete, session-key and repo-map helpers - move usePersistentBoolean to its own hook
This commit is contained in:
1 parent
85288d6393
commit
2d14972fad
24 files changed
+814
-412
No files matched your search
@@ -4,15 +4,15 @@ import { useSessionSearch } from './useSessionSearch'
|
||||
|
||||
const { sessionsData, lastArgsRef, flagsRef } = vi.hoisted(() => ({
|
||||
sessionsData: [] as Array<{ id: string; title: string; location: { directory: string }; parentID?: string; time: { updated: number } }>,
|
||||
lastArgsRef: { current: undefined as { directories: string[]; options?: { search?: string; limit?: number; keepPreviousResults?: boolean } } | undefined },
|
||||
flagsRef: { current: { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false } },
|
||||
lastArgsRef: { current: undefined as { directories: string[]; options?: { search?: string; limit?: number; keepPreviousResults?: boolean; allDirectories?: boolean } } | undefined },
|
||||
flagsRef: { current: { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false } },
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/hooks/useOpenCode')>()
|
||||
return {
|
||||
...actual,
|
||||
useSessionsAcrossDirectories: (directories: string[], options?: { search?: string; limit?: number; keepPreviousResults?: boolean }) => {
|
||||
useSessionsAcrossDirectories: (directories: string[], options?: { search?: string; limit?: number; keepPreviousResults?: boolean; allDirectories?: boolean }) => {
|
||||
lastArgsRef.current = { directories, options }
|
||||
const search = options?.search?.toLowerCase() ?? ''
|
||||
const data = search
|
||||
@@ -21,6 +21,7 @@ vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
||||
return {
|
||||
data,
|
||||
isLoading: false,
|
||||
isError: flagsRef.current.isError,
|
||||
isPlaceholderData: flagsRef.current.isPlaceholderData,
|
||||
fetchNextPage: vi.fn(),
|
||||
hasNextPage: flagsRef.current.hasNextPage,
|
||||
@@ -38,7 +39,7 @@ describe('useSessionSearch', () => {
|
||||
{ id: 'ses_beta', title: 'beta task', location: { directory: '/w/a' }, time: { updated: 1 } },
|
||||
)
|
||||
lastArgsRef.current = undefined
|
||||
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false }
|
||||
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -89,23 +90,59 @@ describe('useSessionSearch', () => {
|
||||
expect(result.current.isSearchPending).toBe(false)
|
||||
})
|
||||
|
||||
it('passes allDirectories through to useSessionsAcrossDirectories', () => {
|
||||
renderHook(() => useSessionSearch(['/w/a'], { allDirectories: true }))
|
||||
|
||||
expect(lastArgsRef.current?.options?.allDirectories).toBe(true)
|
||||
})
|
||||
|
||||
it('passes isError through from useSessionsAcrossDirectories', () => {
|
||||
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: true }
|
||||
|
||||
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
||||
|
||||
expect(result.current.isError).toBe(true)
|
||||
})
|
||||
|
||||
it('blocks pagination while a search is pending', () => {
|
||||
vi.useFakeTimers()
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
||||
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
||||
|
||||
expect(result.current.canFetchNextPage).toBe(true)
|
||||
|
||||
act(() => {
|
||||
result.current.setQuery('deploy')
|
||||
})
|
||||
|
||||
expect(result.current.isSearchPending).toBe(true)
|
||||
expect(result.current.canFetchNextPage).toBe(false)
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(150)
|
||||
})
|
||||
|
||||
expect(result.current.isSearchPending).toBe(false)
|
||||
expect(result.current.canFetchNextPage).toBe(true)
|
||||
})
|
||||
|
||||
it('exposes canFetchNextPage only when paging is safe', () => {
|
||||
const { result, rerender } = renderHook(() => useSessionSearch(['/w/a']))
|
||||
expect(result.current.canFetchNextPage).toBe(false)
|
||||
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false }
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
||||
rerender()
|
||||
expect(result.current.canFetchNextPage).toBe(true)
|
||||
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: true, isFetchNextPageError: false, isPlaceholderData: false }
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: true, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
||||
rerender()
|
||||
expect(result.current.canFetchNextPage).toBe(false)
|
||||
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: true, isPlaceholderData: false }
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: true, isPlaceholderData: false, isError: false }
|
||||
rerender()
|
||||
expect(result.current.canFetchNextPage).toBe(false)
|
||||
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: true }
|
||||
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: true, isError: false }
|
||||
rerender()
|
||||
expect(result.current.canFetchNextPage).toBe(false)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user