diff --git "a/v\303\246r/src/App.tsx" "b/v\303\246r/src/App.tsx" index 8ef557e..4da300d 100644 --- "a/v\303\246r/src/App.tsx" +++ "b/v\303\246r/src/App.tsx" @@ -3,121 +3,17 @@ import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' import './App.css' +import ViewCity from './components/ViewCity' import useGetWeather from './hooks/fetchWeather/useGetWeather' function App() { const [count, setCount] = useState(0) - // Example fetch, plz remove asap - const { result } = useGetWeather(67, 67, 420) return ( <>
-
- - React logo - Vite logo -
-
- {JSON.stringify(result)} -

Get started

-

- Edit src/App.tsx and save to test HMR -

-
- -
- -
- -
-
- -

Documentation

-

Your questions, answered

- -
-
- -

Connect with us

-

Join the Vite community

- -
-
- -
+ +
) diff --git "a/v\303\246r/src/components/ViewCity.tsx" "b/v\303\246r/src/components/ViewCity.tsx" new file mode 100644 index 0000000..7a2c13a --- /dev/null +++ "b/v\303\246r/src/components/ViewCity.tsx" @@ -0,0 +1,32 @@ +import useGetWeather from "../hooks/fetchWeather/useGetWeather"; +import useGetCityCoordinates from "../hooks/useGetCityCoordinates"; + +interface ViewCityProp { + city: string +} + +export default function ViewCity(arg: ViewCityProp){ + + const data = useGetCityCoordinates(arg.city); + + const {isLoading, error, result} = useGetWeather(data.result[0]?.latitude, data.result[0]?.longitude); + + if(isLoading){ + return

Laster

; + } + if(error){ + + return

Det skjedde en feil

+ } + const firstTimeStep = result?.properties.timeseries[0]; + const windSpeed = firstTimeStep?.data.instant.details?.wind_speed; + const temperature = firstTimeStep?.data.instant.details?.air_temperature; + + return ( +
+
Været i {arg.city}
+

Temperatur: {temperature}

+

Vindhastighet: {windSpeed}

+
+ ); +} \ No newline at end of file diff --git "a/v\303\246r/src/hooks/useGetCityCoordinates.ts" "b/v\303\246r/src/hooks/useGetCityCoordinates.ts" index f5a9003..7397f5f 100644 --- "a/v\303\246r/src/hooks/useGetCityCoordinates.ts" +++ "b/v\303\246r/src/hooks/useGetCityCoordinates.ts" @@ -1,7 +1,7 @@ import { useQuery } from "@tanstack/react-query" export type citySearchResult = { - result: { + results: { name: string, latitude: number, longitude: number @@ -16,7 +16,7 @@ const useGetCityCoordinates = (cityName: string) => { queryFn: () => fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${cityName}`).then((res) => res.json() as Promise) }) - const result = data?.result ?? [] + const result = data?.results ?? [] return { isLoading, error, result } } diff --git "a/v\303\246r/src/main.tsx" "b/v\303\246r/src/main.tsx" index 34913a4..accea2b 100644 --- "a/v\303\246r/src/main.tsx" +++ "b/v\303\246r/src/main.tsx" @@ -2,6 +2,7 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' import './index.css' import App from './App.tsx' +import ViewCity from './components/ViewCity.tsx' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' @@ -11,7 +12,7 @@ const queryClient = new QueryClient() createRoot(document.getElementById('root')!).render( - + , )