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
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
## Weather Project

This project has been created by a student at Parsity, an online software engineering course. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the repository that this project forks.
This project was created by Mutsumi Hata, a student at Parsity, an online software engineering program. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the original repository from which this project forks.

If you have any questions about this project or the program in general, visit [parsity.io](https://parsity.io/) or email hello@parsity.io.

### Project Description

This simple Redux application builds upon my knowledge of React. I used React's ability to manage components in separate, and more manageble files. I then added Redux's ability to make state management more predictable and scalable. This application also uses React's Sparkline feature to create a line graph of the 5-day temperature, air pressure, and humidity forecasts.

The application allows a user to input the name of a city and returns a 5-day forecast for temperatutre, air pressure and humidity. Along with the daily average, the application returns a 5-day average, along with a line graph of the returned data.

I would like to become more familiar with customizing SparkLine charts.

### Table of Contents

RTK-Weather

- store
- slices
- search.js
- configureStore.js
- rootReducer.js
- globals.css
- layout.js
- page.js
- README.md

### How to Run Application

1. Open terminal
2. Locate file: rtk-weather
3. Type: npm run dev
4. Type: open http://localhost:3000 (or other appropriate host)

### Things to Add/Edit

1. Clear input field onClick
2. Cleaner visual - each city result should be on one line
Binary file removed app/favicon.ico
Binary file not shown.
106 changes: 1 addition & 105 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,107 +1,3 @@
: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;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
background-color: white;
}
20 changes: 10 additions & 10 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use client';
import React from 'react';
import { Provider } from 'react-redux';
import store from './store/configureStore';
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>
<Provider store={store}>
{children}
</Provider>
</body>
</html>
)
}
};
185 changes: 98 additions & 87 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,106 @@
import Image from 'next/image'
import styles from './page.module.css'
'use client';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { Sparklines, SparklinesLine } from 'react-sparklines';
import { fetchWeather } from './store/slices/search';

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 [searchInput, setSearchInput] = useState('');
const [searchResults, setSearchResults] = useState([]);
const dispatch = useDispatch();

<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
const handleSearch = () => {
if (searchInput.trim() === ''){
alert('Error! You must enter a city name.');
return;
}

<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>
dispatch(fetchWeather(searchInput))
.then((response) => {
if (response.payload.cod === '404') {

Choose a reason for hiding this comment

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

interesting that the interface is .cod and not .code

alert('Error! You did not enter a correctly spelled city.');
} else {
setSearchResults((prevResults) => [
...prevResults,
{ city: searchInput, data: response.payload }
]);
}
});
};

<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>
const calculateAverage = (dataList, property) => {
if (!dataList || dataList.length === 0) return 0;
const sum = dataList.reduce((acc, item) => acc + item.main[property], 0);
return (sum / dataList.length).toFixed(2);
};

return (
<main>
<h1>Sparkly Sparkles Weather</h1>
<input id="search-query" placeholder='Enter city name' onChange={(e) => setSearchInput(e.target.value)} />
<br />
<button onClick={handleSearch}>Search</button>

<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>
{searchResults.map((result, index) => (
<div key={index}>
<h2 className='other-data'>{result.city}</h2>

<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>
{result.data && result.data.list && result.data.list.length > 0 && (
<>
<h3>Temperature</h3>
<div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}>
<Sparklines data={result.data.list.slice(0, 5).map(datum => datum.main.temp)} height={50}>
<SparklinesLine color="#FFA500" />
</Sparklines>
</div>
<div className='search-results-five'>
<ul>
{result.data.list.slice(0, 5).map((datum, index) => (
<li key={index} className='data'>{datum.main && datum.main.temp}</li>
))}
</ul>
<ul>
<li className='data'>5-day average: {calculateAverage(result.data.list, 'temp')}</li>
</ul>
</div>

<h3>Pressure</h3>
<div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}>
<Sparklines data={result.data.list.slice(0, 5).map(item => item.main.pressure)} height={50}>
<SparklinesLine color="#000080" />
</Sparklines>
</div>
<div className='search-results-five'>
<ul>
{result.data.list.slice(0, 5).map((item, index) => (
<li key={index} className='data'>{item.main && item.main.pressure}</li>
))}
</ul>
<ul>
<li className='data'>5-day average: {calculateAverage(result.data.list, 'pressure')}</li>
</ul>
</div>

<h3>Humidity</h3>
<div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}>
<Sparklines data={result.data.list.slice(0, 5).map(item => item.main.humidity)} height={50}>
<SparklinesLine color="#008000" />
</Sparklines>
</div>
<div className='search-results-five'>
<ul>
{result.data.list.slice(0, 5).map((item, index) => (
<li key={index} className='data'>{item.main && item.main.humidity}</li>
))}
</ul>
<ul>
<li className='data'>5-day average: {calculateAverage(result.data.list, 'humidity')}</li>
</ul>

Choose a reason for hiding this comment

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

this html is a bit long and hard to understand, there's logic also that could have been extracted to functions to help with readability

</div>
</>
)}
</div>
))}
</main>
)
}
);
};
Loading