-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fa23b2
commit 4c46467
Showing
19 changed files
with
421 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,6 @@ | |
body { | ||
@apply bg-background text-foreground; | ||
} | ||
} | ||
} | ||
|
||
@import url(./index.css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import url(../fonts/weather-icons.min.css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Button | ||
variant='ghost' | ||
size='icon' | ||
className='text-base' | ||
onClick={() => { | ||
router.replace( | ||
`/?${ | ||
hasUnits | ||
? queries | ||
.map((query) => { | ||
if (query.key === 'units') { | ||
return `units=${ | ||
units === 'imperial' ? 'metric' : 'imperial' | ||
}` | ||
} | ||
return `${query.key}=${query.value}` | ||
}) | ||
.join('&') | ||
: `units=${units === 'imperial' ? 'metric' : 'imperial'}` | ||
}` | ||
) | ||
}} | ||
> | ||
{units === 'imperial' ? 'F' : 'C'}° | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LucideIcon>(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 ( | ||
<Button size='icon' variant='ghost' onClick={() => getGeoLocation()}> | ||
{React.createElement(icon.current)} | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { location } from '@/utils/types' | ||
import { Separator } from '../ui/separator' | ||
|
||
type CityProps = { | ||
promise: Promise<location[]> | ||
} | ||
|
||
export default async function CurrentDetails({ promise }: CityProps) { | ||
const [location] = await promise | ||
return ( | ||
<> | ||
<Separator className='mb-4 mt-1' /> | ||
<h1 className='mb-2 text-2xl lg:text-3xl'> | ||
{location?.name}, {location?.country} | ||
</h1> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<section className='flex items-center justify-between'> | ||
<div> | ||
<h3 className='text-8xl font-medium leading-tight'> | ||
{tempValue(current.temp, units)}° | ||
</h3> | ||
<p className='mb-7 flex items-center gap-1 text-xs'> | ||
<span className='flex items-center'> | ||
<Icons.chevdown className='inline h-5 w-5 p-0.5' />{' '} | ||
{tempValue(daily[0].temp.min, units)} | ||
° | ||
</span> | ||
<span className='flex items-center'> | ||
<Icons.chevup className='inline h-5 w-5 p-0.5' />{' '} | ||
{tempValue(daily[0].temp.max, units)} | ||
° | ||
</span> | ||
</p> | ||
<div> | ||
<p> | ||
{current.weather[0].main} •{' '} | ||
{getWindCondition(current.wind_speed)?.condition} | ||
</p> | ||
<p className='text-xs leading-normal'> | ||
Feels like {tempValue(current.feels_like, units)}° | ||
</p> | ||
</div> | ||
</div> | ||
<div className='flex flex-col items-center'> | ||
<i | ||
className={cn( | ||
`wi wi-owm${ | ||
!getIfDay(current.sunrise, current.sunset) ? '-night' : '' | ||
}-${current.weather[0].id}`, | ||
'm-4 text-8xl' | ||
)} | ||
></i> | ||
<p className='text-xs'>{current.weather[0].description}</p> | ||
</div> | ||
</section> | ||
<Separator className='my-4' /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { tellMeRain } from '@/utils' | ||
|
||
export default function CurrentDetail({ minutely }) { | ||
return ( | ||
<> | ||
<section> | ||
<p className='text-center'>{tellMeRain(minutely)}</p> | ||
</section> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.