Skip to content

Commit

Permalink
added avatars, cleaned up styling, more baby proofing
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Lang'at <viictoo@users.noreply.github.com>
  • Loading branch information
Hasbi-sabah and viictoo committed Jul 21, 2024
1 parent 494081e commit 88e0b7a
Show file tree
Hide file tree
Showing 17 changed files with 830 additions and 261 deletions.
82 changes: 59 additions & 23 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
@layer base {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
--background: 0 0% 100%;
--foreground: 20 14.3% 4.1%;
--card: 0 0% 100%;
--card-foreground: 20 14.3% 4.1%;
--popover: 0 0% 100%;
--popover-foreground: 20 14.3% 4.1%;
--primary: 24 9.8% 10%;
--primary-foreground: 60 9.1% 97.8%;
--secondary: 60 4.8% 95.9%;
--secondary-foreground: 24 9.8% 10%;
--muted: 60 4.8% 95.9%;
--muted-foreground: 25 5.3% 44.7%;
--accent: 60 4.8% 95.9%;
--accent-foreground: 24 9.8% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 60 9.1% 97.8%;
--border: 20 5.9% 90%;
--input: 20 5.9% 90%;
--ring: 20 14.3% 4.1%;
--radius: 0.5rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
.dark {
--background: 20 14.3% 4.1%;
--foreground: 60 9.1% 97.8%;
--card: 20 14.3% 4.1%;
--card-foreground: 60 9.1% 97.8%;
--popover: 20 14.3% 4.1%;
--popover-foreground: 60 9.1% 97.8%;
--primary: 60 9.1% 97.8%;
--primary-foreground: 24 9.8% 10%;
--secondary: 12 6.5% 15.1%;
--secondary-foreground: 60 9.1% 97.8%;
--muted: 12 6.5% 15.1%;
--muted-foreground: 24 5.4% 63.9%;
--accent: 12 6.5% 15.1%;
--accent-foreground: 60 9.1% 97.8%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 60 9.1% 97.8%;
--border: 12 6.5% 15.1%;
--input: 12 6.5% 15.1%;
--ring: 24 5.7% 82.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}

@layer utilities {
.text-balance {
text-wrap: balance;
@layer base {
* {
@apply border-border dark;
}
}
body {
@apply bg-background text-foreground;
}
}
61 changes: 33 additions & 28 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default function Home() {
UUID,
"quiz_q"
));
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
alert("Something went wrong.");
return;
}
Expand Down Expand Up @@ -109,8 +109,8 @@ export default function Home() {
setFile(result);
setFileName(file.name);
setLoading(false);
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
alert("Something went wrong.");
return;
}
Expand Down Expand Up @@ -153,8 +153,8 @@ export default function Home() {
setFile(fullText);
setFileName(file.name);
setLoading(false);
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
alert("Something went wrong.");
return;
}
Expand Down Expand Up @@ -214,8 +214,8 @@ export default function Home() {
let res;
try {
res = await getStory(newFreeHistory, UUID, "free");
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
alert("Something went wrong.");
return;
}
Expand Down Expand Up @@ -244,8 +244,8 @@ export default function Home() {
let res;
try {
res = await getStory(newQuizHistory, UUID, "quiz_r", question);
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
alert("Something went wrong.");
return;
}
Expand All @@ -259,27 +259,32 @@ export default function Home() {
setLoading(false);
}
return (
<main className="flex min-h-screen flex-col items-center justify-between p-10">
<main className="flex min-h-screen flex-col p-10">
<Upload handleFileChange={handleFileChange} fileName={fileName} />
<Loading loading={loading} />
{file && (
<div>
<ModeToggle setMode={setMode} />
{mode === "free" ? (
<FreeMode
FreeHistory={FreeHistory}
prompt={prompt}
setPrompt={setPrompt}
handleSubmit={handleSubmit}
/>
) : (
<QuizMode
loading={loading}
handleQuestion={handleQuestion}
userQuizHistory={userQuizHistory}
handleResponse={handleResponse}
/>
)}
<div className="flex flex-grow flex-col h-full items-center justify-between gap-10 px-[10%]">
<div>
<ModeToggle mode={mode} setMode={setMode} />
</div>
<div className="min-w-[100%]">
{mode === "free" ? (
<FreeMode
loading={loading}
FreeHistory={FreeHistory}
prompt={prompt}
setPrompt={setPrompt}
handleSubmit={handleSubmit}
/>
) : (
<QuizMode
loading={loading}
handleQuestion={handleQuestion}
userQuizHistory={userQuizHistory}
handleResponse={handleResponse}
/>
)}
</div>
</div>
)}
</main>
Expand Down
17 changes: 17 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"baseColor": "stone",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
108 changes: 82 additions & 26 deletions components/freeMode.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,95 @@
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
interface history {
role: string;
content: string;
}

interface FreeModeProps {
FreeHistory: history[];
prompt: string;
setPrompt: (prompt: string) => void;
handleSubmit: () => void;
}
loading: boolean;
FreeHistory: history[];
prompt: string;
setPrompt: (prompt: string) => void;
handleSubmit: () => void;
}

export default function FreeMode({FreeHistory, prompt, setPrompt, handleSubmit}: FreeModeProps) {
export default function FreeMode({
loading,
FreeHistory,
prompt,
setPrompt,
handleSubmit,
}: FreeModeProps) {
return (
<>
<p>file loaded successfully! Ask the document questions:</p>
<div className="flex flex-col w-full px-10 items-center">
<p>Ask the document questions:</p>
{FreeHistory.slice(1).length > 0 &&
FreeHistory.slice(1).map((msg: history, index: number) => (
<h1 key={index}>
{msg.role}: {msg.content}
</h1>
<div className={`flex items-center gap-3 ${
msg.role === "user" ? "self-end" : "self-start"
}`}>
{msg.role !== "user" && (
<Avatar>
<AvatarImage src="/aillama.jpg" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
)}
<Card
key={index}
className={`border-none `}
>
<CardHeader className="p-2">
<CardTitle
className={`text-sm ${
msg.role === "user" ? "self-end" : "self-start"
}`}
>
{msg.role}
</CardTitle>
</CardHeader>
<CardContent className="pb-2">
<p>{msg.content}</p>
</CardContent>
</Card>
{msg.role === "user" && (
<Avatar>
<AvatarImage src="/llamaUser.jpg" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
)}
</div>
))}
<input
className="text-black w-full"
type="text"
value={prompt}
onKeyDown={(event) => {
if (event.key === "Enter") {
handleSubmit();
}
}}
onChange={(event) => {
setPrompt(event.target.value);
}}
/>
<button onClick={handleSubmit}>Submit</button>
</>
<div className="flex w-full items-center space-x-2 pt-3">
<Input
className="w-full"
value={prompt}
type="text"
onKeyDown={(event) => {
if (event.key === "Enter" && prompt.trim() !== "" && !loading) {
handleSubmit();
}
}}
onChange={(event) => {
setPrompt(event.target.value);
}}
placeholder="Enter a prompt"
/>
<Button
disabled={loading || prompt.trim() === ""}
onClick={handleSubmit}
>
Submit
</Button>
</div>
</div>
);
}
50 changes: 30 additions & 20 deletions components/modeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
export default function ModeToggle({setMode}: {setMode: (mode: string) => void}) {
return (
<div className="flex">
<button
onClick={() => {
setMode("free");
}}
>
Free interact
</button>
<button
onClick={() => {
setMode("quiz");
}}
>
Quiz mode
</button>
</div>
)
}
import { Button } from "./ui/button";

export default function ModeToggle({
mode,
setMode,
}: {
mode: string;
setMode: (mode: string) => void;
}) {
return (
<div className="flex gap-5">
<Button
variant={mode === "free" ? "default" : "secondary"}
onClick={() => {
setMode("free");
}}
>
Free interaction Mode
</Button>
<Button
variant={mode !== "free" ? "default" : "secondary"}
onClick={() => {
setMode("quiz");
}}
>
Quiz Mode
</Button>
</div>
);
}
Loading

0 comments on commit 88e0b7a

Please sign in to comment.