add context and fix sidebar

This commit is contained in:
Yash 2024-04-05 08:33:09 +00:00
parent 97988798bd
commit 4faf6bd82a
4 changed files with 15 additions and 21 deletions

View file

@ -4,11 +4,11 @@ import Sidebar from "@/components/Sidebar/index";
import { useState } from "react";
export default function Content() {
const [selectedItem, setSelectedItem] = useState<string | null>();
const [selectedItem, setSelectedItem] = useState<string | null>(null);
return (
<div className="flex w-screen">
{/* <Sidebar selectChange={setSelectedItem} /> */}
<Sidebar selectChange={setSelectedItem} />
<Main sidebarOpen={selectedItem !== null} />
</div>
);

View file

@ -1,18 +1,10 @@
import Main from "@/components/Main";
import Sidebar from "@/components/Sidebar/index";
import { cookies } from "next/headers";
import { MemoryProvider } from "@/contexts/MemoryContext";
import Content from "./content";
export default function Home() {
const selectedItem = cookies().get("selectedItem")?.value;
const setSelectedItem = async (selectedItem: string | null) => {
"use server";
cookies().set("selectedItem", selectedItem!);
};
return (
<div className="flex w-screen">
{/* <Sidebar selectChange={setSelectedItem} spaces={spaces} /> */}
<Main sidebarOpen={selectedItem !== null} />
</div>
<MemoryProvider spaces={[]}>
<Content />
</MemoryProvider>
);
}

View file

@ -7,6 +7,7 @@ import { MemoriesBar } from "./MemoriesBar";
import { AnimatePresence, motion } from "framer-motion";
import { Bin } from "@/assets/Bin";
import { CollectedSpaces } from "../../../types/memory";
import { useMemory } from "@/contexts/MemoryContext";
export type MenuItem = {
icon: React.ReactNode | React.ReactNode[];
@ -27,11 +28,11 @@ const menuItemsBottom: Array<MenuItem> = [
export default function Sidebar({
selectChange,
spaces,
}: {
selectChange?: (selectedItem: string | null) => Promise<void>;
spaces: CollectedSpaces[];
selectChange?: (selectedItem: string | null) => void;
}) {
const { spaces } = useMemory();
const menuItemsTop: Array<MenuItem> = [
{
icon: <MemoryIcon className="h-10 w-10" />,

View file

@ -1,15 +1,16 @@
"use client";
import React from "react";
import { Space } from "../../types/memory";
import { CollectedSpaces } from "../../types/memory";
// temperory (will change)
export const MemoryContext = React.createContext<{
spaces: Space[];
spaces: CollectedSpaces[];
}>({
spaces: [],
});
export const MemoryProvider: React.FC<
{ spaces: Space[] } & React.PropsWithChildren
{ spaces: CollectedSpaces[] } & React.PropsWithChildren
> = ({ children, spaces }) => {
return (
<MemoryContext.Provider value={{ spaces }}>