diff --git a/src/App.tsx b/src/App.tsx index ffccfeb0..6b20aad5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import './App.css' import Concept from './pages/Concept' import { userApi } from './api/userApi' import Projects from './pages/Projects' +import { ProjectView } from './pages/ProjectView' @@ -26,6 +27,7 @@ function App() { } /> } /> } /> + } /> } /> } /> diff --git a/src/api/directus.ts b/src/api/directus.ts index 84aaa0c5..1d63f44c 100644 --- a/src/api/directus.ts +++ b/src/api/directus.ts @@ -16,6 +16,7 @@ export type Place = { text: string; position?: Point; picture: string; + subname: string; }; export type Tag = { diff --git a/src/api/itemsApi.ts b/src/api/itemsApi.ts index 407c726b..c6a10770 100644 --- a/src/api/itemsApi.ts +++ b/src/api/itemsApi.ts @@ -1,4 +1,4 @@ -import { createItem, deleteItem, readItems, updateItem } from '@directus/sdk'; +import { createItem, deleteItem, readItem, readItems, updateItem } from '@directus/sdk'; import { MyCollections, directusClient } from './directus'; import { ItemsApi } from 'utopia-ui/dist/types'; @@ -23,6 +23,17 @@ export class itemsApi implements ItemsApi{ } } + async getItem(id : string) { + try { + return await directusClient.request(readItem(this.collectionName as never, id)); + } catch (error: any) { + console.log(error); + if (error.errors[0]?.message) + throw error.errors[0].message; + else throw error; + } + } + async createItem(item: T & { id?: string }) { try { return await directusClient.request(createItem(this.collectionName as keyof MyCollections, item)) diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx new file mode 100644 index 00000000..1bb79755 --- /dev/null +++ b/src/pages/ProjectView.tsx @@ -0,0 +1,37 @@ +import { useState, useEffect } from "react"; +import { itemsApi } from "../api/itemsApi"; +import { Project } from '../api/directus' +import { useLocation } from "react-router-dom"; +import { CardPage } from "utopia-ui/src/Components/Templates/CardPage"; + +export const ProjectView = () => { + + const [projectsApi, setProjectsApi] = useState>(); + const [project, setProject] = useState(); + + let location = useLocation(); + + + const loadProject = async () => { + const project : unknown = await projectsApi?.getItem(location.pathname.split("/")[2]); + setProject(project as Project); + + } + + useEffect(() => { + setProjectsApi(new itemsApi('projects')); + }, []) + + useEffect(() => { + loadProject(); + }, [projectsApi]) + + return ( + + +

{project?.subname}

+ +

{project?.text}

+
+ ) +} diff --git a/src/pages/Projects.tsx b/src/pages/Projects.tsx index d0e94881..07a9235b 100644 --- a/src/pages/Projects.tsx +++ b/src/pages/Projects.tsx @@ -1,6 +1,3 @@ -import UsersIcon from '@heroicons/react/24/outline/UsersIcon' -import MapPinIcon from '@heroicons/react/24/outline/MapPinIcon' -import CalendarIcon from '@heroicons/react/24/outline/CalendarIcon' import { TextInput, TitleCard, SelectBox, useAuth } from 'utopia-ui' import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' @@ -61,9 +58,10 @@ const {token,isAuthenticated} = useAuth(); return ( -

{i.subname}

- {i.text} +

{i.subname}

+ +

{i.text}

{/** *
 2
diff --git a/src/routes/sidebar.tsx b/src/routes/sidebar.tsx index 2e2bedbc..5ad79dde 100644 --- a/src/routes/sidebar.tsx +++ b/src/routes/sidebar.tsx @@ -1,5 +1,5 @@ -import { BookOpenIcon, RectangleGroupIcon, UsersIcon, MapIcon } from '@heroicons/react/24/outline' +import { BookOpenIcon, RectangleGroupIcon, MapIcon } from '@heroicons/react/24/outline' //const iconClasses = `h-6 w-6` //const submenuIconClasses = `h-5 w-5`