Spaces:
Sleeping
Sleeping
wuyiqunLu commited on
feat: virtual scroll for sidebar list (#46)
Browse fileshttps://github.com/landing-ai/vision-agent-ui/assets/132986242/34e787a6-c708-4f87-958a-594696c2fb42
Files changed (7)
9 unmodified lines101112131415161718199 unmodified lines}export default async function Layout({ children }: ChatLayoutProps) {const { isAdmin } = await authEmail();if (!isAdmin) {redirect('/');}const chats = await adminGetAllKVChats();9 unmodified lines1011121314151617181920219 unmodified lines}export default async function Layout({ children }: ChatLayoutProps) {const { isAdmin, user } = await authEmail();if (!isAdmin) {redirect('/');} else if (!user) {return null;}const chats = await adminGetAllKVChats();
8 unmodified lines9101112131415168 unmodified lines}export default async function Layout({ children }: ChatLayoutProps) {const { email, isAdmin } = await authEmail();const chats = await getKVChats();return (<div className="relative flex h-[calc(100vh_-_theme(spacing.16))] overflow-hidden"><div8 unmodified lines910111213141516171819208 unmodified lines}export default async function Layout({ children }: ChatLayoutProps) {const { email, isAdmin, user } = await authEmail();const chats = await getKVChats();if (!user) {return null;}return (<div className="relative flex h-[calc(100vh_-_theme(spacing.16))] overflow-hidden"><div
61 unmodified lines626364656661 unmodified linesexport async function authEmail() {const session = await auth();const email = session?.user?.email;return { email, isAdmin: !!email?.endsWith('landing.ai') };}61 unmodified lines62636465666768697061 unmodified linesexport async function authEmail() {const session = await auth();const email = session?.user?.email;return {email,isAdmin: !!email?.endsWith('landing.ai'),user: session?.user,};}
22 unmodified lines2324252627282922 unmodified linesreturn (<LinkclassName={cn('p-2 m-2 bg-background max-h-[100px] rounded-xl shadow-md flex items-center border border-transparent hover:border-gray-500 transition-all cursor-pointer',classNames,)}href={link}22 unmodified lines2324252627282922 unmodified linesreturn (<LinkclassName={cn('p-2 bg-background max-h-[100px] rounded-xl shadow-md flex items-center border border-transparent hover:border-gray-500 transition-all cursor-pointer w-full',classNames,)}href={link}
12345678910111213141516171819202122232425262728293031323334import ChatCard, { ChatCardLayout } from './ChatCard';import { IconPlus } from '../ui/Icons';import { auth } from '@/auth';import { ChatEntity } from '@/lib/types';export interface ChatSidebarListProps {chats: ChatEntity[];isAdminView?: boolean;}export default async function ChatSidebarList({chats,isAdminView,}: ChatSidebarListProps) {const session = await auth();if (!session || !session.user) {return null;}return (<>{!isAdminView && (<ChatCardLayout link="/chat"><div className="overflow-hidden flex items-center size-full"><IconPlus className="w-1/4 font-bold" /><p className="text-sm w-3/4 ml-3 font-bold">New chat</p></div></ChatCardLayout>)}{chats.map(chat => (<ChatCard key={chat.id} chat={chat} isAdminView={isAdminView} />))}</>);}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869'use client';import ChatCard, { ChatCardLayout } from './ChatCard';import { IconPlus } from '../ui/Icons';import { auth } from '@/auth';import { ChatEntity } from '@/lib/types';import { VariableSizeList as List } from 'react-window';import { cleanInputMessage } from '@/lib/messageUtils';import AutoSizer from 'react-virtualized-auto-sizer';export interface ChatSidebarListProps {chats: ChatEntity[];isAdminView?: boolean;}const getItemSize = (message: string, isAdminView?: boolean) => {if (message.length >= 45) return 116;else if (message.length >= 20) return 104;else return 88;};export default async function ChatSidebarList({chats,isAdminView,}: ChatSidebarListProps) {return (<>{!isAdminView && (<div className="p-2"><ChatCardLayout link="/chat"><div className="overflow-hidden flex items-center size-full"><IconPlus className="w-1/4 font-bold" /><p className="text-sm w-3/4 ml-3 font-bold">New chat</p></div></ChatCardLayout></div>)}<AutoSizer>{({ height, width }) => (<ListitemData={chats}height={height}itemCount={chats.length}itemSize={index =>getItemSize(cleanInputMessage(chats[index].messages?.[0]?.content ?? ''),isAdminView,)}width={width}>{({ style, index, data }) => (<divstyle={style}className="px-2 flex items-center overflow-hidden"><ChatCardkey={data[index].id}chat={data[index]}isAdminView={isAdminView}/></div>)}</List>)}</AutoSizer></>);}
48 unmodified lines4950515253545 unmodified lines60616263646548 unmodified lines"react-markdown": "^8.0.7","react-syntax-highlighter": "^15.5.0","react-textarea-autosize": "^8.5.3","remark-gfm": "^3.0.1","remark-math": "^5.1.1","sharp": "^0.33.3",5 unmodified lines"@types/react": "^18.2.48","@types/react-dom": "^18.2.18","@types/react-syntax-highlighter": "^15.5.11","@types/uuid": "^9.0.8","@typescript-eslint/parser": "^6.19.0","autoprefixer": "^10.4.17",48 unmodified lines49505152535455565 unmodified lines6263646566676848 unmodified lines"react-markdown": "^8.0.7","react-syntax-highlighter": "^15.5.0","react-textarea-autosize": "^8.5.3","react-virtualized-auto-sizer": "^1.0.24","react-window": "^1.8.10","remark-gfm": "^3.0.1","remark-math": "^5.1.1","sharp": "^0.33.3",5 unmodified lines"@types/react": "^18.2.48","@types/react-dom": "^18.2.18","@types/react-syntax-highlighter": "^15.5.11","@types/react-window": "^1.8.8","@types/uuid": "^9.0.8","@typescript-eslint/parser": "^6.19.0","autoprefixer": "^10.4.17",
115 unmodified lines11611711811912012122 unmodified lines1441451461471481491148 unmodified lines1298129913001301130213031267 unmodified lines257125722573257425752576545 unmodified lines3122312331243125312631272166 unmodified lines5294529552965297529852991504 unmodified lines680468056806680768086809650 unmodified lines746074617462746374647465115 unmodified linesreact-textarea-autosize:specifier: ^8.5.3version: 8.5.3(@types/react@18.2.79)(react@18.2.0)remark-gfm:specifier: ^3.0.1version: 3.0.122 unmodified lines'@types/react-syntax-highlighter':specifier: ^15.5.11version: 15.5.11'@types/uuid':specifier: ^9.0.8version: 9.0.81148 unmodified lines'@types/react-syntax-highlighter@15.5.11':resolution: {integrity: sha512-ZqIJl+Pg8kD+47kxUjvrlElrraSUrYa4h0dauY/U/FTUuprSCqvUj+9PNQNQzVc6AJgIWUUxn87/gqsMHNbRjw==}'@types/react@18.2.79':resolution: {integrity: sha512-RwGAGXPl9kSXwdNTafkOEuFrTBD5SA2B3iEB96xi8+xu5ddUa/cpvyVCSNn+asgLCTHkb5ZxN8gbuibYJi4s1w==}1267 unmodified linesmdn-data@2.0.30:resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==}merge2@1.4.1:resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}engines: {node: '>= 8'}545 unmodified linespeerDependencies:react: ^16.8.0 || ^17.0.0 || ^18.0.0react@18.2.0:resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}engines: {node: '>=0.10.0'}2166 unmodified linesdependencies:'@types/react': 18.2.79'@types/react@18.2.79':dependencies:'@types/prop-types': 15.7.121504 unmodified linesmdn-data@2.0.30: {}merge2@1.4.1: {}micromark-core-commonmark@1.1.0:650 unmodified linestransitivePeerDependencies:- '@types/react'react@18.2.0:dependencies:loose-envify: 1.4.0115 unmodified lines11611711811912012112212312412512612722 unmodified lines1501511521531541551561571581148 unmodified lines1307130813091310131113121313131413151267 unmodified lines258325842585258625872588258925902591545 unmodified lines31373138313931403141314231433144314531463147314831493150315131523153315431552166 unmodified lines53225323532453255326532753285329533053311504 unmodified lines68366837683868396840684168426843650 unmodified lines749474957496749774987499750075017502750375047505750675077508750975107511115 unmodified linesreact-textarea-autosize:specifier: ^8.5.3version: 8.5.3(@types/react@18.2.79)(react@18.2.0)react-virtualized-auto-sizer:specifier: ^1.0.24version: 1.0.24(react-dom@18.2.0(react@18.2.0))(react@18.2.0)react-window:specifier: ^1.8.10version: 1.8.10(react-dom@18.2.0(react@18.2.0))(react@18.2.0)remark-gfm:specifier: ^3.0.1version: 3.0.122 unmodified lines'@types/react-syntax-highlighter':specifier: ^15.5.11version: 15.5.11'@types/react-window':specifier: ^1.8.8version: 1.8.8'@types/uuid':specifier: ^9.0.8version: 9.0.81148 unmodified lines'@types/react-syntax-highlighter@15.5.11':resolution: {integrity: sha512-ZqIJl+Pg8kD+47kxUjvrlElrraSUrYa4h0dauY/U/FTUuprSCqvUj+9PNQNQzVc6AJgIWUUxn87/gqsMHNbRjw==}'@types/react-window@1.8.8':resolution: {integrity: sha512-8Ls660bHR1AUA2kuRvVG9D/4XpRC6wjAaPT9dil7Ckc76eP9TKWZwwmgfq8Q1LANX3QNDnoU4Zp48A3w+zK69Q==}'@types/react@18.2.79':resolution: {integrity: sha512-RwGAGXPl9kSXwdNTafkOEuFrTBD5SA2B3iEB96xi8+xu5ddUa/cpvyVCSNn+asgLCTHkb5ZxN8gbuibYJi4s1w==}1267 unmodified linesmdn-data@2.0.30:resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==}memoize-one@5.2.1:resolution: {integrity: sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==}merge2@1.4.1:resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}engines: {node: '>= 8'}545 unmodified linespeerDependencies:react: ^16.8.0 || ^17.0.0 || ^18.0.0react-virtualized-auto-sizer@1.0.24:resolution: {integrity: sha512-3kCn7N9NEb3FlvJrSHWGQ4iVl+ydQObq2fHMn12i5wbtm74zHOPhz/i64OL3c1S1vi9i2GXtZqNqUJTQ+BnNfg==}peerDependencies:react: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0react-dom: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0react-window@1.8.10:resolution: {integrity: sha512-Y0Cx+dnU6NLa5/EvoHukUD0BklJ8qITCtVEPY1C/nL8wwoZ0b5aEw8Ff1dOVHw7fCzMt55XfJDd8S8W8LCaUCg==}engines: {node: '>8.0.0'}peerDependencies:react: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0react-dom: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0react@18.2.0:resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}engines: {node: '>=0.10.0'}2166 unmodified linesdependencies:'@types/react': 18.2.79'@types/react-window@1.8.8':dependencies:'@types/react': 18.2.79'@types/react@18.2.79':dependencies:'@types/prop-types': 15.7.121504 unmodified linesmdn-data@2.0.30: {}memoize-one@5.2.1: {}merge2@1.4.1: {}micromark-core-commonmark@1.1.0:650 unmodified linestransitivePeerDependencies:- '@types/react'react-virtualized-auto-sizer@1.0.24(react-dom@18.2.0(react@18.2.0))(react@18.2.0):dependencies:react: 18.2.0react-dom: 18.2.0(react@18.2.0)react-window@1.8.10(react-dom@18.2.0(react@18.2.0))(react@18.2.0):dependencies:'@babel/runtime': 7.24.4memoize-one: 5.2.1react: 18.2.0react-dom: 18.2.0(react@18.2.0)react@18.2.0:dependencies:loose-envify: 1.4.0
app/all/layout.tsx+3-1
app/chat/layout.tsx+5-1
auth.ts+5-1
components/chat-sidebar/ChatCard.tsx+1-1
components/chat-sidebar/ChatListSidebar.tsx+48-13
package.json+3
pnpm-lock.yaml+46