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
98 changes: 5 additions & 93 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,78 +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;
Expand All @@ -86,22 +11,9 @@ body {
}

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;
}
font-family: Arial, sans-serif;
background-color: #f0f4f8;
color: #212529;
margin: 0;
padding: 0;
}
19 changes: 8 additions & 11 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
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 { Provider } from "react-redux";
import store from "./store/configureStore";

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body>
<Provider store={store}>{children}</Provider>
</body>
</html>
)
);
}
206 changes: 118 additions & 88 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,125 @@
import Image from 'next/image'
import styles from './page.module.css'
"use client";
import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import {
fetchWeather,
fetchWeatherByZip,
fetchWeatherByCity,
} from "./store/slices/weatherSlice";
import styles from "./page.module.css";
import axios from "axios";
import {
Sparklines,
SparklinesLine,
SparklinesReferenceLine,
} from "react-sparklines";

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 Home = () => {
const [city, setCity] = useState("");
const [cityName, setCityName] = useState("");
const dispatch = useDispatch();
const { loading, data, error, geoCityName, geoState, geoZip, country } =
useSelector((state) => state.weather);

<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
const getUserLocation = async () => {
try {
const response = await axios.get("https://ipapi.co/json/");
const userCity = response.data.city;
const userState = response.data.region;
const userCountry = response.data.country;
const fullCityName = `${userCity}, ${
userState ? userState + ", " : ""
}${userCountry}`;

dispatch(fetchWeather(fullCityName));
setCityName(fullCityName);

dispatch({ type: "weather/setCityName", payload: fullCityName });
return fullCityName;
} catch (error) {
console.error("Error fetching user location", error);
}
};

<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>
useEffect(() => {
getUserLocation();
}, []);

<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 handleSearch = async () => {
try {
const formattedInput = city.trim();
const isZipCode = /^\d{5}(-\d{4})?$/.test(formattedInput);

<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>
if (isZipCode) {
dispatch(fetchWeatherByZip(formattedInput));
} else {
const [inputCity, inputState] = formattedInput
.split(",")
.map((part) => part.trim());
dispatch(fetchWeatherByCity({ city: inputCity, state: inputState }));
setCityName(formattedInput);
}
} catch (error) {
console.error("Error fetching location from input", error);
}
};

<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>
const handleKeyPress = (event) => {
if (event.key === "Enter") {
handleSearch();
}
};

const getChartData = (key) => {
return data.list ? data.list.map((item) => item.main[key]) : [];
};

return (
<div className={styles.container}>
<h2 className={styles.heading}>Weather Search</h2>
<input
className={styles.searchInput}
type="text"
value={city}
onChange={(e) => setCity(e.target.value)}
onKeyDown={handleKeyPress}
placeholder="Enter a US zip code"
/>
<button className={styles.searchBtn} onClick={handleSearch}>
Search
</button>
{loading && <p>Loading...</p>}
{error && <p>Error: {error}</p>}
<div>
<br></br>
<h3>
Showing data for{" "}
{geoCityName && geoZip
? `${geoCityName}, ${geoZip}, ${country}`
: cityName}
</h3>
<br></br>
<h3>Temperature</h3>
<Sparklines
data={data.list ? data.list.map((item) => item.main.temp) : []}

Choose a reason for hiding this comment

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

what is this for?
its creating the empty space

></Sparklines>
<Sparklines data={getChartData("temp")}>
<SparklinesLine color="blue" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
<h3>Pressure</h3>
<Sparklines data={getChartData("pressure")}>
<SparklinesLine color="green" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
<h3>Humidity</h3>
<Sparklines data={getChartData("humidity")}>
<SparklinesLine color="orange" />
<SparklinesReferenceLine type="mean" />
</Sparklines>
</div>
</main>
)
}
</div>
);
};

export default Home;
Loading