mirror of
https://github.com/openclaw/clawhub.git
synced 2026-08-15 17:32:22 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56d83e00fc | ||
|
|
34583a640c |
@@ -7,25 +7,33 @@ vi.mock('@tanstack/react-router', () => ({
|
||||
|
||||
import { Route } from '../routes/search'
|
||||
|
||||
function runBeforeLoad(search: { q?: string; highlighted?: boolean }, hostname = 'clawdhub.com') {
|
||||
const route = Route as unknown as {
|
||||
__config: {
|
||||
beforeLoad?: (args: {
|
||||
search: { q?: string; highlighted?: boolean }
|
||||
location: { url: URL }
|
||||
}) => void
|
||||
}
|
||||
}
|
||||
const beforeLoad = route.__config.beforeLoad as (args: {
|
||||
search: { q?: string; highlighted?: boolean }
|
||||
location: { url: URL }
|
||||
}) => void
|
||||
let thrown: unknown
|
||||
|
||||
try {
|
||||
beforeLoad({ search, location: { url: new URL(`https://${hostname}/search`) } })
|
||||
} catch (error) {
|
||||
thrown = error
|
||||
}
|
||||
|
||||
return thrown
|
||||
}
|
||||
|
||||
describe('search route', () => {
|
||||
it('redirects to the skills index', () => {
|
||||
const route = Route as unknown as {
|
||||
__config: {
|
||||
beforeLoad?: (args: { search: { q?: string; highlighted?: boolean } }) => void
|
||||
}
|
||||
}
|
||||
const beforeLoad = route.__config.beforeLoad as (args: {
|
||||
search: { q?: string; highlighted?: boolean }
|
||||
}) => void
|
||||
let thrown: unknown
|
||||
|
||||
try {
|
||||
beforeLoad({ search: { q: 'crab', highlighted: true } })
|
||||
} catch (error) {
|
||||
thrown = error
|
||||
}
|
||||
|
||||
expect(thrown).toEqual({
|
||||
it('redirects skills host to the skills index', () => {
|
||||
expect(runBeforeLoad({ q: 'crab', highlighted: true }, 'clawdhub.com')).toEqual({
|
||||
redirect: {
|
||||
to: '/skills',
|
||||
search: {
|
||||
@@ -37,29 +45,28 @@ describe('search route', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('redirects to the skills index without query', () => {
|
||||
const route = Route as unknown as {
|
||||
__config: {
|
||||
beforeLoad?: (args: { search: { q?: string; highlighted?: boolean } }) => void
|
||||
}
|
||||
}
|
||||
const beforeLoad = route.__config.beforeLoad as (args: {
|
||||
search: { q?: string; highlighted?: boolean }
|
||||
}) => void
|
||||
let thrown: unknown
|
||||
|
||||
try {
|
||||
beforeLoad({ search: {} })
|
||||
} catch (error) {
|
||||
thrown = error
|
||||
}
|
||||
|
||||
expect(thrown).toEqual({
|
||||
it('redirects souls host with query to home search', () => {
|
||||
expect(runBeforeLoad({ q: 'crab', highlighted: true }, 'onlycrabs.ai')).toEqual({
|
||||
redirect: {
|
||||
to: '/skills',
|
||||
to: '/',
|
||||
search: {
|
||||
q: 'crab',
|
||||
highlighted: undefined,
|
||||
search: undefined,
|
||||
},
|
||||
replace: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('redirects souls host without query to home with search mode', () => {
|
||||
expect(runBeforeLoad({}, 'onlycrabs.ai')).toEqual({
|
||||
redirect: {
|
||||
to: '/',
|
||||
search: {
|
||||
q: undefined,
|
||||
highlighted: undefined,
|
||||
search: true,
|
||||
},
|
||||
replace: true,
|
||||
},
|
||||
|
||||
@@ -84,7 +84,7 @@ export default function Header() {
|
||||
Upload
|
||||
</Link>
|
||||
{isSoulMode ? null : <Link to="/import">Import</Link>}
|
||||
<Link to="/" search={{ q: undefined, highlighted: undefined, search: true }}>
|
||||
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>
|
||||
Search
|
||||
</Link>
|
||||
{me ? <Link to="/stars">Stars</Link> : null}
|
||||
@@ -138,7 +138,7 @@ export default function Header() {
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem asChild>
|
||||
<Link to="/" search={{ q: undefined, highlighted: undefined, search: true }}>
|
||||
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>
|
||||
Search
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
|
||||
+23
-3
@@ -1,16 +1,36 @@
|
||||
import { createFileRoute, redirect } from '@tanstack/react-router'
|
||||
import { detectSiteMode } from '../lib/site'
|
||||
|
||||
export const Route = createFileRoute('/search')({
|
||||
validateSearch: (search) => ({
|
||||
q: typeof search.q === 'string' && search.q.trim() ? search.q : undefined,
|
||||
highlighted: search.highlighted === '1' || search.highlighted === 'true' ? true : undefined,
|
||||
}),
|
||||
beforeLoad: ({ search }) => {
|
||||
beforeLoad: ({ search, location }) => {
|
||||
const hostname =
|
||||
(location as { url?: URL }).url?.hostname ??
|
||||
(typeof window !== 'undefined' ? window.location.hostname : undefined)
|
||||
const mode = detectSiteMode(hostname)
|
||||
if (mode === 'skills') {
|
||||
throw redirect({
|
||||
to: '/skills',
|
||||
search: {
|
||||
q: search.q || undefined,
|
||||
sort: undefined,
|
||||
dir: undefined,
|
||||
highlighted: search.highlighted || undefined,
|
||||
view: undefined,
|
||||
},
|
||||
replace: true,
|
||||
})
|
||||
}
|
||||
|
||||
throw redirect({
|
||||
to: '/skills',
|
||||
to: '/',
|
||||
search: {
|
||||
q: search.q || undefined,
|
||||
highlighted: search.highlighted || undefined,
|
||||
highlighted: undefined,
|
||||
search: search.q ? undefined : true,
|
||||
},
|
||||
replace: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user