diff --git a/frontend/src/components/CardsContainer.tsx b/frontend/src/components/CardsContainer.tsx index 47dc6d6..af14061 100644 --- a/frontend/src/components/CardsContainer.tsx +++ b/frontend/src/components/CardsContainer.tsx @@ -1,68 +1,72 @@ -import FeilCard from "./FeilCard" -import { backendURL } from "../const.ts" +import FeilCard from "./FeilCard"; +import { backendURL } from "../const.ts"; import { Feilmelding } from "../interface.ts"; +import { useState } from "react"; /** - * - * @returns Komponent for returnering av konteiner med alle feilinnmeldingene. + * + * @returns Komponent for returnering av konteiner med alle feilinnmeldingene. */ // const fetcher = (url: RequestInfo | URL) => fetch(url).then(r => r.json()) +// const test = async () => { +// const response = await fetch(backendURL + "/api/hentallefeil") +// const data = await response.json() // data er Promise +// return data.then({ -async function fetchAlleFeil() { +// }) +// } + +const CardsContainer = () => { + const [test, setTest] = useState([]); + + async function fetchAlleFeil() { // const {data, error, isLoading } = useSWR("/api/hentallefeil", fetcher) // if (error) return
fail
// if (isLoading) return
loader
// return
hello {data.data}!
- try { - const response = await fetch(backendURL + "/api/hentallefeil", { - method: "GET", - headers: { - "Content-Type": "application/json" - }, - }) - .then((data) => data.json()) - .then((feil) => { - return feil.map((jsonFeilmelding: any) => new Feilmelding(jsonFeilmelding)) - }) - .catch((error) => { - console.log(error) - }) - return response - } catch (error) { - console.log("error:", error); - } -} + const response = await fetch(backendURL + "/api/hentallefeil", { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }) + .then((data) => data.json()) + .then((feil) => { + setTest( + feil.map((jsonFeilmelding: any) => new Feilmelding(jsonFeilmelding)) + ); + }) + .catch((error) => { + console.log(error); + }); + return response; + } +// fetchAlleFeil(); -const printFeil = async () => { - const a = await fetchAlleFeil(); - console.log("a:", a); + const feilMeldinger: Feilmelding[] = test; + + // console.log(test()) + + return ( +
+
+ {feilMeldinger.map((feilMelding) => ( + + ))} +
+
+
+

Forsøker å loade feil objekter her:

+
+
+ ); }; - -const CardsContainer = () => { - - const feilMeldinger: Feilmelding[] = [] - printFeil() - - return( -
-
- {feilMeldinger.map((feilMelding) => ( - - ))} -
-
-
-

Forsøker å loade feil objekter her:

-
-
- - ) -} -export default CardsContainer \ No newline at end of file +export default CardsContainer; diff --git a/frontend/src/const.ts b/frontend/src/const.ts index aeec6f6..64d30ed 100644 --- a/frontend/src/const.ts +++ b/frontend/src/const.ts @@ -1,3 +1,3 @@ -export const backendURL = "http://localhost:8080" -// const backend = "https://helse-sprik.intern.dev.nav.no" +// export const backendURL = "http://localhost:8080" +export const backend = "https://helse-sprik.intern.dev.nav.no"