mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-05 04:10:29 +08:00
Update Sessions.tsx
This commit is contained in:
parent
4a68052d2e
commit
498eca1e31
@ -1,4 +1,4 @@
|
|||||||
import { DraggableVirtualList, type DraggableVirtualListRef } from '@renderer/components/DraggableList'
|
import { DynamicVirtualList, type DynamicVirtualListRef } from '@renderer/components/VirtualList'
|
||||||
import { useCreateDefaultSession } from '@renderer/hooks/agents/useCreateDefaultSession'
|
import { useCreateDefaultSession } from '@renderer/hooks/agents/useCreateDefaultSession'
|
||||||
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
||||||
import { useRuntime } from '@renderer/hooks/useRuntime'
|
import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||||
@ -14,6 +14,7 @@ import { Alert, Spin } from 'antd'
|
|||||||
import { motion } from 'framer-motion'
|
import { motion } from 'framer-motion'
|
||||||
import { memo, useCallback, useEffect, useRef } from 'react'
|
import { memo, useCallback, useEffect, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
import AddButton from './AddButton'
|
import AddButton from './AddButton'
|
||||||
import SessionItem from './SessionItem'
|
import SessionItem from './SessionItem'
|
||||||
@ -24,12 +25,12 @@ interface SessionsProps {
|
|||||||
|
|
||||||
const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { sessions, isLoading, error, deleteSession, hasMore, loadMore, isLoadingMore, total } = useSessions(agentId)
|
const { sessions, isLoading, error, deleteSession, hasMore, loadMore, isLoadingMore } = useSessions(agentId)
|
||||||
const { chat } = useRuntime()
|
const { chat } = useRuntime()
|
||||||
const { activeSessionIdMap } = chat
|
const { activeSessionIdMap } = chat
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { createDefaultSession, creatingSession } = useCreateDefaultSession(agentId)
|
const { createDefaultSession, creatingSession } = useCreateDefaultSession(agentId)
|
||||||
const listRef = useRef<DraggableVirtualListRef>(null)
|
const listRef = useRef<DynamicVirtualListRef>(null)
|
||||||
|
|
||||||
// Handle scroll to load more
|
// Handle scroll to load more
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -113,20 +114,18 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DraggableVirtualList
|
<StyledVirtualList
|
||||||
ref={listRef}
|
ref={listRef}
|
||||||
className="sessions-tab"
|
className="sessions-tab"
|
||||||
list={sessions}
|
list={sessions}
|
||||||
disabled
|
estimateSize={() => 9 * 4}
|
||||||
style={{ height: '100%', padding: '9px 0 10px 10px' }}
|
// FIXME: This component only supports CSSProperties
|
||||||
itemContainerStyle={{ paddingBottom: '8px' }}
|
scrollerStyle={{ overflowX: 'hidden' }}
|
||||||
|
autoHideScrollbar
|
||||||
header={
|
header={
|
||||||
<>
|
<AddButton onClick={createDefaultSession} disabled={creatingSession} className="-mt-[4px] mb-[6px]">
|
||||||
<AddButton onClick={createDefaultSession} disabled={creatingSession}>
|
{t('agent.session.add.title')}
|
||||||
{t('agent.session.add.title')}
|
</AddButton>
|
||||||
</AddButton>
|
|
||||||
<div className="my-1"></div>
|
|
||||||
</>
|
|
||||||
}>
|
}>
|
||||||
{(session, index) => (
|
{(session, index) => (
|
||||||
<>
|
<>
|
||||||
@ -144,8 +143,15 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</DraggableVirtualList>
|
</StyledVirtualList>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StyledVirtualList = styled(DynamicVirtualList)`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 12px 10px;
|
||||||
|
height: 100%;
|
||||||
|
` as typeof DynamicVirtualList
|
||||||
|
|
||||||
export default memo(Sessions)
|
export default memo(Sessions)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user