Skip to content

Commit

Permalink
interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
benhalverson committed Sep 4, 2024
1 parent dea46e4 commit e2da221
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/interfaces/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* The response for the /colors endpoint
*/
export interface ColorsResponse {
filaments: Filament[];
}

export interface Filament {
filament: string;
hexColor: string;
colorTag: string;
profile: string;
}
2 changes: 2 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './colors';
export * from './productResponse';
6 changes: 6 additions & 0 deletions src/interfaces/productResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**The response for the /list of products */
export interface ProductResponse {
size: string;
stl: string;
version: string;
}
15 changes: 14 additions & 1 deletion src/pages/Product.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { lazy, Suspense, useState } from "react";
/* eslint-disable react-hooks/exhaustive-deps */
import { lazy, Suspense, useEffect, useState } from "react";
import {
Radio,
RadioGroup,
Expand All @@ -7,6 +8,7 @@ import {
ShoppingBagIcon,
UserIcon,
} from "@heroicons/react/24/outline";
import { ColorsResponse } from '../interfaces';
const PreviewComponent = lazy(() => import("../components/PreviewComponent"));

const product = {
Expand Down Expand Up @@ -35,7 +37,18 @@ function classNames(...classes: string[]) {

export default function ProductPage() {
const [selectedColor, setSelectedColor] = useState(product.colors[0]);
const [colors, setColors] = useState<ColorsResponse[]>([]);

const getColors = async () => {
const response = await fetch("https://3dprinter-web-api.benhalverson.workers.dev/colors");
const data = await response.json() as ColorsResponse[];
setColors(data)
console.log(colors);
};

useEffect(() => {
getColors();
}, []);
return (
<div className="bg-white">
<header className="relative bg-white">
Expand Down
8 changes: 1 addition & 7 deletions src/pages/ProductList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useState } from "react";
import { ProductResponse } from '../interfaces';

const BASE_URL = "https://3dprinter-web-api.benhalverson.workers.dev/list";

Expand All @@ -12,8 +13,6 @@ function ProductList() {
const data = (await response.json()) as ProductResponse[];

setProducts(data);
console.log("products", products);
console.log("typeof", typeof products);
return data;
} catch (error) {
console.error("error", error);
Expand All @@ -34,8 +33,3 @@ function ProductList() {

export default ProductList;

interface ProductResponse {
size: string;
stl: string;
version: string;
}

0 comments on commit e2da221

Please sign in to comment.