diff --git a/app/globals.css b/app/globals.css
index 9c42d5f..c8c52d4 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -76,4 +76,6 @@
body {
@apply bg-background text-foreground;
}
-}
\ No newline at end of file
+}
+
+@import url(./index.css);
\ No newline at end of file
diff --git a/app/index.css b/app/index.css
new file mode 100644
index 0000000..7e8fdc5
--- /dev/null
+++ b/app/index.css
@@ -0,0 +1 @@
+@import url(../fonts/weather-icons.min.css);
\ No newline at end of file
diff --git a/app/layout.tsx b/app/layout.tsx
index 0fd92b0..f40799b 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -30,7 +30,9 @@ export default function RootLayout({
- {children}
+
+ {children}
+
diff --git a/app/page.tsx b/app/page.tsx
index aeed5de..080c020 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -1,4 +1,9 @@
+import City from '@/components/screen/City'
+import Current from '@/components/screen/Current'
+import CurrentDetail from '@/components/screen/CurrentDetail'
import NavBar from '@/components/screen/NavBar'
+import { getLocation, getWeather } from '@/lib/api'
+import { Suspense } from 'react'
export type Params = {
lat?: `${number}`
@@ -13,12 +18,36 @@ type PageProps = {
searchParams?: Params
}
-export default function Page(props: PageProps) {
+export default async function Page(props: PageProps) {
const { lat, lon, city, country, units } = props.searchParams as Params
+ const weatherPromise = getWeather(lat, lon)
+ const locationPromise = getLocation(lat, lon, city, country)
+ const weather = await weatherPromise
+ const timezone =
+ weather?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone
+
return (
<>
-
+
+ {weather?.error ? (
+
+ Error: {weather?.error || 'Something went wrong'}
+
+ ) : (
+ <>
+ Loading...}>
+
+
+
+
+
{JSON.stringify(weather, null, 2)}
+ >
+ )}
>
)
}
diff --git a/components/atom/toggle-units.tsx b/components/atom/toggle-units.tsx
new file mode 100644
index 0000000..6893010
--- /dev/null
+++ b/components/atom/toggle-units.tsx
@@ -0,0 +1,52 @@
+'use client'
+
+import { useRouter, useSearchParams } from 'next/navigation'
+import { Button } from '../ui/button'
+import { Params } from '@/app/page'
+
+type Queries = {
+ key: string
+ value: string
+}
+
+export default function ToggleUnits({ units }: { units: Params['units'] }) {
+ const router = useRouter()
+ const query = useSearchParams()
+ const params = query?.entries()
+ const queries: Queries[] = []
+
+ if (!params)
+ for (const [key, value] of params as any) {
+ queries.push({ key, value })
+ }
+
+ const hasUnits = queries.some((query) => query.key === 'units')
+
+ return (
+
+ )
+}
diff --git a/components/atom/use-gps.tsx b/components/atom/use-gps.tsx
new file mode 100644
index 0000000..fe2f35c
--- /dev/null
+++ b/components/atom/use-gps.tsx
@@ -0,0 +1,56 @@
+'use client'
+
+import React, { useCallback, useEffect, useRef } from 'react'
+import { Button } from '../ui/button'
+import { Icons } from '../ui/icons'
+import { useRouter } from 'next/navigation'
+import { LucideIcon } from 'lucide-react'
+
+export default function GetGPS() {
+ const router = useRouter()
+ const icon = useRef(Icons.gps) // using a ref to change the icon so that the data comes in html from server
+
+ const success = useCallback(
+ async (position: GeolocationPosition) => {
+ const { latitude, longitude } = position.coords
+
+ localStorage.setItem('gps-granted', String(true))
+ icon.current = Icons.gpsFixed
+ router.replace(`/?lat=${latitude}&lon=${longitude}`)
+ console.log('success')
+ },
+ [router]
+ )
+
+ function onError() {
+ localStorage.removeItem('gps-granted')
+ icon.current = Icons.gps
+ console.log('error')
+ }
+
+ const getGeoLocation = useCallback(() => {
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(
+ success,
+ (_e) => {
+ onError()
+ },
+ {
+ enableHighAccuracy: true,
+ }
+ )
+ }
+ }, [success])
+
+ useEffect(() => {
+ if (localStorage.getItem('gps-granted')) {
+ getGeoLocation()
+ }
+ }, [getGeoLocation])
+
+ return (
+
+ )
+}
diff --git a/components/screen/City.tsx b/components/screen/City.tsx
new file mode 100644
index 0000000..84063a1
--- /dev/null
+++ b/components/screen/City.tsx
@@ -0,0 +1,18 @@
+import type { location } from '@/utils/types'
+import { Separator } from '../ui/separator'
+
+type CityProps = {
+ promise: Promise
+}
+
+export default async function CurrentDetails({ promise }: CityProps) {
+ const [location] = await promise
+ return (
+ <>
+
+
+ {location?.name}, {location?.country}
+
+ >
+ )
+}
diff --git a/components/screen/Current.tsx b/components/screen/Current.tsx
new file mode 100644
index 0000000..4c326de
--- /dev/null
+++ b/components/screen/Current.tsx
@@ -0,0 +1,74 @@
+import { cn } from '@/lib/utils'
+import { getIfDay } from '@/utils'
+import { getWindCondition, tempValue } from '@/utils/constants'
+import { Separator } from '../ui/separator'
+import { Icons } from '../ui/icons'
+
+type CurrentProps = {
+ daily: {
+ temp: {
+ min: number
+ max: number
+ }
+ }[]
+ current: {
+ temp: number
+ feels_like: number
+ weather: {
+ id: number
+ description: string
+ main: string
+ }[]
+ wind_speed: number
+ sunrise: number
+ sunset: number
+ }
+ units: boolean
+}
+
+export default function Current({ daily, current, units }: CurrentProps) {
+ return (
+ <>
+
+