diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 3a539ad..35a3407 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -1,5 +1,6 @@ import { useMemo } from 'react' import { Config, ConfigProvider } from '../../hooks/useConfig.js' +import { getGitHubSource } from '../../lib/sources/gitHubSource.js' import { getHttpSource } from '../../lib/sources/httpSource.js' import { getHuggingFaceSource } from '../../lib/sources/huggingFaceSource.js' import { getHyperparamSource } from '../../lib/sources/hyperparamSource.js' @@ -12,6 +13,7 @@ export default function App() { const col = search.get('col') === null ? undefined : Number(search.get('col')) const source = getHuggingFaceSource(sourceId) ?? + getGitHubSource(sourceId) ?? getHttpSource(sourceId) ?? getHyperparamSource(sourceId, { endpoint: location.origin }) diff --git a/src/components/Folder/Folder.test.tsx b/src/components/Folder/Folder.test.tsx index 1084203..c75a416 100644 --- a/src/components/Folder/Folder.test.tsx +++ b/src/components/Folder/Folder.test.tsx @@ -95,7 +95,6 @@ describe('Folder Component', () => { sourceId: 'test-source', sourceParts: [{ text: 'test-source', sourceId: 'test-source' }], kind: 'directory', - prefix: '', listFiles: () => Promise.resolve(mockFiles), } const { getByPlaceholderText, findByText, getByText, queryByText } = render() @@ -133,7 +132,6 @@ describe('Folder Component', () => { sourceId: 'test-source', sourceParts: [{ text: 'test-source', sourceId: 'test-source' }], kind: 'directory', - prefix: '', listFiles: () => Promise.resolve(mockFiles), } const { getByPlaceholderText, findByText } = render() @@ -153,7 +151,6 @@ describe('Folder Component', () => { sourceId: 'test-source', sourceParts: [{ text: 'test-source', sourceId: 'test-source' }], kind: 'directory', - prefix: '', listFiles: async () => { await fetch('something') // to ensure we wait for loading return [] diff --git a/src/components/Folder/Folder.tsx b/src/components/Folder/Folder.tsx index 3919a4a..b3ebd61 100644 --- a/src/components/Folder/Folder.tsx +++ b/src/components/Folder/Folder.tsx @@ -63,15 +63,15 @@ export default function Folder({ source }: FolderProps) { } else if (e.key === 'Enter') { // if there is only one result, view it if (filtered?.length === 1 && 0 in filtered) { - const key = join(source.prefix, filtered[0].name) - if (key.endsWith('/')) { + const file = filtered[0] + if (file.kind === 'directory') { // clear search because we're about to change folder if (searchRef.current) { searchRef.current.value = '' } setSearchQuery('') } - location.href = `/files?key=${key}` + location.href = routes?.getSourceRouteUrl?.({ sourceId: file.sourceId }) ?? `/files?key=${file.sourceId}` } } else if (e.key === 'ArrowDown') { // move focus to first list item @@ -81,7 +81,7 @@ export default function Folder({ source }: FolderProps) { searchElement?.addEventListener('keyup', handleKeyup) // Clean up event listener return () => searchElement?.removeEventListener('keyup', handleKeyup) - }, [filtered, source.prefix]) + }, [filtered, routes]) // Jump to search box if user types '/' useEffect(() => { @@ -97,7 +97,7 @@ export default function Folder({ source }: FolderProps) { return () => { document.removeEventListener('keydown', handleKeydown) } }, []) - return + return @@ -114,7 +114,7 @@ export default function Folder({ source }: FolderProps) {