Further clean up in home page initial cards experience

This commit is contained in:
sabaimran
2024-12-22 18:11:19 -08:00
parent 4c4f4401b1
commit c83709fdd1
5 changed files with 27 additions and 29 deletions

View File

@@ -136,10 +136,9 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
}, [uploading]); }, [uploading]);
useEffect(() => { useEffect(() => {
if (props.prefillMessage) { if (props.prefillMessage === undefined) return;
setMessage(props.prefillMessage); setMessage(props.prefillMessage);
chatInputRef?.current?.focus(); chatInputRef?.current?.focus();
}
}, [props.prefillMessage]); }, [props.prefillMessage]);
useEffect(() => { useEffect(() => {

View File

@@ -3,7 +3,7 @@ import { Card, CardContent, CardDescription } from "@/components/ui/card";
import styles from "./suggestions.module.css"; import styles from "./suggestions.module.css";
import { convertSuggestionTitleToIconClass } from "./suggestionsData"; import { convertSuggestionTitleToIconClass } from "./suggestionsData";
import { ArrowLeft, ArrowRight, MagicWand } from "@phosphor-icons/react"; import { ArrowLeft, ArrowRight, MagicWand, XCircle } from "@phosphor-icons/react";
interface StepOneSuggestionCardProps { interface StepOneSuggestionCardProps {
title: string; title: string;
@@ -64,20 +64,20 @@ export function StepTwoSuggestionCard(data: StepTwoSuggestionCardProps) {
} }
export function StepOneSuggestionRevertCard(data: StepOneSuggestionRevertCardProps) { export function StepOneSuggestionRevertCard(data: StepOneSuggestionRevertCardProps) {
const cardClassName = `${styles.card} md:w-full md:h-fit sm:w-full h-fit md:w-fit cursor-pointer m-2 md:p-2 animate-fade-in-up border-none shadow-none`; const cardClassName = `${styles.card} md:w-full md:h-fit sm:w-full h-fit md:w-fit cursor-pointer m-2 md:p-1 animate-fade-in-up border-opacity-50 shadow-none`;
const descriptionClassName = `${styles.text} dark:text-white`; const descriptionClassName = `${styles.text} dark:text-white`;
return ( return (
<Card className={cardClassName} onClick={data.onClick}> <Card className={cardClassName} onClick={data.onClick}>
<div className="flex w-full"> <div className="flex w-full h-full items-center justify-center">
<CardContent className="m-0 p-2 w-full flex flex-row"> <CardContent className="m-0 p-2 w-full flex flex-row items-center justify-center">
<ArrowLeft className="w-6 h-6 text-muted-foreground inline-flex mr-1" />
{convertSuggestionTitleToIconClass(data.title, data.color.toLowerCase())} {convertSuggestionTitleToIconClass(data.title, data.color.toLowerCase())}
<CardDescription <CardDescription
className={`${descriptionClassName} sm:line-clamp-2 md:line-clamp-4 pt-1 break-words whitespace-pre-wrap max-w-full`} className={`${descriptionClassName} sm:line-clamp-2 md:line-clamp-4 pt-1 break-words whitespace-pre-wrap max-w-full text-center`}
> >
{data.body} {data.body}
</CardDescription> </CardDescription>
<XCircle className="w-6 h-6 text-muted-foreground inline-flex ml-1" />
</CardContent> </CardContent>
</div> </div>
</Card> </Card>

View File

@@ -440,7 +440,7 @@ export const stepTwoSuggestion: { [key: string]: StepTwoSuggestion[] } = {
prompt: "Find the main arguments in this document.", prompt: "Find the main arguments in this document.",
}, },
{ {
prompt: "Explain the relevance of this document to the topic at hand.", prompt: "Explain the relevance of this document to various other disciplines.",
}, },
], ],
}; };

View File

@@ -98,16 +98,24 @@ div.homeGreetings {
div.chatBox { div.chatBox {
padding: 0; padding: 0;
height: 100vh; height: 100%;
} }
div.chatLayout { div.chatLayout {
gap: 0; gap: 0;
grid-template-columns: 1fr; display: flex;
grid-template-rows: auto 1fr; height: 100%;
} }
div.homeGreetings { div.homeGreetings {
grid-template-rows: auto 1fr; display: flex;
flex-direction: column;
}
div.inputBox {
margin-bottom: 0;
height: fit-content;
align-items: flex-end;
margin-top: auto;
} }
} }

View File

@@ -49,7 +49,6 @@ import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/s
import { AppSidebar } from "./components/appSidebar/appSidebar"; import { AppSidebar } from "./components/appSidebar/appSidebar";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { KhojLogoType } from "./components/logo/khojLogo"; import { KhojLogoType } from "./components/logo/khojLogo";
import { Button } from "@/components/ui/button";
interface ChatBodyDataProps { interface ChatBodyDataProps {
chatOptionsData: ChatOptions | null; chatOptionsData: ChatOptions | null;
@@ -61,17 +60,9 @@ interface ChatBodyDataProps {
isLoadingUserConfig: boolean; isLoadingUserConfig: boolean;
} }
function FisherYatesShuffle(array: any[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function ChatBodyData(props: ChatBodyDataProps) { function ChatBodyData(props: ChatBodyDataProps) {
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [prefilledMessage, setPrefilledMessage] = useState(""); const [prefillMessage, setPrefillMessage] = useState("");
const [chatInputFocus, setChatInputFocus] = useState<ChatInputFocus>(ChatInputFocus.MESSAGE); const [chatInputFocus, setChatInputFocus] = useState<ChatInputFocus>(ChatInputFocus.MESSAGE);
const [images, setImages] = useState<string[]>([]); const [images, setImages] = useState<string[]>([]);
const [processingMessage, setProcessingMessage] = useState(false); const [processingMessage, setProcessingMessage] = useState(false);
@@ -156,7 +147,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
// generate colored icons for the available agents // generate colored icons for the available agents
const agentIcons = agents.map((agent) => getIconFromIconName(agent.icon, agent.color)!); const agentIcons = agents.map((agent) => getIconFromIconName(agent.icon, agent.color)!);
setAgentIcons(agentIcons); setAgentIcons(agentIcons);
}, [agentsData, props.isMobileWidth]); }, [agentsData]);
function showAllSuggestionsCards() { function showAllSuggestionsCards() {
setStepOneSuggestionOptions(stepOneSuggestions); setStepOneSuggestionOptions(stepOneSuggestions);
@@ -204,7 +195,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
}, []); }, []);
function clickStepOneSuggestion(suggestion: StepOneSuggestion) { function clickStepOneSuggestion(suggestion: StepOneSuggestion) {
setPrefilledMessage(suggestion.intent); setPrefillMessage(suggestion.intent);
const stepTwoSuggestions = getStepTwoSuggestions(suggestion.type); const stepTwoSuggestions = getStepTwoSuggestions(suggestion.type);
setSelectedStepOneSuggestion(suggestion); setSelectedStepOneSuggestion(suggestion);
setStepTwoSuggestionOptions(stepTwoSuggestions); setStepTwoSuggestionOptions(stepTwoSuggestions);
@@ -308,7 +299,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
> >
<ChatInputArea <ChatInputArea
isLoggedIn={props.isLoggedIn} isLoggedIn={props.isLoggedIn}
prefillMessage={prefilledMessage} prefillMessage={prefillMessage}
focus={chatInputFocus} focus={chatInputFocus}
sendMessage={(message) => setMessage(message)} sendMessage={(message) => setMessage(message)}
sendImage={(image) => setImages((prevImages) => [...prevImages, image])} sendImage={(image) => setImages((prevImages) => [...prevImages, image])}
@@ -367,10 +358,10 @@ function ChatBodyData(props: ChatBodyDataProps) {
body={selectedStepOneSuggestion.actionTagline} body={selectedStepOneSuggestion.actionTagline}
color={selectedStepOneSuggestion.color} color={selectedStepOneSuggestion.color}
onClick={() => { onClick={() => {
setPrefillMessage("");
setSelectedStepOneSuggestion(null); setSelectedStepOneSuggestion(null);
setStepTwoSuggestionOptions([]); setStepTwoSuggestionOptions([]);
setChatInputFocus(ChatInputFocus.MESSAGE); setChatInputFocus(ChatInputFocus.MESSAGE);
setPrefilledMessage("");
}} }}
/> />
)} )}