From 6180b516c90124bc2f89a07d57f6cc324e8926bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kratochv=C3=ADl?= <xkrato10@fi.muni.cz>
Date: Fri, 24 Jun 2022 11:31:05 +0200
Subject: [PATCH] feat: SearchPage - fetching directors from the API

---
 frontend/src/components/SearchPage.tsx | 50 ++++----------------------
 1 file changed, 7 insertions(+), 43 deletions(-)

diff --git a/frontend/src/components/SearchPage.tsx b/frontend/src/components/SearchPage.tsx
index dd869d9..51f56d5 100644
--- a/frontend/src/components/SearchPage.tsx
+++ b/frontend/src/components/SearchPage.tsx
@@ -59,46 +59,6 @@ const resultsExample: MovieIO[] = [
   },
 ];
 
-//replace with api call only once
-const directorsList: DirectorIO[] = [
-  {
-    name: "Karel1",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1561",
-  },
-  {
-    name: "Karel2",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1562",
-  },
-  {
-    name: "Karel3",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1563",
-  },
-  {
-    name: "Karel4",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1564",
-  },
-  {
-    name: "Karel5",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1565",
-  },
-  {
-    name: "Karel6",
-    surname: "Vomacka",
-    birthDate: "17.5.1979",
-    id: "1566",
-  },
-];
-
 const runtimeMarks = {
   0: "0",
   30: "30",
@@ -130,12 +90,16 @@ export const SearchPage = () => {
   const [form] = Form.useForm();
 
   const [categories, setCategories] = useState<CategoryIO[]>([]);
+  const [directors, setDirectors] = useState<DirectorIO[]>([]);
 
   useEffect(() => {
     const fetchData = async () => {
       try {
         const response = await axiosConfig.get<CategoryIO[]>('/categories');
         setCategories([ ...response.data ]);
+
+        const dirResponse = await axiosConfig.get<DirectorIO[]>('/directors');
+        setDirectors([ ...dirResponse.data ]);
       } catch {
 
       }
@@ -346,10 +310,10 @@ export const SearchPage = () => {
                     )
                 }
               >
-                {directorsList.map((dir: DirectorIO) => {
+                {directors.map((director: DirectorIO) => {
                   return (
-                    <Option value={dir.id}>
-                      {dir.name + " " + dir.surname}
+                    <Option value={director.id}>
+                      {director.name + " " + director.surname}
                     </Option>
                   );
                 })}
-- 
GitLab