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
70 changes: 70 additions & 0 deletions app/components/allData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use client';
import React from 'react';
import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines';
import { useSelector } from 'react-redux';
import 'bootstrap/dist/css/bootstrap.min.css';

/**
*
* @returns react component containing all of the weather data for each city entered.
*/
export const AllData = () => {

Choose a reason for hiding this comment

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

This name is a bit to generic. Personally, prefer something more like specific that will allow me understand from the file name what the component is responsible for. i.e.
CityWeatherData

const weather = useSelector((state) => state.weather.weather);

/**
*
* @param {*} data The data list returned from openweather api.
* @param {*} avgType The weather distinction nested within the data list. Naming convention must be
* exactly the same as json layout, i.e `temp`, `pressure`, or `humidity`.
* @returns The average of the sum of all data points for avgType.
*/
const findAvg = (data, avgType) => {
const typeData = data.map((datum) => datum.main[avgType]);
console.log('here', typeData, typeData.length);

Choose a reason for hiding this comment

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

remove console logs

const sum = typeData.reduce(
(acc, value) => acc + value, 0,
);

return Math.round(sum/typeData.length);
}

return weather.map((cityWeather) => {
return (
<div className='graph-container' key={cityWeather.city.name}>

<div className='graphs city-name' key={cityWeather.city.name}>
<h4>{cityWeather.city.name}</h4>
</div>

<div className='graphs'>
<h5>Temperature</h5>
<Sparklines data={cityWeather.list.map((datum) => datum.main.temp)} width={20} height={10} margin={1}>
<SparklinesLine color='grey' style={{strokeWidth: 0.5, fill: 'none'}}/>
<SparklinesReferenceLine type="mean" />
</Sparklines>
<p>{findAvg(cityWeather.list, 'temp')} F</p>
</div>

<div className='graphs'>
<h5>Pressure</h5>
<Sparklines data={cityWeather.list.map((datum) => datum.main.pressure)} width={20} height={10} margin={1}>
<SparklinesLine color='red' style={{strokeWidth: 0.5, fill: 'none'}}/>
<SparklinesReferenceLine type="mean" />
</Sparklines>
<p>{findAvg(cityWeather.list, 'pressure')} hPa</p>
</div>

<div className='graphs'>
<h5>Humidity</h5>
<Sparklines data={cityWeather.list.map((datum) => datum.main.humidity)} width={20} height={10} margin={1}>
<SparklinesLine color='blue' style={{strokeWidth: 0.5, fill: 'none'}}/>
<SparklinesReferenceLine type="mean" />
</Sparklines>
<p>{findAvg(cityWeather.list, 'humidity')} %</p>
</div>
</div>
)
})


}
35 changes: 35 additions & 0 deletions app/components/cityInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use client';
import 'bootstrap/dist/css/bootstrap.css';
import { fetchWeather, fetchCity } from '../store/slices/weather';
import { useDispatch } from 'react-redux';
import { useState } from 'react';

export const InputField = () => {
const dispatch = useDispatch();
const [input, setInput] = useState();

/**
* dispatch `fetchCity` for async api call to retrieve city coords.
* dispatch `fetchWeather` to get all weather information.
*/
const handleClick = () => {
dispatch(fetchCity(input))
.then((response) =>{
const latitude = response.payload[0].lat;
const longitude = response.payload[0].lon;
dispatch(fetchWeather( {latitude, longitude} ))

Choose a reason for hiding this comment

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

remove empty line

})
};

// returns component with searchbar with event handler
return (
<div className='searchbar mb-3 input-group'>
<input type='text' className='form-control' placeholder='Enter City'
onChange={(e) => setInput(e.target.value)} />
<button className='btn btn-primary' type='button' onClick={handleClick}>Search</button>
</div>

Choose a reason for hiding this comment

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

empty line

)
}

109 changes: 9 additions & 100 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,107 +1,16 @@
: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;
}

@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;
}
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
.graphs {
width: 25%;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
.graph-container {
display: flex;
align-items: center;
}

a {
color: inherit;
text-decoration: none;
.city-name {
text-align: center;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
.set-margin {
margin: 5% 10%;
}
23 changes: 11 additions & 12 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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',
}
'use client';
import './globals.css';
import { Inter } from 'next/font/google';
import { Provider } from 'react-redux';
import store from './store/configureStore';
const inter = Inter({ subsets: ['latin'] });

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
<html lang='en'>
<body className={inter.className}>
<Provider store={store}>{children}</Provider>
</body>
</html>
Comment on lines +11 to +14

Choose a reason for hiding this comment

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

styling went off here

)
}
116 changes: 25 additions & 91 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,29 @@
import Image from 'next/image'
import styles from './page.module.css'
'use client';
import 'bootstrap/dist/css/bootstrap.min.css';
import { useSelector } from 'react-redux';
import { InputField } from './components/cityInput';
import { AllData } from './components/allData';
import React from 'react';

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>

const weather = useSelector((state) => state.weather.weather);

if (weather === null) {
return (
<main>
<InputField />
</main>
)
Comment on lines +13 to +17

Choose a reason for hiding this comment

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

watch out for the style

} else {
return (
<main>
<div className='set-margin'>
<InputField />
<AllData />
</div>
</div>

<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>

<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>
</main>
)
}

<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>

<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>

<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>
)
}
}
3 changes: 2 additions & 1 deletion app/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

.center::before,
.center::after {
content: '';
content: "";
left: 50%;
position: absolute;
filter: blur(45px);
Expand All @@ -107,6 +107,7 @@
.logo {
position: relative;
}

/* Enable hover only on non-touch devices */
@media (hover: hover) and (pointer: fine) {
.card:hover {
Expand Down
Loading