feat: Add list styling and optimize DragableList component
- Added list styling functionality to the DragableList component. - Removed unused imports and updated container height to accommodate additional content.
This commit is contained in:
parent
500e91977c
commit
e1ea875c21
@ -13,13 +13,14 @@ import { FC } from 'react'
|
|||||||
interface Props<T> {
|
interface Props<T> {
|
||||||
list: T[]
|
list: T[]
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
|
listStyle?: React.CSSProperties
|
||||||
children: (item: T, index: number) => React.ReactNode
|
children: (item: T, index: number) => React.ReactNode
|
||||||
onUpdate: (list: T[]) => void
|
onUpdate: (list: T[]) => void
|
||||||
onDragStart?: OnDragStartResponder
|
onDragStart?: OnDragStartResponder
|
||||||
onDragEnd?: OnDragEndResponder
|
onDragEnd?: OnDragEndResponder
|
||||||
}
|
}
|
||||||
|
|
||||||
const DragableList: FC<Props<any>> = ({ children, list, style, onDragStart, onUpdate, onDragEnd }) => {
|
const DragableList: FC<Props<any>> = ({ children, list, style, listStyle, onDragStart, onUpdate, onDragEnd }) => {
|
||||||
const _onDragEnd = (result: DropResult, provided: ResponderProvided) => {
|
const _onDragEnd = (result: DropResult, provided: ResponderProvided) => {
|
||||||
onDragEnd?.(result, provided)
|
onDragEnd?.(result, provided)
|
||||||
if (result.destination) {
|
if (result.destination) {
|
||||||
@ -34,7 +35,7 @@ const DragableList: FC<Props<any>> = ({ children, list, style, onDragStart, onUp
|
|||||||
<DragDropContext onDragStart={onDragStart} onDragEnd={_onDragEnd}>
|
<DragDropContext onDragStart={onDragStart} onDragEnd={_onDragEnd}>
|
||||||
<Droppable droppableId="droppable">
|
<Droppable droppableId="droppable">
|
||||||
{(provided) => (
|
{(provided) => (
|
||||||
<div {...provided.droppableProps} ref={provided.innerRef}>
|
<div {...provided.droppableProps} ref={provided.innerRef} style={{ ...style }}>
|
||||||
{list.map((item, index) => (
|
{list.map((item, index) => (
|
||||||
<Draggable key={`draggable_${item.id}_${index}`} draggableId={item.id} index={index}>
|
<Draggable key={`draggable_${item.id}_${index}`} draggableId={item.id} index={index}>
|
||||||
{(provided) => (
|
{(provided) => (
|
||||||
@ -42,7 +43,7 @@ const DragableList: FC<Props<any>> = ({ children, list, style, onDragStart, onUp
|
|||||||
ref={provided.innerRef}
|
ref={provided.innerRef}
|
||||||
{...provided.draggableProps}
|
{...provided.draggableProps}
|
||||||
{...provided.dragHandleProps}
|
{...provided.dragHandleProps}
|
||||||
style={{ ...provided.draggableProps.style, marginBottom: 8, ...style }}>
|
style={{ ...provided.draggableProps.style, marginBottom: 8, ...listStyle }}>
|
||||||
{children(item, index)}
|
{children(item, index)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import { fetchMessagesSummary } from '@renderer/services/api'
|
|||||||
import LocalStorage from '@renderer/services/storage'
|
import LocalStorage from '@renderer/services/storage'
|
||||||
import { useAppSelector } from '@renderer/store'
|
import { useAppSelector } from '@renderer/store'
|
||||||
import { Assistant, Topic } from '@renderer/types'
|
import { Assistant, Topic } from '@renderer/types'
|
||||||
import { Button, Dropdown, MenuProps } from 'antd'
|
import { Dropdown, MenuProps } from 'antd'
|
||||||
import { findIndex, take } from 'lodash'
|
import { findIndex } from 'lodash'
|
||||||
import { FC, useCallback, useState } from 'react'
|
import { FC, useCallback } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
@ -20,8 +20,6 @@ interface Props {
|
|||||||
|
|
||||||
const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic }) => {
|
const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic }) => {
|
||||||
const { assistant, removeTopic, updateTopic, updateTopics } = useAssistant(_assistant.id)
|
const { assistant, removeTopic, updateTopic, updateTopics } = useAssistant(_assistant.id)
|
||||||
const [showAll, setShowAll] = useState(false)
|
|
||||||
const [draging, setDraging] = useState(false)
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const generating = useAppSelector((state) => state.runtime.generating)
|
const generating = useAppSelector((state) => state.runtime.generating)
|
||||||
|
|
||||||
@ -99,14 +97,7 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<DragableList
|
<DragableList list={assistant.topics} onUpdate={updateTopics}>
|
||||||
list={take(assistant.topics, showAll ? assistant.topics.length : 14)}
|
|
||||||
onUpdate={updateTopics}
|
|
||||||
onDragStart={() => {
|
|
||||||
setShowAll(true)
|
|
||||||
setDraging(true)
|
|
||||||
}}
|
|
||||||
onDragEnd={() => setDraging(false)}>
|
|
||||||
{(topic) => {
|
{(topic) => {
|
||||||
const isActive = topic.id === activeTopic?.id
|
const isActive = topic.id === activeTopic?.id
|
||||||
return (
|
return (
|
||||||
@ -128,13 +119,6 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</DragableList>
|
</DragableList>
|
||||||
{!draging && assistant.topics.length > 15 && (
|
|
||||||
<Footer>
|
|
||||||
<Button type="link" onClick={() => setShowAll(!showAll)}>
|
|
||||||
{showAll ? t('button.collapse') : t('button.show.all')}
|
|
||||||
</Button>
|
|
||||||
</Footer>
|
|
||||||
)}
|
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -145,7 +129,7 @@ const Container = styled.div`
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
height: calc(100vh - var(--navbar-height));
|
max-height: calc(100vh - var(--navbar-height) - 140px);
|
||||||
`
|
`
|
||||||
|
|
||||||
const TopicListItem = styled.div`
|
const TopicListItem = styled.div`
|
||||||
@ -204,9 +188,4 @@ const MenuButton = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const Footer = styled.div`
|
|
||||||
margin: 0 4px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
`
|
|
||||||
|
|
||||||
export default Topics
|
export default Topics
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user