Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: User View Navigation Regression #209

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions apps/masterbots.ai/app/b/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { getChatbot, getBrowseThreads, getCategories } from '@/services/hasura'
import {
getChatbot,
getBrowseThreads
// getCategories
} from '@/services/hasura'
import { botNames } from '@/lib/bots-names'
import { ThreadList } from '@/components/shared/thread-list'
import AccountDetails from '@/components/shared/account-details'
import { CategoryTabs } from '@/components/shared/category-tabs/category-tabs'
import { SearchInput } from '@/components/shared/search-input'
// import { CategoryTabs } from '@/components/shared/category-tabs/category-tabs'
// import { SearchInput } from '@/components/shared/search-input'
import { toSlug } from '@/lib/url'

export default async function BotThreadsPage({
params
}: {
params: { id: string }
}) {
const categories = await getCategories()
// const categories = await getCategories()
let chatbot, threads

chatbot = await getChatbot({
Expand All @@ -28,9 +32,9 @@ export default async function BotThreadsPage({

console.log(chatbot.categories)
return (
<div className=" container">
<CategoryTabs categories={categories} />
<SearchInput />
<div>
{/* <CategoryTabs categories={categories} /> */}
{/* <SearchInput /> */}
<AccountDetails
alt={chatbot.name}
avatar={chatbot.avatar}
Expand All @@ -41,7 +45,7 @@ export default async function BotThreadsPage({
category={chatbot.categories[0]?.category.name}
/>
<div className="container">
<ThreadList filter={{ chatbotName }} initialThreads={threads} />
<ThreadList isBot filter={{ chatbotName }} initialThreads={threads} />
</div>
</div>
)
Expand Down
20 changes: 12 additions & 8 deletions apps/masterbots.ai/app/u/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {
getBrowseThreads,
getCategories,
// getCategories,
getUserInfoFromBrowse
} from '@/services/hasura'
import { ThreadList } from '@/components/shared/thread-list'
import AccountDetails from '@/components/shared/account-details'
import { CategoryTabs } from '@/components/shared/category-tabs/category-tabs'
import { SearchInput } from '@/components/shared/search-input'
// import { CategoryTabs } from '@/components/shared/category-tabs/category-tabs'
// import { SearchInput } from '@/components/shared/search-input'

export default async function BotThreadsPage({
params
}: {
params: { slug: string }
}) {
const categories = await getCategories()
// const categories = await getCategories()
const user = await getUserInfoFromBrowse(params.slug)
if (!user) return <div className="m-auto">No user found.</div>
const threads = await getBrowseThreads({
slug: params.slug,
limit: 20
})
return (
<div className="container">
<CategoryTabs categories={categories} />
<SearchInput />
<div>
{/* <CategoryTabs categories={categories} />
<SearchInput /> */}
<AccountDetails
alt={user.username}
avatar={user.profilePicture || ''}
Expand All @@ -32,7 +32,11 @@ export default async function BotThreadsPage({
username={user.username}
/>
<div className="container">
<ThreadList filter={{ slug: params.slug }} initialThreads={threads} />
<ThreadList
isUser
filter={{ slug: params.slug }}
initialThreads={threads}
/>
</div>
</div>
)
Expand Down
19 changes: 13 additions & 6 deletions apps/masterbots.ai/components/shared/account-details.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Image from 'next/image'
import Link from 'next/link'
import { Separator } from '../ui/separator'
import { cn } from '@/lib/utils'

export default function AccountDetails({
alt,
Expand All @@ -17,7 +18,12 @@ export default function AccountDetails({

return (
<div className="flex bg-cover py-10 bg-gradient-to-l from-mirage via-[#2B5D91] to-[#388DE2]">
<div className="dark:bg-[#09090B] bg-white rounded-lg p-6 max-w-[600px] flex flex-column gap-3 relative mx-auto font-mono min-w-[700px] min-h-[300px]">
<div
className={cn(
'dark:bg-[#09090B] bg-white rounded-lg p-6 max-w-[600px] flex flex-column gap-3 relative mx-auto font-mono min-w-[700px]',
chatbotName ? 'min-h-[300px]' : ''
)}
>
<div className="flex size-24 absolute border-4 border-[#388DE2] right-0 top-0 translate-x-1/4 rounded-full -translate-y-1/4 dark:bg-[#131316] bg-white">
<Image
alt={username || chatbotName}
Expand All @@ -34,12 +40,13 @@ export default function AccountDetails({
</div>
<Separator className="flex dark:bg-mirage bg-gray-300" />
<div className="flex text-xl font-semibold">{category}</div>
<div className="flex text-base grow">
<div className="flex font-medium">
{description ? <div className="flex">{description}</div> : ''}
{description && (
<div className="flex text-base grow">
<div className="flex font-medium">
<div className="flex">{description}</div>
</div>
</div>
</div>

)}
<div className="flex justify-between">
<div className="font-light">
Threads: <span className=" text-[#71717A]">{threadNum ?? 0}</span>
Expand Down
40 changes: 24 additions & 16 deletions apps/masterbots.ai/components/shared/thread-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function ThreadHeading({
response,
question,
copy = false,
chat = false
chat = false,
isUser = false,
isBot = false
}: ThreadHeadingProps) {
return (
<div className={cn(`flex flex-col font-medium w-full`)}>
Expand All @@ -20,28 +22,32 @@ export function ThreadHeading({
)}
>
<div className="flex grow gap-3">
<AccountAvatar
alt={thread.chatbot.name}
href={`/${chat ? 'c' : 'b'}/${toSlug(thread.chatbot.name)}`}
src={thread.chatbot.avatar}
/>
{!isBot && (
<AccountAvatar
alt={thread.chatbot.name}
href={`/${chat ? 'c' : 'b'}/${toSlug(thread.chatbot.name)}`}
src={thread.chatbot.avatar}
/>
)}

<div
className={cn(
'w-[calc(100%-64px)] m:w-[calc(100%-28px)] flex items-center gap-3 text-left'
)}
>
{question}
{chat ? null : (
<>
<span className="opacity-50 text-[0.875rem]">by</span>
<AccountAvatar
alt={thread.user.username}
href={`/u/${thread.user.slug}`}
src={thread.user.profilePicture || ''}
/>
</>
)}
{chat
? null
: !isUser && (
<>
<span className="opacity-50 text-[0.875rem]">by</span>
<AccountAvatar
alt={thread.user.username}
href={`/u/${thread.user.slug}`}
src={thread.user.profilePicture || ''}
/>
</>
)}
</div>
</div>
{copy ? <Shortlink /> : null}
Expand All @@ -62,4 +68,6 @@ interface ThreadHeadingProps {
question: string
copy?: boolean
chat?: boolean
isBot?: boolean
isUser?: boolean
}
20 changes: 16 additions & 4 deletions apps/masterbots.ai/components/shared/thread-list-accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { createMessagePairs } from '@/lib/threads'

export function ThreadListAccordion({
thread,
chat = false
chat = false,
isUser = false,
isBot = false
}: ThreadListAccordionProps) {
const [state, setState] = useSetState({
isOpen: false,
Expand All @@ -35,17 +37,25 @@ export function ThreadListAccordion({
type="multiple"
>
{/* Frist level question and excerpt visible on lists */}
<AccordionItem className="border-b-mirage border-solid relative" value="pair-1">
<AccordionItem
className="border-b-mirage border-solid relative"
value="pair-1"
>
<AccordionTrigger
isSticky
className={cn('hover:bg-mirage px-2 border border-[transparent] dark:border-b-mirage border-b-gray-300 rounded-t-lg', state.isOpen && 'bg-mirage')}
className={cn(
'hover:bg-mirage px-2 border border-[transparent] dark:border-b-mirage border-b-gray-300 rounded-t-lg',
state.isOpen && 'bg-mirage'
)}
>
<ThreadHeading
chat={chat}
copy={state.isOpen}
question={state.firstQuestion}
response={state.isOpen ? '' : state.firstResponse}
thread={thread}
{...(isBot ? { isBot } : {})}
{...(isUser ? { isUser } : {})}
/>
</AccordionTrigger>

Expand All @@ -60,7 +70,7 @@ export function ThreadListAccordion({
showHeading={false}
thread={thread}
initialMessagePairs={createMessagePairs(thread.messages)}
className='border-r-[transparent]'
className="border-r-[transparent]"
/>
</div>
</AccordionContent>
Expand All @@ -72,4 +82,6 @@ export function ThreadListAccordion({
interface ThreadListAccordionProps extends DialogProps {
thread: Thread
chat?: boolean
isBot?: boolean
isUser?: boolean
}
8 changes: 7 additions & 1 deletion apps/masterbots.ai/components/shared/thread-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export function ThreadList({
initialThreads,
filter,
chat = false,
dialog = false
dialog = false,
isUser = false,
isBot = false
}: ThreadListProps) {
const { query } = useGlobalStore()
const loadMoreRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -120,6 +122,8 @@ export function ThreadList({
defaultOpen={false} // we can have one open by default
key={thread.threadId}
thread={thread}
{...(isBot ? { isBot } : {})}
{...(isUser ? { isUser } : {})}
/>
))}
<div ref={loadMoreRef}>
Expand All @@ -134,4 +138,6 @@ interface ThreadListProps {
chat?: boolean
dialog?: boolean
filter: GetBrowseThreadsParams
isUser?: boolean
isBot?: boolean
}
Loading