Skip to content

Commit

Permalink
Improve home
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-janon committed Jul 30, 2024
1 parent d327a37 commit 0599bb1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/components/Cmdk/components/Cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export const Cmdk: React.FC<CmdkProps> = ({ isOpen, setIsCmdkOpen }) => {
setIsCmdkOpen={setIsCmdkOpen}
/>
)}
{activePage === "chat" && <CmdkChat />}
{activePage === "chat" && <CmdkChat initialValue={inputValue} setCmdkInputValue={setInputValue} />}
</Command.List>
</Command>
</DialogContent>
Expand All @@ -318,6 +318,7 @@ function Home({
onSelect={() => {
goToChat();
}}
value={inputValue}
>
<FeedbackIcon />
Chat with the docs
Expand All @@ -341,7 +342,7 @@ function Home({
router.push("/");
}}
>
<HomeIcon sx={{ strokeWidth: 0.2 }} />
<HomeIcon className="dark:text-grey-300" sx={{ strokeWidth: 0.2 }} />
Go to "Home" section
</Item>
<Item
Expand Down Expand Up @@ -383,13 +384,15 @@ function Item({
children,
shortcut,
onSelect = () => {},
value,
}: {
children: React.ReactNode;
shortcut?: string;
onSelect?: (value: string) => void;
value?: string;
}) {
return (
<Command.Item onSelect={onSelect}>
<Command.Item onSelect={onSelect} value={value} itemType="command">
{children}
{shortcut && (
<div cmdk-zeta-shortcuts="">
Expand Down
19 changes: 15 additions & 4 deletions src/components/Cmdk/components/CmdkChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TextField } from "@mui/material";
import twTheme from "@zetachain/ui-toolkit/theme/tailwind.theme.json";
import { useChat } from "ai/react";
import clsx from "clsx";
import React from "react";
import React, { useEffect } from "react";

const CustomTextField = styled(TextField)(({ theme }) => ({
"& .MuiOutlinedInput-root": {
Expand Down Expand Up @@ -80,11 +80,18 @@ const AssistantMessage: React.FC<{ children: React.ReactNode; messageClasses?: s
);
};

export const CmdkChat: React.FC<CmdkChatProps> = ({ ...props }) => {
export const CmdkChat: React.FC<CmdkChatProps> = ({ initialValue, setCmdkInputValue }) => {
const { messages, append, handleSubmit, input, handleInputChange, error, isLoading, setInput } = useChat({});

const isLoadingAssistantMessage = isLoading;

useEffect(() => {
if (initialValue && input.length === 0) {
setInput(initialValue);
setCmdkInputValue("");
}
}, [initialValue, input]);

return (
<div className="w-full" onClick={(e) => e.stopPropagation()}>
<div className={clsx("relative py-4")}>
Expand Down Expand Up @@ -140,14 +147,15 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ ...props }) => {
<LoadingDots className="mb-1" />
</AssistantMessage>
)}
{messages.length === 0 && (
{messages.length === 0 && input.length === 0 && (
<Command.Group className="w-full" heading="Example questions">
{cmdkChatQuestions.map((question) => {
const key = question.replace(/\s+/g, "_");

return (
<Command.Item
key={key}
value={question}
className={clsx("cursor-pointer", "w-full")}
onSelect={() => {
append({ role: "user", content: question });
Expand Down Expand Up @@ -213,4 +221,7 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ ...props }) => {
);
};

interface CmdkChatProps {}
interface CmdkChatProps {
initialValue: string;
setCmdkInputValue: Function;
}

0 comments on commit 0599bb1

Please sign in to comment.