Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clear chat #9

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions src/components/ChatContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,36 @@ import React, {
} from "react";
import { Message, useChat } from "ai/react";
import { Card } from "./ui/card";
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card";
import { MarkdownViewer } from "./MarkdownViewer";
import { useControlContext } from "@/providers/ControlContext";
import { CommonForm } from "./CommonForm";
import { TypingBubble } from "./TypingBubble";
import { MessageCircleX } from "lucide-react";

export const ChatContainer = () => {
const { generalSettings, safetySettings } = useControlContext();
const [loading, setLoading] = useState<boolean>(false);

const { messages, input, handleInputChange, handleSubmit } = useChat({
id: "gemini-pro",
api: `/api/gemini-pro`,
body: {
general_settings: generalSettings,
safety_settings: safetySettings,
},
onError: () => {
setLoading(false);
},
onFinish: () => {
setLoading(false);
},
});
const { messages, setMessages, input, handleInputChange, handleSubmit } =
useChat({
id: "gemini-pro",
api: `/api/gemini-pro`,
body: {
general_settings: generalSettings,
safety_settings: safetySettings,
},
onError: () => {
setLoading(false);
},
onFinish: () => {
setLoading(false);
},
});

const messagesEndRef = useRef<HTMLDivElement>(null);

Expand All @@ -49,10 +56,32 @@ export const ChatContainer = () => {
handleSubmit(event);
};

const handleClearChat = () => {
setMessages([]);
};

return (
<div className="flex flex-col h-[95vh]">
<Card className="flex flex-col flex-1 overflow-hidden">
<div className="flex-1 overflow-y-auto">
{messages.length > 0 && (
<div className={`flex justify-end p-4`}>
<HoverCard openDelay={200}>
<HoverCardTrigger asChild onClick={handleClearChat}>
<div className={`text-primary/60 hover:text-primary/90`}>
<MessageCircleX />
</div>
</HoverCardTrigger>
<HoverCardContent
align="start"
className="w-[260px] text-sm"
side="right"
>
Clear chat history
</HoverCardContent>
</HoverCard>
</div>
)}
{messages.map((message: Message) => (
<div
key={message.id}
Expand Down
1 change: 1 addition & 0 deletions src/components/CommonForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use client";
// components/CommonForm.tsx
import React, {
useState,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageUploadComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ImageUploadComponent: React.FC<ImageUploadComponentProps> = memo(

const removeMedia = useCallback(() => {
setMedia(null);
onRemove(); // Use the onRemove prop instead
onRemove();
}, [onRemove]);

const resizeImage = useCallback(
Expand Down
1 change: 0 additions & 1 deletion src/components/MarkdownViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";
// components/MarkdownViewer.tsx
import React, { useMemo, useState } from "react";
// import CodeBlock from "./CodeBlock";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import rehypeRaw from "rehype-raw";
Expand Down
2 changes: 1 addition & 1 deletion src/components/VisionContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const VisionContainer = () => {
setLoading(false);
}
},
[mediaDataList, prompt, generalSettings, safetySettings]
[mediaDataList, generalSettings, safetySettings]
);

const handleRefresh = useCallback(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/control/SafetySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// componets/control/SafetySelector.tsx
"use client";

// componets/control/SafetySelector.tsx
import * as React from "react";

import {
Expand Down
1 change: 0 additions & 1 deletion src/components/control/SettingsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";

import * as React from "react";

import {
Expand Down
Loading