import { useState } from "preact/hooks"; import { ChatStore } from "./app"; import { calculate_token_length } from "./chatgpt"; import Markdown from "preact-markdown"; interface Props { messageIndex: number; chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; update_total_tokens: () => void; } export default function Message(props: Props) { const { chatStore, messageIndex, setChatStore } = props; const chat = chatStore.history[messageIndex]; const [showEdit, setShowEdit] = useState(false); const [showCopiedHint, setShowCopiedHint] = useState(false); const [renderMarkdown, setRenderWorkdown] = useState(false); const DeleteIcon = () => ( ); const CopiedHint = () => ( Message Copied to clipboard! ); const CopyIcon = () => { return ( <> > ); }; return ( <> {chatStore.postBeginIndex !== 0 && !chatStore.history[messageIndex].hide && chatStore.postBeginIndex === chatStore.history.slice(0, messageIndex).filter(({ hide }) => !hide) .length && (
{chat.hide ? (
chat.content.split("\n")[0].slice(0, 16) + "... (deleted)"
) : renderMarkdown ? (
// @ts-ignore