临时修复

This commit is contained in:
sijinhui 2024-09-24 23:07:25 +08:00
parent 0ff74f01d3
commit 1d04796ca0

View File

@ -32,6 +32,7 @@ export function ChatItem(props: {
index: number; index: number;
narrow?: boolean; narrow?: boolean;
mask: Mask; mask: Mask;
provided;
}) { }) {
const draggableRef = useRef<HTMLDivElement | null>(null); const draggableRef = useRef<HTMLDivElement | null>(null);
useEffect(() => { useEffect(() => {
@ -44,62 +45,54 @@ export function ChatItem(props: {
const { pathname: currentPath } = useLocation(); const { pathname: currentPath } = useLocation();
return ( return (
<Draggable draggableId={`${props.id}`} index={props.index}> <div
{(provided) => ( className={`${styles["chat-item"]} ${
<div props.selected &&
className={`${styles["chat-item"]} ${ (currentPath === Path.Chat || currentPath === Path.Home) &&
props.selected && styles["chat-item-selected"]
(currentPath === Path.Chat || currentPath === Path.Home) && }`}
styles["chat-item-selected"] onClick={props.onClick}
}`} ref={(ele) => {
onClick={props.onClick} draggableRef.current = ele;
ref={(ele) => { props.provided.innerRef(ele);
draggableRef.current = ele; }}
provided.innerRef(ele); {...props.provided.draggableProps}
}} {...props.provided.dragHandleProps}
{...provided.draggableProps} title={`${props.title}\n${Locale.ChatItem.ChatItemCount(props.count)}`}
{...provided.dragHandleProps} >
title={`${props.title}\n${Locale.ChatItem.ChatItemCount( {props.narrow ? (
props.count, <div className={styles["chat-item-narrow"]}>
)}`} <div className={styles["chat-item-avatar"] + " no-dark"}>
> <MaskAvatar
{props.narrow ? ( avatar={props.mask.avatar}
<div className={styles["chat-item-narrow"]}> model={props.mask.modelConfig.model}
<div className={styles["chat-item-avatar"] + " no-dark"}> />
<MaskAvatar
avatar={props.mask.avatar}
model={props.mask.modelConfig.model}
/>
</div>
<div className={styles["chat-item-narrow-count"]}>
{props.count}
</div>
</div>
) : (
<>
<div className={styles["chat-item-title"]}>{props.title}</div>
<div className={styles["chat-item-info"]}>
<div className={styles["chat-item-count"]}>
{Locale.ChatItem.ChatItemCount(props.count)}
</div>
<div className={styles["chat-item-date"]}>{props.time}</div>
</div>
</>
)}
<div
className={styles["chat-item-delete"]}
onClickCapture={(e) => {
props.onDelete?.();
e.preventDefault();
e.stopPropagation();
}}
>
<DeleteIcon />
</div> </div>
<div className={styles["chat-item-narrow-count"]}>{props.count}</div>
</div> </div>
) : (
<>
<div className={styles["chat-item-title"]}>{props.title}</div>
<div className={styles["chat-item-info"]}>
<div className={styles["chat-item-count"]}>
{Locale.ChatItem.ChatItemCount(props.count)}
</div>
<div className={styles["chat-item-date"]}>{props.time}</div>
</div>
</>
)} )}
</Draggable>
<div
className={styles["chat-item-delete"]}
onClickCapture={(e) => {
props.onDelete?.();
e.preventDefault();
e.stopPropagation();
}}
>
<DeleteIcon />
</div>
</div>
); );
} }
@ -133,12 +126,39 @@ export function ChatList(props: { narrow?: boolean }) {
}; };
return ( return (
<DragDropContext <DragDropContext onDragEnd={onDragEnd}>
onDragEnd={onDragEnd} <Droppable
autoScrollerOptions={{ disabled: true }} droppableId="chat-list"
> renderClone={(provided, snapshot, rubic) => (
<Droppable droppableId="chat-list"> <ChatItem
{(provided) => ( title={sessions[rubic.source.index].topic}
time={new Date(
sessions[rubic.source.index].lastUpdate,
).toLocaleString()}
count={sessions[rubic.source.index].messages.length}
key={sessions[rubic.source.index].id}
id={sessions[rubic.source.index].id}
index={rubic.source.index}
selected={rubic.source.index === selectedIndex}
onClick={() => {
navigate(Path.Chat);
selectSession(rubic.source.index);
}}
onDelete={async () => {
if (
(!props.narrow && !isMobileScreen) ||
(await showConfirm(Locale.Home.DeleteChat))
) {
chatStore.deleteSession(rubic.source.index);
}
}}
narrow={props.narrow}
mask={sessions[rubic.source.index].mask}
provided={provided}
/>
)}
>
{(provided, snapshot) => (
<div <div
className={styles["chat-list"]} className={styles["chat-list"]}
ref={provided.innerRef} ref={provided.innerRef}
@ -146,10 +166,8 @@ export function ChatList(props: { narrow?: boolean }) {
> >
<QueueAnim <QueueAnim
delay={300} delay={300}
// className={motionStyles["queue-simple"]}
ease={["easeOutQuart", "easeInOutQuart"]} ease={["easeOutQuart", "easeInOutQuart"]}
duration={[550, 450]} duration={[550, 450]}
type={["right", "left"]}
animConfig={[ animConfig={[
{ opacity: [1, 0], translateY: [0, 30] }, { opacity: [1, 0], translateY: [0, 30] },
{ height: 0 }, { height: 0 },
@ -158,30 +176,35 @@ export function ChatList(props: { narrow?: boolean }) {
// interval={150} // interval={150}
> >
{sessions.map((item, i) => ( {sessions.map((item, i) => (
<div key={i}> <div key={item.id}>
<ChatItem <Draggable draggableId={`${item.id}`} index={i}>
title={item.topic} {(provided, snapshot) => (
time={new Date(item.lastUpdate).toLocaleString()} <ChatItem
count={item.messages.length} title={item.topic}
key={item.id} time={new Date(item.lastUpdate).toLocaleString()}
id={item.id} count={item.messages.length}
index={i} key={item.id}
selected={i === selectedIndex} id={item.id}
onClick={() => { index={i}
navigate(Path.Chat); selected={i === selectedIndex}
selectSession(i); onClick={() => {
}} navigate(Path.Chat);
onDelete={async () => { selectSession(i);
if ( }}
(!props.narrow && !isMobileScreen) || onDelete={async () => {
(await showConfirm(Locale.Home.DeleteChat)) if (
) { (!props.narrow && !isMobileScreen) ||
chatStore.deleteSession(i); (await showConfirm(Locale.Home.DeleteChat))
} ) {
}} chatStore.deleteSession(i);
narrow={props.narrow} }
mask={item.mask} }}
/> narrow={props.narrow}
mask={item.mask}
provided={provided}
/>
)}
</Draggable>
</div> </div>
))} ))}
</QueueAnim> </QueueAnim>