Skip to content

Commit

Permalink
front: HGU Weather using OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
junglesub committed Jul 15, 2024
1 parent 0270060 commit 106962f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ jobs:
uses: gradle/[email protected]
with:
arguments: build

env:
REACT_APP_WEATHER_KEY: ${{ secrets.REACT_APP_WEATHER_KEY }}

# 현재 날짜와 시간을 가져오기
- name: Get current date and time
id: date
Expand Down
2 changes: 2 additions & 0 deletions src/main/front/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
Expand Down
14 changes: 14 additions & 0 deletions src/main/front/src/components/FeedItemNew/WeatherData.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.NewUI .weather {
padding-bottom: 16px;
}

.NewUI .weather b {
display: flex;
align-items: center;
}

.NewUI .weather b img {
width: 48px;
height: 48px;
margin-right: 4px;
}
34 changes: 34 additions & 0 deletions src/main/front/src/components/FeedItemNew/WeatherData.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useEffect, useState } from "react";

import "./WeatherData.css";

function WeatherData() {
const [weatherInfo, setWeatherInfo] = useState();
useEffect(() => {
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${36.103268}&lon=${129.388611}&appid=${
process.env.REACT_APP_WEATHER_KEY
}&units=metric`;
fetch(url).then((doc) => doc.json().then((json) => setWeatherInfo(json)));
}, []);

return (
<div className="FeedItem">
<div className="weather">
{!!weatherInfo?.weather ? (
<b>
지금 한동 날씨는:{" "}
<img
alt="Weather"
src={`http://openweathermap.org/img/wn/${weatherInfo.weather[0].icon}.png`}
/>{" "}
{weatherInfo.main.temp}°C
</b>
) : (
"Loading..."
)}
</div>
</div>
);
}

export default WeatherData;
2 changes: 2 additions & 0 deletions src/main/front/src/pages/NewUI.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./NewUI.css";
import FeedItemNew from "../components/FeedItemNew/FeedItemNew";
import WeatherData from "../components/FeedItemNew/WeatherData";

const allFeeds = [
{
Expand Down Expand Up @@ -54,6 +55,7 @@ function NewUI() {
</div>

<div className="list">
<WeatherData />
{allFeeds.length === 0 && <div>No Entry..</div>}
{allFeeds
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
Expand Down

0 comments on commit 106962f

Please sign in to comment.