Skip to content

Commit

Permalink
fix: redirect to thread landing on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
gaboesquivel committed Apr 14, 2024
1 parent 5cb2b62 commit 992167e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions apps/masterbots.ai/app/(browse)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ThreadList } from '@/components/shared/thread-list'
import { CategoryTabs } from '@/components/shared/category-tabs/category-tabs'
import { SearchInput } from '@/components/shared/search-input'
import { getBrowseThreads, getCategories } from '@/services/hasura'
import { getBrowseThreads, getCategories, getThread } from '@/services/hasura'
import { Card } from '@/components/ui/card'
import { decodeQuery } from '@/lib/url'
import { permanentRedirect } from 'next/navigation'
import { getThreadLink } from '@/lib/threads'

export default async function HomePage({ searchParams }: HomePageProps) {
if (searchParams.threadId) {
const thread = await getThread({ threadId: searchParams.threadId })
permanentRedirect(getThreadLink({ thread }))
}

const categories = await getCategories()
const query = searchParams.query ? decodeQuery(searchParams.query) : null
const limit = searchParams.limit ? parseInt(searchParams.limit) : 20
Expand Down Expand Up @@ -44,5 +51,10 @@ export default async function HomePage({ searchParams }: HomePageProps) {
}

interface HomePageProps {
searchParams?: { query: string; page: string; limit: string }
searchParams?: {
query: string
page: string
limit: string
threadId: string
}
}
2 changes: 1 addition & 1 deletion apps/masterbots.ai/lib/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export function getAllUserMessagesAsStringArray(
return cleanMessages.join(', ')
}

export function getThreadLink({chat=false, thread}:{chat:boolean, thread: Thread}){
export function getThreadLink({chat=false, thread}:{chat?:boolean, thread: Thread}){
return chat ? `/c/${toSlug(thread.chatbot.name)}/${thread.threadId}` : `/${toSlug(thread.chatbot.categories[0]?.category.name)}/${thread.threadId}`
}

0 comments on commit 992167e

Please sign in to comment.