Skip to content

Commit

Permalink
Delete message
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Apr 28, 2024
1 parent a57ee65 commit 490753a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/ChatHistory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { memo, useState } from "react";
import { Box, CircularProgress, TextField, IconButton, useTheme } from "@mui/material";
import ReactMarkdown from "react-markdown";
import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import { CodeBlock } from "./CodeBlock";
import { Lightbox } from "react-modal-image";
Expand Down Expand Up @@ -55,7 +56,7 @@ const linkStyle = {
wordBreak: "break-all",
};

const ChatHistory = memo(({ chatHistory, isModelResponding, onRun, onChange }) => {
const ChatHistory = memo(({ chatHistory, isModelResponding, onRun, onChange, onDelete }) => {
const [isLightboxOpen, setIsLightboxOpen] = useState(false);
const [lightboxImageIndex, setLightboxImageIndex] = useState(0);
const [lightboxMessageIndex, setLightboxMessageIndex] = useState(0);
Expand All @@ -78,6 +79,12 @@ const ChatHistory = memo(({ chatHistory, isModelResponding, onRun, onChange }) =
setEditingMessage(newMessage);
};

const handleDeleteClick = (index) => {
const updatedChatHistory = [...chatHistory];
updatedChatHistory.splice(index, 1);
onDelete(updatedChatHistory);
};

const handleKeyDown = (e) => {
if (e.key === "Enter" || e.keyCode === 13) {
setEditingMessageIndex(-1);
Expand Down Expand Up @@ -127,6 +134,9 @@ const ChatHistory = memo(({ chatHistory, isModelResponding, onRun, onChange }) =
/>
) : (
<>
<IconButton size="small" onClick={() => handleDeleteClick(index)}>
<DeleteIcon fontSize="inherit" />
</IconButton>
{chat.user}
<IconButton size="small" onClick={() => handleEditClick(index, chat.user)}>
<EditIcon fontSize="inherit" />
Expand Down
5 changes: 5 additions & 0 deletions src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ function Main({ darkMode, toggleTheme }) {
sendFileAndQuery(null, null, newHistory[index].user, newHistory.slice(0, index));
};

const handleDelete = async (newHistory) => {
setChatHistory(newHistory);
};

const fetchUserData = async () => {
const token = localStorage.getItem("token");
const headers = {
Expand Down Expand Up @@ -466,6 +470,7 @@ function Main({ darkMode, toggleTheme }) {
>
<ChatHistory
onChange={handleChange}
onDelete={handleDelete}
onRun={handleRun}
chatHistory={chatHistory}
isModelResponding={isModelResponding}
Expand Down

0 comments on commit 490753a

Please sign in to comment.