-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: UI upt sync search with alpha branch #223
Changes from all commits
9e9a184
2e1b935
958d296
627f141
f4bef58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
import { DialogProps } from '@radix-ui/react-dialog' | ||
import type { MB } from '@repo/supabase' | ||
import { cn } from '@/lib/utils' | ||
'use client' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont use client here, remember we need to discuss as team everytime we want to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import { | ||
Accordion, | ||
AccordionContent, | ||
AccordionItem, | ||
AccordionTrigger | ||
} from '@/components/ui/accordion' | ||
import { createMessagePairs } from '@/lib/threads' | ||
import { cn, sleep } from '@/lib/utils' | ||
import { DialogProps } from '@radix-ui/react-dialog' | ||
import type { MB } from '@repo/supabase' | ||
import { useSearchParams } from 'next/navigation' | ||
import { useEffect, useRef } from 'react' | ||
import { useSetState } from 'react-use' | ||
import { ThreadAccordionClient } from './thread-accordion.client' | ||
import { ThreadHeading } from './thread-heading' | ||
import { createMessagePairs } from '@/lib/threads' | ||
|
||
export function ThreadListAccordion({ | ||
thread, | ||
chat = false | ||
chat = false, | ||
isUser = false, | ||
isBot = false | ||
}: ThreadListAccordionProps) { | ||
const [state, setState] = useSetState({ | ||
isOpen: false, | ||
firstQuestion: | ||
thread.messages.find(m => m.role === 'user')?.content || 'not found', | ||
firstResponse: | ||
thread.messages.find(m => m.role === 'assistant')?.content || 'not found' | ||
}) | ||
const searchParams = useSearchParams(); | ||
const threadRef = useRef<HTMLDivElement>(null) | ||
const handleThreadIdChange = async () => { | ||
if (searchParams.get('threadId') === thread.threadId) { | ||
await sleep(300) // animation time | ||
threadRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }) | ||
} else if (state.isOpen && searchParams.get('threadId')) { | ||
setState({ isOpen: false }) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
handleThreadIdChange() | ||
}, [searchParams]) | ||
|
||
return ( | ||
<Accordion className="w-full" type="multiple"> | ||
<AccordionItem value="pair-1"> | ||
<Accordion | ||
className="w-full" | ||
onValueChange={v => { | ||
setState({ isOpen: v[0] === 'pair-1' }) | ||
}} | ||
type="multiple" | ||
> | ||
{/* Frist level question and excerpt visible on lists */} | ||
<AccordionItem className="border-b-mirage border-solid relative" value="pair-1"> | ||
<AccordionTrigger | ||
className={cn('hover:bg-mirage px-5 data-[state=open]:bg-mirage')} | ||
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')} | ||
> | ||
<ThreadHeading | ||
chat={chat} | ||
|
@@ -36,11 +73,8 @@ export function ThreadListAccordion({ | |
<div className="overflow-y-scroll scrollbar srcoll-smooth max-h-[500px]"> | ||
<ThreadAccordionClient | ||
chat={chat} | ||
initialMessagePairs={createMessagePairs([ | ||
thread.firstMessage, | ||
thread.firstAnswer | ||
])} | ||
thread={thread} | ||
initialMessagePairs={createMessagePairs(thread.messages)} | ||
/> | ||
</div> | ||
</AccordionContent> | ||
|
@@ -50,6 +84,8 @@ export function ThreadListAccordion({ | |
} | ||
|
||
interface ThreadListAccordionProps extends DialogProps { | ||
thread: MB.ThreadFull | ||
thread: MB.Thread | ||
chat?: boolean | ||
isUser?: boolean | ||
isBot?: boolean | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
'use client' | ||
|
||
import React, { useEffect, useRef, useState } from 'react' | ||
import { useSearchParams, useRouter } from 'next/navigation' | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation' | ||
import { useEffect, useRef, useState } from 'react' | ||
|
||
// ! This component is not necessary to be split this way, only functionality. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is work in progress, you can ignore it |
||
// ! Though functionality looks correct, this causes an error in the app, a infinite loop very easy | ||
// ! I suggest to only split the code in the same file, or use a different approach to split the code. | ||
// * Search params might look fine but if an user goes (or saves) a link with a page number, it will be lost the first items that are on smaller page number | ||
// * E.g.: If I go to /?page=2, I will lose the first items that are on page 1... This is not a good user experience | ||
export function ThreadListReload() { | ||
const params = useSearchParams() | ||
const router = useRouter() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndlerRL dont use client for this. use aria-data css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aria on the CSS? The idea here is to scroll into the thread location, not to change the styling. How do I use then client functions without a client component? The
scrollIntoView
is client side. Why not touse client
here? 🤔