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
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#2f7c47",
"activityBar.background": "#2f7c47",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#422c74",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#2f7c47",
"statusBar.background": "#215732",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#2f7c47",
"statusBarItem.remoteBackground": "#215732",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#215732",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#21573299",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#215732"
}
172 changes: 172 additions & 0 deletions app/components/cityView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"use client";
import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import {
deleteCity,
fetchForecast,
resetList,
} from "@/store/slices/forecastSlice";

import {
Sparklines,
SparklinesLine,
SparklinesReferenceLine,
} from "react-sparklines";

export default function CityView() {
const { forecastData, loading, error, cities } = useSelector(
(state) => state.forecast
);

const dispatch = useDispatch();

const [query, setQuery] = useState("");

useEffect(() => {}, []);

const handleSearch = () => {
if (!query || query.trim() === "") {
alert("Search cannot be empty");
setQuery("");
} else {
dispatch(fetchForecast(query));
setQuery("");
Comment on lines +30 to +33

Choose a reason for hiding this comment

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

DRY
create a function resetSearchBox that calls setQuery. Will help with readability also.

}
};

const handleReset = () => {
if (confirm("Are you sure you want to reset? ")) {
dispatch(resetList());
}
};

const handleInput = (event) => {
setQuery(event.target.value);
};

const handleDelete = (cityId) => {
if (confirm("are you sure you want to delete this city?")) {
dispatch(deleteCity(cityId));
}
};

function average(arr) {

Choose a reason for hiding this comment

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

very generic function name and argument, be specific

return arr.reduce((sum, num) => sum + num) / arr.length;
}

return (
<div className="container">
<div className="input-group m-5">
<input
type="text"
className="form-control"
placeholder="Search city"
value={query}
onChange={handleInput}
required
/>
<button
type="button"
className="btn btn-primary"
onClick={handleSearch}
>
Search
</button>
</div>
<div className="container">
<div className=" text-center">
<button
type="button"
className="btn btn-danger btn-sm"
onClick={handleReset}
>
{" "}
reset list
</button>

</div>
</div>

<h2 className="text-center m-4">City Forecast</h2>
{loading && <div>Loading...</div>}
{!loading && error && <div>Error: {error}</div>}
{!loading && forecastData && (
<div>
<table className="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">City</th>
<th scope="col">Temperature (°F)</th>
<th scope="col">Humidity (%)</th>
<th scope="col">Pressure (hPa)</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{cities.map((city) => {
const tempArray = city.list.map((item) => item.main.temp);
const humidityArray = city.list.map(
(item) => item.main.humidity
);
const pressureArray = city.list.map(
(item) => item.main.pressure
);

const tempAvg = Math.round(average(tempArray));
const humidAvg = Math.round(average(humidityArray));
const pressAvg = Math.round(average(pressureArray));

return (
<tr key={city.id} className="align-bottom">
<td scope="row" className="align-middle"></td>
<td className="align-middle">
<h2>{city.name}</h2>
</td>
<td className="align-bottom">
<Sparklines data={tempArray} height={75} width={125}>
<SparklinesLine color="red" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
<div className="text-center">
{" "}
<h5>{tempAvg} °F </h5>
</div>
</td>
<td className="align-bottom">
<Sparklines data={humidityArray} height={75} width={125}>
<SparklinesLine color="green" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
<div className="text-center">
{" "}
<h5>{humidAvg} %</h5>
</div>
</td>
<td className="align-bottom">
<Sparklines data={pressureArray} height={75} width={125}>
<SparklinesLine color="blue" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
<div className="text-center">
<h5>{pressAvg} hPa </h5>
</div>
</td>
<td className="text-center align-middle">
<button
onClick={() => handleDelete(city.id)}
className="btn btn-danger btn-sm"
>
Delete
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}
107 changes: 0 additions & 107 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,107 +0,0 @@
: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;
}
}
23 changes: 13 additions & 10 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import './globals.css'
import { Inter } from 'next/font/google'
"use client";
import "bootstrap/dist/css/bootstrap.css";
import { Signika_Negative } from "next/font/google";
import { Provider } from "react-redux";
import store from "@/store/configureStore";

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

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
const signikaNegative = Signika_Negative({
subsets: ["latin"],
weight: ["400", "500", "700"],
});

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={signikaNegative.className}>
<Provider store={store}>{children}</Provider>
</body>
</html>
)
);
}
Loading