Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/components/searchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { useState } from 'react'

const SearchBar = ({ onSearch }) => {
const [searchCity, setSearchCity] = useState('');

//trim removing whitespace to help validate search parameters
const handleSearch = () => {
if (searchCity.trim() !=='') {
onSearch(searchCity.trim());
setSearchCity('');
}
};
//convenience to hit 'enter' instead of only clicking by calling handlesearch via 'enter' keydown
const handleKeyDown = (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: use names that are less vague - instead of e use event

if (e.key === 'Enter') {
handleSearch();
}
}

return (
<div>
<input
className='city-input'
type='text'
placeholder='Enter city'
value={searchCity}
onChange={(e) => setSearchCity(e.target.value)}
onKeyDown={handleKeyDown}
/>
<button
className='button'

onClick={handleSearch}
>
Search
</button>
</div>
);
}

export default SearchBar;
110 changes: 16 additions & 94 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,107 +1,29 @@
:root {
--max-width: 1100px;
--border-radius: 12px;
--font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono',
'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro',
'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;

--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;

--primary-glow: conic-gradient(
from 180deg at 50% 50%,
#16abff33 0deg,
#0885ff33 55deg,
#54d6ff33 120deg,
#0071ff33 160deg,
transparent 360deg
);
--secondary-glow: radial-gradient(
rgba(255, 255, 255, 1),
rgba(255, 255, 255, 0)
);

--tile-start-rgb: 239, 245, 249;
--tile-end-rgb: 228, 232, 233;
--tile-border: conic-gradient(
#00000080,
#00000040,
#00000030,
#00000020,
#00000010,
#00000010,
#00000080
);

--callout-rgb: 238, 240, 241;
--callout-border-rgb: 172, 175, 176;
--card-rgb: 180, 185, 188;
--card-border-rgb: 131, 134, 135;
body {
background-color: rgb(243, 231, 217);
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;

--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
--secondary-glow: linear-gradient(
to bottom right,
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0.3)
);

--tile-start-rgb: 2, 13, 46;
--tile-end-rgb: 2, 5, 19;
--tile-border: conic-gradient(
#ffffff80,
#ffffff40,
#ffffff30,
#ffffff20,
#ffffff10,
#ffffff10,
#ffffff80
);

--callout-rgb: 20, 20, 20;
--callout-border-rgb: 108, 108, 108;
--card-rgb: 100, 100, 100;
--card-border-rgb: 200, 200, 200;
}
h2 {
color: rgb(78, 140, 240);
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
.button{
margin-left: 5px;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
.button:hover {
background-color: rgb(193, 193, 241);
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
.city-name-render {
text-align: center;
}

a {
color: inherit;
text-decoration: none;
.render-container {
display: flex;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
.spark-box {
flex: 1;
margin: 5px;
border: rgb(75, 74, 74);
}
13 changes: 7 additions & 6 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
'use client'
import store from './store/configureStore';
import { Inter } from 'next/font/google';
import { Provider } from 'react-redux';
import './globals.css'
import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<Provider store={store}>{children}</Provider>
</body>
</html>
)
}
165 changes: 77 additions & 88 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,84 @@
import Image from 'next/image'
import styles from './page.module.css'

'use client'
import React from 'react';
import SearchBar from './components/searchBar';
import { useDispatch, useSelector } from 'react-redux';
import { fetchWeatherAPI } from './store/slices/weatherSlice';
import { SparklinesLine, Sparklines, SparklinesReferenceLine } from 'react-sparklines';

function getHighLow(data) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: use functional expressions vs declarations

if (data.length === 0) return { high: 0, low: 0 };
const high = Math.round(Math.max(...data));
const low = Math.round(Math.min(...data));
return { high, low };
}

function averageTemps(data) {
if (data.length === 0) return 0;
const sum = data.reduce((accumulator, value) => accumulator + value, 0);
return Math.round(sum / data.length);
}

export default function Home() {
return (
<main className={styles.main}>
<div className={styles.description}>
<p>
Get started by editing&nbsp;
<code className={styles.code}>app/page.js</code>
</p>
<div>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className={styles.vercelLogo}
width={100}
height={24}
priority
/>
</a>
</div>
</div>
const dispatch = useDispatch();
const cities = useSelector((state) => [...state.weather.cities].reverse());
const loading = useSelector((state) => state.weather.loading);
const error = useSelector((state) => state.weather.error);

<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
const handleSearch = (searchCity) => {
dispatch(fetchWeatherAPI(searchCity));
};

<div className={styles.grid}>
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Docs <span>-&gt;</span>
</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
return (
<div className='smaller'>
<div className='boxes'>
<h1 className='page-title'>Basic RTK Weather App</h1>

<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Learn <span>-&gt;</span>
</h2>
<p>Learn about Next.js in an interactive course with&nbsp;quizzes!</p>
</a>
<SearchBar onSearch={handleSearch} />

<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Templates <span>-&gt;</span>
</h2>
<p>Explore the Next.js 13 playground.</p>
</a>
{loading && <p className='Slow-ding'>Be super patient or you'll run out of time.</p>}
{error && <p className='error'>Error: {error}</p>}

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Deploy <span>-&gt;</span>
</h2>
<p>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
)
}
{cities.map((cityData, index) => (
<div key={index} className='big-container'>
<h2 className='city-name-render'>Weather in {cityData.city.name}</h2>
<div className='render-container'>
<div className='spark-box'>
<h3 className='temperature-title'>Temperature</h3>
<Sparklines data={cityData.temperature} height={40}>
<SparklinesLine color='blue' />
<SparklinesReferenceLine type='avg' />
</Sparklines>
<p className='average-temp-display'>
Average 5-day Temperature: {averageTemps(cityData.temperature)}°F
</p>
<p className='average-temp-display'>High: {getHighLow(cityData.temperature).high}°F</p>
<p className='average-temp-display'>Low: {getHighLow(cityData.temperature).low}°F</p>
</div>
<div className='spark-box'>
<h3 className='pressure-title'>Pressure</h3>
<Sparklines data={cityData.pressure} height={40}>
<SparklinesLine color='green' />
<SparklinesReferenceLine type='avg' />
</Sparklines>
<p className='average-pressure-display'>
Average 5-day Pressure: {averageTemps(cityData.pressure)} hPa
</p>
</div>
<div className='spark-box'>
<h3 className='humidity-title'>Humidity</h3>
<div className='sparkline-box'>
<Sparklines data={cityData.humidity} height={40}>
<SparklinesLine color='purple' />
<SparklinesReferenceLine type='avg' />
</Sparklines>
</div>
<p className='average-humidity-display'>Average: {averageTemps(cityData.humidity)}%</p>
</div>
</div>
</div>
))}
</div>
</div>
);
}
Loading