From 31cc5ecdb693be1da04ee0a3e6dc876535d5fb4b Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 23 Apr 2023 13:12:25 -0600 Subject: AƱade loader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/api_client.ts | 5 +++-- src/clients/loader.ts | 8 ++++++++ src/components/layout.tsx | 2 +- src/components/main_content_layout.tsx | 12 ++++++++++++ src/components/search_bar.tsx | 9 +++++---- src/components/stylesheets/search_bar.css | 3 +++ src/components/stylesheets/searchbar.css | 3 --- src/components/stylesheets/shared.css | 9 +++++++++ src/main.tsx | 4 ++++ src/routes/products/products.tsx | 9 ++++++++- 10 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/clients/loader.ts create mode 100644 src/components/main_content_layout.tsx create mode 100644 src/components/stylesheets/search_bar.css delete mode 100644 src/components/stylesheets/searchbar.css diff --git a/src/clients/api_client.ts b/src/clients/api_client.ts index f2bcd35..a7b5e0d 100644 --- a/src/clients/api_client.ts +++ b/src/clients/api_client.ts @@ -1,16 +1,17 @@ import axios from "axios"; export class ApiClient { - readonly url = "http://localhost:5000/api"; + readonly url = "http://localhost:3000/api"; async get(path: string) { const request_url = `${ this.url }${ path }`; try { const response = await axios.get(request_url); + return response; } catch(error) { - console.log(error); + return error.response; } } } \ No newline at end of file diff --git a/src/clients/loader.ts b/src/clients/loader.ts new file mode 100644 index 0000000..645ba88 --- /dev/null +++ b/src/clients/loader.ts @@ -0,0 +1,8 @@ +import { ApiClient } from "./api_client"; + +export default async function loader(path: string, { params }) { + const client = new ApiClient(); + const response = await client.get(path); + + return response.data; +} \ No newline at end of file diff --git a/src/components/layout.tsx b/src/components/layout.tsx index 4988ecc..742ad0e 100644 --- a/src/components/layout.tsx +++ b/src/components/layout.tsx @@ -2,7 +2,7 @@ import { ReactNode } from "react"; import Navbar from "./navbar"; import "./stylesheets/shared.css" -interface Props { +export interface Props { children: ReactNode; } diff --git a/src/components/main_content_layout.tsx b/src/components/main_content_layout.tsx new file mode 100644 index 0000000..0b55d6a --- /dev/null +++ b/src/components/main_content_layout.tsx @@ -0,0 +1,12 @@ +import "./stylesheets/shared.css" +import { Props } from "./layout"; + +export default function MainContentLayout(props: Props ) { + return( + <> +
+ { props.children } +
+ + ); +} \ No newline at end of file diff --git a/src/components/search_bar.tsx b/src/components/search_bar.tsx index 5f1f438..a33bcca 100644 --- a/src/components/search_bar.tsx +++ b/src/components/search_bar.tsx @@ -1,18 +1,19 @@ -import "./stylesheets/searchbar.css" +import "./stylesheets/shared.css" +import "./stylesheets/search_bar.css" export default function SearchBar({ path }) { return(
-
-
+
+