Skip to content

Commit

Permalink
Merge pull request #282 from gregrickaby/feature/next-app-router-mant…
Browse files Browse the repository at this point in the history
…ine-v7

Next app router mantine v7
  • Loading branch information
gregrickaby committed Oct 12, 2023
2 parents 5184e94 + 0e19bf0 commit cf8ac4c
Show file tree
Hide file tree
Showing 43 changed files with 3,130 additions and 5,426 deletions.
3 changes: 3 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['stylelint-config-standard']
}
21 changes: 21 additions & 0 deletions app/Page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.container {
margin: 0 auto;
padding: 0 20px;
max-width: 1200px;

& > * {
margin-bottom: 20px;
margin-top: 20px;
}
}

.search {
align-items: center;
display: flex;
gap: 10px;
margin-bottom: 20px;
}

.main {
min-height: 100vh;
}
14 changes: 5 additions & 9 deletions pages/api/places.ts → app/api/places/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {NextRequest} from 'next/server'

export const config = {
runtime: 'edge'
}
export const runtime = 'edge'

export interface PredictionResponse {
description: string
Expand All @@ -22,12 +18,12 @@ export interface Place {
* @author Greg Rickaby
* @see https://console.cloud.google.com/apis/credentials
* @see https://developers.google.com/maps/documentation/places/web-service/autocomplete
* @see https://nextjs.org/docs/api-routes/edge-api-routes
* @see https://nextjs.org/docs/api-reference/edge-runtime
* @see https://nextjs.org/docs/app/building-your-application/routing/route-handlers
* @see https://nextjs.org/docs/pages/api-reference/edge
*/
export default async function places(req: NextRequest) {
export async function GET(request: Request) {
// Get query params from request.
const {searchParams} = new URL(req.url)
const {searchParams} = new URL(request.url)

// Parse params.
const unsanitizedLocation = searchParams.get('location') || ''
Expand Down
13 changes: 5 additions & 8 deletions pages/api/weather.ts → app/api/weather/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type {NextRequest} from 'next/server'
import {WeatherResponse} from '~/lib/types'

export const config = {
runtime: 'edge'
}
export const runtime = 'edge'

export interface GeocodeResponse {
status: string
Expand All @@ -29,12 +26,12 @@ export interface GeocodeResponse {
* @see https://console.cloud.google.com/apis/credentials
* @see https://developers.google.com/maps/documentation/geocoding/overview
* @see https://openweathermap.org/api/one-call-api
* @see https://nextjs.org/docs/api-routes/edge-api-routes
* @see https://nextjs.org/docs/api-reference/edge-runtime
* @see https://nextjs.org/docs/app/building-your-application/routing/route-handlers
* @see https://nextjs.org/docs/pages/api-reference/edge
*/
export default async function weather(req: NextRequest) {
export async function GET(request: Request) {
// Get query params from request.
const {searchParams} = new URL(req.url)
const {searchParams} = new URL(request.url)

// Parse params.
const unsanitizedLocation = searchParams.get('location') || ''
Expand Down
15 changes: 7 additions & 8 deletions components/Alerts.tsx → app/components/Alerts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use client'

import {Alert, Text, Title} from '@mantine/core'
import {notifications} from '@mantine/notifications'
import {IconAlertTriangle} from '@tabler/icons-react'
import {useEffect} from 'react'
import {FiTriangle} from 'react-icons/fi'
import {useWeatherContext} from '~/components/WeatherProvider'

/**
Expand All @@ -20,7 +22,7 @@ export default function Alerts() {
notifications.show({
autoClose: 5000,
color: 'red',
icon: <FiTriangle />,
icon: <IconAlertTriangle />,
message:
'Hazardous weather conditions reported for this area. Scroll down for details.',
title: 'Warning'
Expand All @@ -35,21 +37,18 @@ export default function Alerts() {

return (
<section>
<Title align="center" my="lg" order={2}>
<Title my="lg" order={2}>
Alerts
</Title>
{alerts?.map((alert, index: number) => (
<Alert
color="red"
icon={<FiTriangle />}
icon={<IconAlertTriangle />}
key={index}
mb="xl"
sx={{textTransform: 'capitalize'}}
title={alert?.event}
>
<Text mb="md" sx={{textTransform: 'lowercase'}}>
{alert?.description}
</Text>
<Text mb="md">{alert?.description}</Text>
</Alert>
))}
</section>
Expand Down
6 changes: 6 additions & 0 deletions app/components/BackToTop.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.backtotop {
bottom: 12px;
position: fixed;
right: 12px;
z-index: 100;
}
32 changes: 32 additions & 0 deletions app/components/BackTopTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client'

import {Affix, Button, rem, Transition} from '@mantine/core'
import {useWindowScroll} from '@mantine/hooks'
import {IconArrowUp} from '@tabler/icons-react'
import classes from '~/components/BackToTop.module.css'

/**
* Back To Top component.
*/
export default function BackToTop() {
const [scroll, scrollTo] = useWindowScroll()

return (
<div className={classes.backtotop}>
<Affix position={{bottom: rem(20), right: rem(20)}}>
<Transition transition="slide-up" mounted={scroll.y > 0}>
{(transitionStyles) => (
<Button
aria-label="scroll to top"
leftSection={<IconArrowUp size="1rem" />}
style={transitionStyles}
onClick={() => scrollTo({y: 0})}
>
Scroll to top
</Button>
)}
</Transition>
</Affix>
</div>
)
}
24 changes: 24 additions & 0 deletions app/components/CurrentConditions.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.description {
font-size: 2rem;
font-weight: 700;
line-height: 1;
margin: 0;
text-align: center;
text-transform: capitalize;
}

.bigtemp {
font-size: 8rem;
font-weight: 700;
line-height: 1;
margin: 0;
text-align: center;
}

.feelslike {
font-size: 2rem;
font-weight: 700;
line-height: 1;
margin: 0;
text-align: center;
}
53 changes: 53 additions & 0 deletions app/components/CurrentConditions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use client'

import {Stack, Text} from '@mantine/core'
import classes from '~/components/CurrentConditions.module.css'
import {useWeatherContext} from '~/components/WeatherProvider'
import {formatTemperature} from '~/lib/helpers'

/**
* Current Conditions component.
*/
export default function CurrentConditions() {
const {
weather: {
current: {
weather: [{description}],
temp,
feels_like
}
},
tempUnit
} = useWeatherContext()

return (
<Stack align="center">
<Text
className={classes.description}
component="p"
gradient={{from: 'indigo', to: 'cyan', deg: 45}}
variant="gradient"
>
{description}
</Text>
<Text
className={classes.bigtemp}
component="p"
gradient={{from: 'indigo', to: 'cyan', deg: 45}}
variant="gradient"
>
{formatTemperature(tempUnit, temp)}
</Text>
{feels_like > temp && (
<Text
className={classes.feelslike}
component="p"
gradient={{from: 'yellow', to: 'orange', deg: 45}}
variant="gradient"
>
Feels Like: {formatTemperature(tempUnit, feels_like)}
</Text>
)}
</Stack>
)
}
19 changes: 19 additions & 0 deletions app/components/Footer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.footer {
display: flex;
flex-direction: column;
font-family: monospace;
font-size: 0.875rem;
text-align: center;

p {
margin-bottom: 0;
}

a {
color: var(--mantine-color-anchor);

&:hover {
text-decoration: none;
}
}
}
33 changes: 33 additions & 0 deletions app/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {IconBrandGithub} from '@tabler/icons-react'
import classes from '~/components/Footer.module.css'
import config from '~/lib/config'

/**
* Footer component.
*/
export default function Footer() {
return (
<footer className={classes.footer}>
<p>
website by{' '}
<a
aria-label={`visit ${config.siteAuthor} website`}
href={config.authorUrl}
rel="author"
>
{config.siteAuthor}
</a>
</p>
<p>
<a
aria-label="view source code on github"
href={config.githubUrl}
rel="noopener noreferrer"
target="_blank"
>
<IconBrandGithub />
</a>
</p>
</footer>
)
}
11 changes: 11 additions & 0 deletions app/components/Forecast.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.title {
text-align: center;
}

.card {
text-align: center;

img {
margin: 0 auto;
}
}

1 comment on commit cf8ac4c

@vercel
Copy link

@vercel vercel bot commented on cf8ac4c Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

local-weather – ./

local-weather-gregrickaby.vercel.app
local-weather-git-main-gregrickaby.vercel.app
localwx.vercel.app

Please sign in to comment.