diff --git a/client/src/App.js b/client/src/App.js index 84b9e7ed92f9874f253dd951f59100c372cfcd88..5b3838eb70d9d0b444f245a2e037592a97d88479 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -5,20 +5,25 @@ import Home from './pages/Home'; import SignupPage from './pages/SignupPage'; import LoginPage from './pages/LoginPage'; import EditPage from './pages/EditPage'; -import PrivateRoute from './utils/PrivateRoutes'; +import OnlyUser from './utils/OnlyUser'; import PageNotFound from './components/PageNotFound'; import Footer from './components/Footer'; import GetLocFirst from './pages/GetLocFirst'; +import { isLogined } from './utils/Auth'; function App() { - + const isLs = localStorage.getItem('login') function loginDefault() { if (isLs === null) { localStorage.setItem('login', false) } + if (isLs === false || isLs === null) { + localStorage.setItem('local-code', '3743011') + + } } return ( @@ -26,13 +31,22 @@ function App() { {loginDefault()} - - + {isLogined() ? + + : + + } + + {isLogined() ? + + : + + } - + - + diff --git a/client/src/Utils/CheckDB.js b/client/src/Utils/CheckDB.js index a0ba915e25f8a178ecf39a00f4df4887b1cde535..25ae23bc68be72694d2cb37c93d600b3729e9625 100644 --- a/client/src/Utils/CheckDB.js +++ b/client/src/Utils/CheckDB.js @@ -2,8 +2,18 @@ import axios from 'axios'; import { Swal } from 'sweetalert2'; import { routesClient } from './../routesClient'; -export function getTempEtc() { + +export async function callUserInfo() { + const res = await axios.get(routesClient.userinfo) + return res.data.contents.user_info +} + +export function getWeatherOut() { callUserInfo().then((res) => { + console.log(res) + // if (res['loc_code'] === null) { + res['loc_code'] = 3743011 + // } const outs = axios.get(routesClient.outsideLoc + res['loc_code']) return outs .then((res) => { @@ -22,11 +32,6 @@ export function getTempEtc() { }) }) } -export async function callUserInfo() { - const res = await axios.get(routesClient.userinfo) - console.log(res.data.contents.user_info) - return res.data.contents.user_info -} export function checkCookies() { const acctoken_cookies = document.cookie.split('=')[1]; diff --git a/client/src/Utils/Oauth.js b/client/src/Utils/Oauth.js index 9fc0900e8f275bc9ecdb083c325cd7a31dc0c3a5..653b650d000c6023298022b57427af2108d7516e 100644 --- a/client/src/Utils/Oauth.js +++ b/client/src/Utils/Oauth.js @@ -39,10 +39,10 @@ export function AuthWithKakao(isLogin) { isLogin ? { email: emailValue, isOAuth: true } : { - email: emailValue, - nick_name: nickValue, - isOAuth: true, - } + email: emailValue, + nick_name: nickValue, + isOAuth: true, + } ) .then((res) => { console.log("kakao", res); @@ -53,6 +53,7 @@ export function AuthWithKakao(isLogin) { ) { // 회원 가입 또는 로그인 성공 localStorage.setItem("login", true); + localStorage.removeItem('local-code'); Swal.fire({ title: isLogin ? "로그인 성공!" : "회원가입 성공!", diff --git a/client/src/Utils/PrivateRoutes.js b/client/src/Utils/OnlyUser.js similarity index 56% rename from client/src/Utils/PrivateRoutes.js rename to client/src/Utils/OnlyUser.js index 0da7762d4865b61db5956cde973021d6f59c0c19..66f5da356c3017e431f2b0520b8b8af83673b440 100644 --- a/client/src/Utils/PrivateRoutes.js +++ b/client/src/Utils/OnlyUser.js @@ -1,8 +1,9 @@ import React from 'react'; import { Redirect, Route } from 'react-router-dom'; +import PageNotFound from '../components/PageNotFound'; import { isLogined } from './Auth'; -function PrivateRoute({ path, children }) { +function OnlyUser({ path, children }) { if (isLogined()) { return ( @@ -10,10 +11,12 @@ function PrivateRoute({ path, children }) { ) } else { - alert('권한이 없습니다') return ( - + <> + + {/* */} + ) } } -export default PrivateRoute +export default OnlyUser diff --git a/client/src/components/ChartHumidity.js b/client/src/components/ChartHumidity.js index 32c5caf38df01370a450d59dedd059ff2d7ea276..384e8326c059943713251935fecc8c3ddcc5fb6a 100644 --- a/client/src/components/ChartHumidity.js +++ b/client/src/components/ChartHumidity.js @@ -1,20 +1,42 @@ -import React from 'react' +import axios from 'axios'; +import React, { useState, useEffect } from 'react' import { Col } from 'react-bootstrap'; import { Bar, Line } from 'react-chartjs-2' +import { callUserInfo } from '../utils/CheckDB'; +import { routesClient } from './../routesClient'; +import { isLogined } from './../utils/Auth'; function ChartHumidity() { - const cardstyled = { - margin: 'auto', - padding: '1em', - display: 'flex', - justifyContent: 'center', - width: '100%', - borderWidth: '3px', - borderRadius: '20px', - borderColor: 'rgb(110, 189, 142)', - color: '#04AB70' - } + const [humi, setHumi] = useState([]) + const [newLabel, setNewLabel] = useState([]) + + useEffect(() => { + if (isLogined()) { + callUserInfo().then((res) => { + const outs = axios.get(routesClient.outsideLoc + res['loc_code']) + console.log('>>', outs) + }) + } + else { + const locDefault = localStorage.getItem('local-code') + axios.get(routesClient.outsideLoc + locDefault) + .then((res) => { + const outWeather = res.data.contents.weather_out + const Array = [] + const Array2 = [] + for (let i = 0; i < outWeather.length; i++) { + Array.push(outWeather[i].humi) + Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0]) + // const colHour = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[0] + // const colMin = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[1] + } + setHumi(Array) + setNewLabel(Array2) + }) + } + }, []) + const options = { legend: { @@ -34,28 +56,26 @@ function ChartHumidity() { maintainAspectRatio: false } const data = { - labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + labels: newLabel, datasets: [ { label: '습도', - fill: true, + data: humi, lineTension: 0.1, - backgroundColor: 'rgba(75,192,192,0.4)', + borderWidth: '2', + fill: true, + backgroundColor: 'rgba(75,192,192,0.1)', borderColor: 'rgba(75,192,192,1)', - borderCapStyle: 'butt', - borderDash: [8, 8], //점선 ex [2,10] - borderDashOffset: 0.0, - borderJoinStyle: 'miter', + borderCapStyle: 'round', pointBorderColor: 'rgba(75,192,192,1)', pointBackgroundColor: '#fff', - pointBorderWidth: 6, + pointBorderWidth: 5, pointHoverRadius: 5, pointHoverBackgroundColor: 'rgba(75,192,192,1)', pointHoverBorderColor: 'rgba(220,220,220,1)', pointHoverBorderWidth: 2, pointRadius: 1, pointHitRadius: 10, - data: [-10, -2, 13, 18, 22, 25, 31, 28, 25, 18, 6, -8] } ] }; diff --git a/client/src/components/ChartPressure.js b/client/src/components/ChartPressure.js index 0230f1b37b5ef3fe4a0dd041de3ed2d301b8815f..79fe840eb444049590919ce7c3193c013e37045d 100644 --- a/client/src/components/ChartPressure.js +++ b/client/src/components/ChartPressure.js @@ -1,9 +1,42 @@ -import React from 'react' -import { Row, Col } from 'react-bootstrap'; -import { Bar, Line } from 'react-chartjs-2' +import axios from 'axios'; +import React, { useEffect, useState } from 'react' +import { Col } from 'react-bootstrap'; +import { Line } from 'react-chartjs-2' +import { callUserInfo } from '../utils/CheckDB'; +import { isLogined } from './../utils/Auth'; +import { routesClient } from './../routesClient'; function ChartPressure() { + const [press, setPress] = useState([]) + const [newLabel, setNewLabel] = useState([]) + + useEffect(() => { + if (isLogined()) { + callUserInfo().then((res) => { + const outs = axios.get(routesClient.outsideLoc + res['loc_code']) + console.log('>>', outs) + }) + } + else { + const locDefault = localStorage.getItem('local-code') + axios.get(routesClient.outsideLoc + locDefault) + .then((res) => { + const outWeather = res.data.contents.weather_out + const Array = [] + const Array2 = [] + for (let i = 0; i < outWeather.length; i++) { + Array.push(outWeather[i].press) + Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0]) + // const colHour = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[0] + // const colMin = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[1] + } + setPress(Array) + setNewLabel(Array2) + }) + } + }, []) + const options = { legend: { display: true, // label 보이기 여부 @@ -21,16 +54,26 @@ function ChartPressure() { maintainAspectRatio: false } const data = { - labels: ['1', '2', '3', '4', '5', '6', '77', '88', '99'], + labels: newLabel, datasets: [ { label: '기압', - data: [1008, 1007, 1000, 1010, 1080, 1020, 1025, 1080, 1030], + data: press, + lineTension: 0.1, borderWidth: '2', fill: true, - borderColor: 'rgba(75,192,192)', - backgroundColor: 'rgba(75,192,192,0.4)', - tension: 0.3 + backgroundColor: 'rgba(75,192,192,0.1)', + borderColor: 'rgba(75,192,192,1)', + borderCapStyle: 'round', + pointBorderColor: 'rgba(75,192,192,1)', + pointBackgroundColor: '#fff', + pointBorderWidth: 5, + pointHoverRadius: 5, + pointHoverBackgroundColor: 'rgba(75,192,192,1)', + pointHoverBorderColor: 'rgba(220,220,220,1)', + pointHoverBorderWidth: 2, + pointRadius: 1, + pointHitRadius: 10, } ] }; diff --git a/client/src/components/ChartTabs.js b/client/src/components/ChartTabs.js index 7caf136d0075f6baf04b867c744c902ebf2cedcb..e5b03309d62b15c0c676fd8bbc95ac502acfff5d 100644 --- a/client/src/components/ChartTabs.js +++ b/client/src/components/ChartTabs.js @@ -5,6 +5,8 @@ import ChartHumidity from './ChartHumidity'; import ChartWindSpeed from './ChartWindSpeed'; import ChartPressure from './ChartPressure'; import '../App.css' +import { getWeatherOut } from './../utils/CheckDB'; +import { isLogined } from './../utils/Auth'; function ChartTabs() { @@ -20,10 +22,12 @@ function ChartTabs() { color: '#04AB70' } - const [key, setKey] = useState('temp'); //3743011 default + + const [key, setKey] = useState('temp'); + return ( diff --git a/client/src/components/ChartTemp.js b/client/src/components/ChartTemp.js index 4715bf47f9634576432695d89a97c3c8e7b71c01..4c2597f8da33159766f1bb56ea1e65504c07f326 100644 --- a/client/src/components/ChartTemp.js +++ b/client/src/components/ChartTemp.js @@ -1,35 +1,40 @@ import React, { useState } from "react"; import { Col } from "react-bootstrap"; import { Bar } from "react-chartjs-2"; -import { callUserInfo } from "../utils/CheckDB"; +import { callUserInfo, getWeather } from "../utils/CheckDB"; import { useEffect } from "react"; import axios from "axios"; import { routesClient } from "./../routesClient"; +import { isLogined } from "./../utils/Auth"; function ChartTemp() { const [temp, setTemp] = useState([]); + const [newLabel, setNewLabel] = useState([]); useEffect(() => { - callUserInfo().then((res) => { - const outs = axios.get(routesClient.outsideLoc + res["loc_code"]); - return outs.then((res) => { + if (isLogined()) { + callUserInfo().then((res) => { + const outs = axios.get(routesClient.outsideLoc + res["loc_code"]); + console.log(">>", outs); + }); + } else { + const locDefault = localStorage.getItem("local-code"); + axios.get(routesClient.outsideLoc + locDefault).then((res) => { const outWeather = res.data.contents.weather_out; - console.log(res.data.contents.weather_out); - let i = 0; - // setTemp(res.data.contents.weather_out[0].temp) - const tempArray = []; - for (i; i < 3; i++) { - console.log(i); - console.log(outWeather[i]); - tempArray.push(outWeather[i].temp); + const Array = []; + const Array2 = []; + console.log(outWeather); + let i = outWeather.length - 9; + for (i; i < outWeather.length; i++) { + Array.push(outWeather[i].temp); + Array2.push(outWeather[i].collected_at.split("T")[1].split(".")[0]); } - setTemp(tempArray); + setTemp(Array); + setNewLabel(Array2); }); - }); + } }, []); - console.log(temp); - const options = { legend: { display: true, // label 보이기 여부 @@ -50,7 +55,7 @@ function ChartTemp() { maintainAspectRatio: false, }; const data = { - labels: ["1", "2", "3", "4", "5", "6", "77", "88", "99"], + labels: newLabel, datasets: [ { label: "온도", @@ -68,17 +73,18 @@ function ChartTemp() { "rgba(191,191,191,1)", "rgba(191,191,191,1)", ], + backgroundColor: [ - "rgba(75,192,192,0.4)", - "rgba(75,192,192,0.4)", - "rgba(75,192,192,0.4)", - "rgba(75,192,192,0.4)", - "rgba(75,192,192,0.4)", - "rgba(75,192,192,0.4)", + "rgba(75,192,192,0.1)", + "rgba(75,192,192,0.1)", + "rgba(75,192,192,0.1)", + "rgba(75,192,192,0.1)", + "rgba(75,192,192,0.1)", + "rgba(75,192,192,0.1)", - "rgba(191,191,191,0.4)", - "rgba(191,191,191,0.4)", - "rgba(191,191,191,0.4)", + "rgba(191,191,191,0.1)", + "rgba(191,191,191,0.1)", + "rgba(191,191,191,0.1)", ], }, ], diff --git a/client/src/components/ChartWindSpeed.js b/client/src/components/ChartWindSpeed.js index f3c948f5af137d181460816c32abdfa736fe0fc6..9337f13357f40151202f900a62689b4b74d698c8 100644 --- a/client/src/components/ChartWindSpeed.js +++ b/client/src/components/ChartWindSpeed.js @@ -1,9 +1,40 @@ -import React from 'react' +import axios from 'axios'; +import React, { useState, useEffect } from 'react' import { Col } from 'react-bootstrap'; -import { Bar } from 'react-chartjs-2' +import { Bar, Line } from 'react-chartjs-2' +import { callUserInfo } from '../utils/CheckDB'; +import { routesClient } from './../routesClient'; +import { isLogined } from './../utils/Auth'; function ChartWindSpeed() { + const [windSpd, setWindSpd] = useState([]) + const [newLabel, setNewLabel] = useState([]) + + useEffect(() => { + if (isLogined()) { + callUserInfo().then((res) => { + const outs = axios.get(routesClient.outsideLoc + res['loc_code']) + console.log('>>', outs) + }) + } + else { + const locDefault = localStorage.getItem('local-code') + axios.get(routesClient.outsideLoc + locDefault) + .then((res) => { + const outWeather = res.data.contents.weather_out + const Array = [] + const Array2 = [] + for (let i = 0; i < outWeather.length; i++) { + Array.push(outWeather[i].wind_speed) + Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0]) + } + setWindSpd(Array) + setNewLabel(Array2) + }) + } + }, []) + const options = { legend: { display: true, // label 보이기 여부 @@ -22,21 +53,33 @@ function ChartWindSpeed() { maintainAspectRatio: false } const data = { - labels: ['1', '2', '3', '4', '5', '6', '77', '88', '99'], + labels: newLabel, datasets: [ { label: '풍속', + data: windSpd, + lineTension: 0.1, borderWidth: '2', - data: [1008, 1007, 1000, 999, 1080, 1020, 1025, 1080, 1030], + fill: true, + backgroundColor: 'rgba(75,192,192,0.1)', borderColor: 'rgba(75,192,192,1)', - backgroundColor: 'rgba(75,192,192,0.4)' + borderCapStyle: 'round', + pointBorderColor: 'rgba(75,192,192,1)', + pointBackgroundColor: '#fff', + pointBorderWidth: 5, + pointHoverRadius: 5, + pointHoverBackgroundColor: 'rgba(75,192,192,1)', + pointHoverBorderColor: 'rgba(220,220,220,1)', + pointHoverBorderWidth: 2, + pointRadius: 1, + pointHitRadius: 10, } ] }; return ( - diff --git a/client/src/components/LoginComp.js b/client/src/components/LoginComp.js index e035e0b228e16e6fe7bd7411dbdb917fcd9087fc..abcbb87ed32cfc4a7bc0b2b9441a4a957250faa6 100644 --- a/client/src/components/LoginComp.js +++ b/client/src/components/LoginComp.js @@ -66,6 +66,7 @@ function LoginComp() { setMailSend(res.data.contents.mail_sending); setAlertShow(true); localStorage.setItem("login", true); + localStorage.removeItem('local-code'); } return ( diff --git a/client/src/components/MainLayer.js b/client/src/components/MainLayer.js index 374acf09671d70bbd2e6a0b3f7f4e75e34a014ae..46cdda20ebaae421f07e9eac9edc2f7cded8244d 100644 --- a/client/src/components/MainLayer.js +++ b/client/src/components/MainLayer.js @@ -3,7 +3,6 @@ import { Button, Image, Row, ButtonGroup, Col } from 'react-bootstrap'; import { Link } from 'react-router-dom'; import '../App.css' import UserInfo from './UserInfo'; -import { kakaoLogout } from '../utils/Oauth'; import UsingAircon from './UsingAircon'; import { isLogined, localLogout } from '../utils/Auth'; import TimeNow from './TimeNow'; @@ -48,7 +47,6 @@ function MainLayer() { - @@ -76,6 +74,8 @@ function MainLayer() { } + + diff --git a/client/src/components/PageNotFound.js b/client/src/components/PageNotFound.js index c6e7b1d1598a0980568de4244132b2855abb0274..87b749a876247ce5a4d175e9d51ea9e175eec8ec 100644 --- a/client/src/components/PageNotFound.js +++ b/client/src/components/PageNotFound.js @@ -3,8 +3,11 @@ import { Row, Container } from 'react-bootstrap'; import Loading from './Loading'; function PageNotFound() { + useEffect(() => { - setTimeout(window.location.replace('/'), 5000); + setTimeout(function () { + window.location.replace('/') + }, 3000); }, []) return ( @@ -17,7 +20,7 @@ function PageNotFound() { PAGE NOT FOUND
-

+

잘못된 접근 입니다.

diff --git a/client/src/pages/Home.js b/client/src/pages/Home.js index 7e657de5eaff0b658c01544abc1f3ebb09e789b8..65457dc987709827da9f7c5ddbf40b7a0f933efe 100644 --- a/client/src/pages/Home.js +++ b/client/src/pages/Home.js @@ -5,6 +5,7 @@ import '../App.css' import EueSuggest from '../components/EueSuggest'; import Donation from '../components/Donation'; import ChartTabs from '../components/ChartTabs'; +import ChartDoughnut from '../components/ChartDoughnut'; function Home() { const constyled = { @@ -43,6 +44,7 @@ function Home() { +