Skip to content

Commit 0276655

Browse files
committed
Fetch API included
1 parent ae3c2b2 commit 0276655

File tree

7 files changed

+95
-14
lines changed

7 files changed

+95
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"dotenv": "^16.4.7",
13+
"next": "15.1.7",
1214
"react": "^19.0.0",
13-
"react-dom": "^19.0.0",
14-
"next": "15.1.7"
15+
"react-dom": "^19.0.0"
1516
},
1617
"devDependencies": {
17-
"typescript": "^5",
18+
"@eslint/eslintrc": "^3",
1819
"@types/node": "^20",
1920
"@types/react": "^19",
2021
"@types/react-dom": "^19",
21-
"postcss": "^8",
22-
"tailwindcss": "^3.4.1",
2322
"eslint": "^9",
2423
"eslint-config-next": "15.1.7",
25-
"@eslint/eslintrc": "^3"
24+
"postcss": "^8",
25+
"tailwindcss": "^3.4.1",
26+
"typescript": "^5"
2627
}
2728
}

src/app/page.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1-
import Image from "next/image";
2-
3-
export default function Home() {
1+
"use client";
2+
import React, { useEffect, useState } from "react";
3+
export default function Page() {
4+
const [posts, setPosts] = useState([]);
5+
const [error, setError] = useState(null);
6+
useEffect(() => {
7+
async function fetchData() {
8+
try {
9+
const response = await fetch(
10+
"http://api.weatherapi.com/v1/forecast.json?key=b59bf0aa6d93440f8fc113152251902&q=London&days=5"
11+
);
12+
if (!response.ok) {
13+
throw new Error(`HTTP error! status: ${response.status}`);
14+
}
15+
const data = await response.json();
16+
setPosts(data.current || []);
17+
} catch (error) {
18+
setError(error);
19+
}
20+
}
21+
fetchData();
22+
}, []);
23+
if (error) {
24+
return (
25+
<div>
26+
<h1>Error</h1>
27+
<p>{error.message}</p>
28+
</div>
29+
);
30+
}
431
return (
5-
6-
<li>
7-
Hello
8-
</li>
32+
<ul>
33+
<li key={posts.last_updated}>
34+
<div>{posts.last_updated}: {posts.temp_c}°C </div>
35+
WIND(mph) {posts.wind_mph}mph
36+
</li>
37+
</ul>
938
);
10-
}
39+
}

src/assets/components/form/Button.tsx

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
5+
interface FormProps {
6+
onSubmit: (inputValue: string) => void;
7+
}
8+
9+
export default function Form({ onSubmit }: FormProps) {
10+
const [inputValue, setInputValue] = useState("");
11+
12+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
13+
setInputValue(event.target.value);
14+
};
15+
16+
const handleSubmit = () => {
17+
console.log(inputValue)
18+
onSubmit(inputValue);
19+
setInputValue(""); // Clear input after submission
20+
};
21+
22+
return (
23+
<form onSubmit={handleSubmit}>
24+
<div>Enter City Name
25+
</div><input
26+
type="text"
27+
value={inputValue}
28+
onChange={handleChange}
29+
placeholder="Enter city name..."
30+
/>
31+
<button
32+
type="submit">
33+
Submit
34+
</button>
35+
</form>
36+
);
37+
}

src/assets/components/form/Sidebar.tsx

Whitespace-only changes.

0 commit comments

Comments
 (0)