mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 03:26:38 +08:00
Create chat-list.tsx
This commit is contained in:
parent
2fdd4f247e
commit
85ca576389
73
app/components/chat-list.tsx
Normal file
73
app/components/chat-list.tsx
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import { useState, useRef, useEffect, useLayoutEffect } from "react";
|
||||||
|
import DeleteIcon from "../icons/delete.svg";
|
||||||
|
import styles from "./home.module.scss";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Message,
|
||||||
|
SubmitKey,
|
||||||
|
useChatStore,
|
||||||
|
ChatSession,
|
||||||
|
BOT_HELLO,
|
||||||
|
} from "../store";
|
||||||
|
|
||||||
|
import Locale from "../locales";
|
||||||
|
import { isMobileScreen } from "../utils";
|
||||||
|
|
||||||
|
export function ChatItem(props: {
|
||||||
|
onClick?: () => void;
|
||||||
|
onDelete?: () => void;
|
||||||
|
title: string;
|
||||||
|
count: number;
|
||||||
|
time: string;
|
||||||
|
selected: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`${styles["chat-item"]} ${
|
||||||
|
props.selected && styles["chat-item-selected"]
|
||||||
|
}`}
|
||||||
|
onClick={props.onClick}
|
||||||
|
>
|
||||||
|
<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"]} onClick={props.onDelete}>
|
||||||
|
<DeleteIcon />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ChatList() {
|
||||||
|
const [sessions, selectedIndex, selectSession, removeSession] = useChatStore(
|
||||||
|
(state) => [
|
||||||
|
state.sessions,
|
||||||
|
state.currentSessionIndex,
|
||||||
|
state.selectSession,
|
||||||
|
state.removeSession,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles["chat-list"]}>
|
||||||
|
{sessions.map((item, i) => (
|
||||||
|
<ChatItem
|
||||||
|
title={item.topic}
|
||||||
|
time={item.lastUpdate}
|
||||||
|
count={item.messages.length}
|
||||||
|
key={i}
|
||||||
|
selected={i === selectedIndex}
|
||||||
|
onClick={() => selectSession(i)}
|
||||||
|
onDelete={() =>
|
||||||
|
(!isMobileScreen() || confirm(Locale.Home.DeleteChat)) &&
|
||||||
|
removeSession(i)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user