Skip to content

Commit

Permalink
Merge pull request #19 from technologiestiftung/feat/add-mobile-sidebar
Browse files Browse the repository at this point in the history
feat: add mobile sidebar
  • Loading branch information
raphael-arce authored Nov 6, 2023
2 parents 499bacd + 26d7163 commit ca9ea39
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { vectorSearch } from "@/lib/vector-search";
import { Collapsible, CollapsibleContent } from "@radix-ui/react-collapsible";
import { ChevronDownIcon, ChevronLeftIcon } from "@radix-ui/react-icons";
import React, { useEffect, useState } from "react";
import MobileSidebar from "@/components/MobileSidebar";
const defaultFormdata: Body = {
query: "",
};
Expand All @@ -27,14 +28,15 @@ export default function Home() {
const [errors, setErrors] = useState<Record<string, any> | null>(null);
const [sidebarisOpen, setSidebarisOpen] = useState(true);


const { resultHistory, setResultHistory } = useLocalStorage(
"ki-anfragen-history",
[],
);

useEffect(() => {
setSidebarisOpen(!isMobile);
setShowSplash(true);
// setShowSplash(true);
}, []);
useEffect(() => {
if (DEBUG) {
Expand Down Expand Up @@ -114,9 +116,16 @@ export default function Home() {
return (
<>
<SplashScreen open={showSplash} setOpen={setShowSplash} />
<div className="absolute h-screen w-full z-50">
<div className="lg:grid h-screen w-full lg:grid-cols-[280px_1fr]">
<aside className="sidebar border-r overflow-auto bg-slate-300">
<div className="absolute min-h-screen w-full z-50">
<div className="flex flex-col min-h-screen lg:grid w-full lg:grid-cols-[280px_1fr]">
<MobileSidebar
resultHistory={resultHistory}
restoreResultHistoryItem={restoreResultHistoryItem}
isHistoryOpen={sidebarisOpen}
setSidebarisOpen={setSidebarisOpen}
newRequestHandler={newRequestHandler}
/>
<aside className="hidden lg:block sidebar border-r overflow-auto bg-slate-300">
<div className="px-4 py-2">
<Button
onClick={newRequestHandler}
Expand Down Expand Up @@ -168,11 +177,10 @@ export default function Home() {
</Collapsible>
</div>
</aside>
<main className="flex flex-col justify-between bg-slate-200 py-3">
<div className="flex flex-col gap-4 p-6 flex-1 overflow-auto" />
<div className="flex flex-col px-6 py-4 space-y-4">
<main className="flex min-h-screen justify-between bg-slate-200 py-3">
<div className="flex flex-col min-h-screen justify-between px-10 py-4 space-y-4">
<div className="flex flex-col space-y-2">
<div className=" lg:w-1/2 lg:mx-auto px-3">
<div className="lg:w-1/2 lg:mx-auto px-3">
{!title && (
<h3 className="text-sm font-semibold text-zinc-900 py-3">
{
Expand Down
112 changes: 112 additions & 0 deletions src/components/MobileSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, { useState } from "react";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { Collapsible, CollapsibleContent } from "@radix-ui/react-collapsible";
import { ResponseDetail } from "@/lib/common";
import { ChevronDownIcon, ChevronLeftIcon, HamburgerMenuIcon } from "@radix-ui/react-icons";
import { XIcon } from "lucide-react";

export default function MobileSidebar(
{
resultHistory,
restoreResultHistoryItem,
isHistoryOpen,
setSidebarisOpen,
newRequestHandler
}: {
resultHistory: ResponseDetail[],
restoreResultHistoryItem: (id: string) => void,
isHistoryOpen: boolean,
setSidebarisOpen: (isOpen: boolean) => void,
newRequestHandler: (event: React.MouseEvent<HTMLButtonElement>) => void,
}) {
const [isMobileSidebarVisible, setIsMobileSidebarVisible] = useState(false);

return <>
<div className="absolute top-0 lg:hidden z-60 p-3">
<button onClick={() => setIsMobileSidebarVisible(!isMobileSidebarVisible)}>
<HamburgerMenuIcon width={20} height={20}/>
</button>
</div>

<div
className={`absolute lg:hidden top-0 left-0 w-screen h-screen bg-grey-300 bg-white bg-opacity-40 z-40 ${
isMobileSidebarVisible ? "visible" : "invisible"
}`}
style={{maxHeight: '-webkit-fill-available', maxWidth: '-webkit-fill-available'}}
>
<div
className='flex w-full h-full'
>
<div
className={`flex items-start w-80 h-full ease-in-out duration-300 ${
isMobileSidebarVisible ? "translate-x-0" : "-translate-x-80"
}`}
>
<aside className="w-80 h-full border-r overflow-auto bg-slate-300">
<div className="px-4 py-2">
<Button
onClick={newRequestHandler}
className="w-full text-white bg-blue-400 hover:bg-blue-700 font-bold py-2 px-4 rounded-none"
>
Neue Anfrage
</Button>

<Separator className="my-3" />

<div
className="flex bg-inherit rounded-none justify-between w-full items-center hover:bg-none"
onClick={() => {
setSidebarisOpen(!isHistoryOpen);
}}
>
<div className="text-slate-800">Anfrageverlauf</div>
{isHistoryOpen ? (
<ChevronDownIcon className="text-slate-800"></ChevronDownIcon>
) : (
<ChevronLeftIcon></ChevronLeftIcon>
)}
</div>

<Collapsible
open={isHistoryOpen}
onOpenChange={() => setSidebarisOpen(!isHistoryOpen)}
>
<CollapsibleContent className="p-2">
{resultHistory &&
resultHistory.map((history, i, arr) => {
return (
<React.Fragment key={history.gpt.id}>
<button
className="text-left w-full text-sm text-zinc-600 hover:text-zinc-100"
onClick={() => restoreResultHistoryItem(history.gpt.id)}
>
{history.requestBody?.query}
</button>
{i !== arr.length - 1 ? (
<Separator className="my-3" />
) : null}
</React.Fragment>
);
})}
</CollapsibleContent>
</Collapsible>
</div>
</aside>
<button
className="p-2"
onClick={() => setIsMobileSidebarVisible(false)}
>
<XIcon />
</button>
</div>
<div
className="flex w-1 grow"
onClick={() => setIsMobileSidebarVisible(false)}
>
</div>

</div>
</div>
</>
}

0 comments on commit ca9ea39

Please sign in to comment.