mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-20 10:30:16 -04:00
initial commit
This commit is contained in:
parent
f9abc9169f
commit
5c604e2a5a
|
@ -20,6 +20,10 @@ export default function Page() {
|
||||||
const [loginError, setLoginError] = useState("");
|
const [loginError, setLoginError] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("here");
|
||||||
|
},[])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const supabase = createClient();
|
const supabase = createClient();
|
||||||
async function checkUser() {
|
async function checkUser() {
|
||||||
|
|
92
compass/app/resource_test/layout.tsx
Normal file
92
compass/app/resource_test/layout.tsx
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import Sidebar from "@/components/Sidebar/Sidebar";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
|
||||||
|
import { createClient } from "@/utils/supabase/client";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import User, { Role } from "@/utils/models/User";
|
||||||
|
import Loading from "@/components/auth/Loading";
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
const [user, setUser] = useState<User>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function getUser() {
|
||||||
|
const supabase = createClient();
|
||||||
|
|
||||||
|
const { data, error } = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
console.log(data, error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.log("Accessed resource page but not logged in");
|
||||||
|
router.push("/auth/login");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userData = await fetch(
|
||||||
|
`${process.env.NEXT_PUBLIC_HOST}/api/user?uuid=${data.user.id}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const user: User = await userData.json();
|
||||||
|
|
||||||
|
setUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
getUser();
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-row">
|
||||||
|
{user ? (
|
||||||
|
<div>
|
||||||
|
{/* button to open sidebar */}
|
||||||
|
<button
|
||||||
|
onClick={() => setIsSidebarOpen(!isSidebarOpen)}
|
||||||
|
className={`fixed z-20 p-2 text-gray-500 hover:text-gray-800 left-0`}
|
||||||
|
aria-label={"Open sidebar"}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
!isSidebarOpen && (
|
||||||
|
<ChevronDoubleRightIcon className="h-5 w-5" />
|
||||||
|
) // Icon for closing the sidebar
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
{/* sidebar */}
|
||||||
|
<div
|
||||||
|
className={`absolute inset-y-0 left-0 transform ${
|
||||||
|
isSidebarOpen
|
||||||
|
? "translate-x-0"
|
||||||
|
: "-translate-x-full"
|
||||||
|
} w-64 transition duration-300 ease-in-out`}
|
||||||
|
>
|
||||||
|
<Sidebar
|
||||||
|
setIsSidebarOpen={setIsSidebarOpen}
|
||||||
|
name={user.username}
|
||||||
|
email={user.email}
|
||||||
|
isAdmin={user.role === Role.ADMIN}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* page ui */}
|
||||||
|
<div
|
||||||
|
className={`flex-1 transition duration-300 ease-in-out ${
|
||||||
|
isSidebarOpen ? "ml-64" : "ml-0"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Loading />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
49
compass/app/resource_test/page.tsx
Normal file
49
compass/app/resource_test/page.tsx
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { PageLayout } from "@/components/PageLayout";
|
||||||
|
import { ResourceTable } from "@/components/Table/ResourceIndex";
|
||||||
|
import Resource from "@/utils/models/Resource";
|
||||||
|
import { createClient } from "@/utils/supabase/client";
|
||||||
|
|
||||||
|
import { BookmarkIcon } from "@heroicons/react/24/solid";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
const [resources, setResources] = useState<Resource[]>([]);
|
||||||
|
console.log("hello");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function getResources() {
|
||||||
|
const supabase = createClient();
|
||||||
|
|
||||||
|
const { data, error } = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
console.log(data, error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.log("Accessed admin page but not logged in");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userListData = await fetch(
|
||||||
|
`${process.env.NEXT_PUBLIC_HOST}/api/resource/all?uuid=${data.user.id}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const resourcesAPI: Resource[] = await userListData.json();
|
||||||
|
|
||||||
|
setResources(resourcesAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getResources();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex flex-col">
|
||||||
|
{/* icon + title */}
|
||||||
|
<PageLayout title="Resources" icon={<BookmarkIcon />}>
|
||||||
|
<ResourceTable users={resources} />
|
||||||
|
</PageLayout>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
7840
compass/package-lock.json
generated
7840
compass/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user