diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index ab3825896..4b13dd1d8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -28,7 +28,11 @@ public function run(): void DB::table('categories')->insert([ 'name' => 'Unlocked Labs', 'rank' => '1', - 'links' => '["http://www.unlockedlabs.org/"]', + 'links' => ' + [ + {"Unlocked Labs Website":"http://www.unlockedlabs.org/"}, + {"Unlocked Labs LinkedIn":"https://www.linkedin.com/company/labs-unlocked/"} + ]', ]); } } diff --git a/resources/js/Components/LeftMenu.tsx b/resources/js/Components/LeftMenu.tsx index 87921326d..33fe7ce0b 100644 --- a/resources/js/Components/LeftMenu.tsx +++ b/resources/js/Components/LeftMenu.tsx @@ -1,11 +1,59 @@ +import axios from "axios"; import Brand from "./Brand"; import { HomeIcon, ArchiveBoxIcon, BookOpenIcon, } from "@heroicons/react/24/solid"; +import useSWR from "swr"; +import { Category, CategoryLink } from "@/common"; + +function CategoryItem({ categoryName, linksArray, rank }: Category) { + const linksList = linksArray.map((linkPair: { [x: string]: string }) => { + const key = Object.keys(linkPair)[0]; + return ( +
  • + {key} +
  • + ); + }); + return ( +
  • +
    + + + {categoryName} + + +
    +
  • + ); +} + +function getCategoryItems( + data: { data: { name: string; rank: number; links: CategoryLink[] }[] }, + error: any, + isLoading: boolean, +) { + if (error) return
    failed to load
    ; + if (isLoading) return
    loading...
    ; + return data.data.map((category) => { + return ( + + ); + }); +} export default function LeftMenu() { + const { data, error, isLoading } = useSWR("/api/v1/categories"); + + const categoryItems = getCategoryItems(data, error, isLoading); + return ( ); } diff --git a/resources/js/common.ts b/resources/js/common.ts index 6b7d40ae1..bf03c411a 100644 --- a/resources/js/common.ts +++ b/resources/js/common.ts @@ -11,3 +11,13 @@ export interface User { role: string; email: string; } + +export interface Category { + categoryName: string; + linksArray: Array; + rank: number; +} + +export interface CategoryLink { + [linkName: string]: string; +}