From 0fc1a32933fa020e8444a81c0cf4c6a25377a162 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:05:17 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20prettier=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 20 +++++++++++++++++++ package.json | 1 + .../solutionReportPage/SolutionReport.js | 10 +++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ae26def..a207bea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", + "prettier": "^2.7.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0", @@ -13564,6 +13565,20 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", @@ -26382,6 +26397,11 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==" }, + "prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==" + }, "pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/package.json b/package.json index 45ee750..aecd253 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", + "prettier": "^2.7.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0", diff --git a/src/pages/solutionReportPage/SolutionReport.js b/src/pages/solutionReportPage/SolutionReport.js index d21b90b..0d3cc8b 100644 --- a/src/pages/solutionReportPage/SolutionReport.js +++ b/src/pages/solutionReportPage/SolutionReport.js @@ -50,7 +50,9 @@ export default function SolutionReport() { {submitted ? ( <> 제보해주셔서 감사합니다. - 다른 정답 제보 + + 다른 정답 제보 + ) : ( @@ -94,7 +96,9 @@ export default function SolutionReport() { <> 기여자 등록 - GitHub 로그인 + + GitHub 로그인 + 내용 @@ -104,7 +108,7 @@ export default function SolutionReport() { cols="100" onInput={handleDetailContentInput} defaultValue={detailContent} - > + /> From e0d07e3c111751bfb8e42870859e55e4136ec72b Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:10:01 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20github=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/errorReportPage/ErrorReport.js | 32 ++++++++--- .../solutionReportPage/SolutionReport.js | 57 ++++++++++--------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/pages/errorReportPage/ErrorReport.js b/src/pages/errorReportPage/ErrorReport.js index a83763c..4fba4b6 100644 --- a/src/pages/errorReportPage/ErrorReport.js +++ b/src/pages/errorReportPage/ErrorReport.js @@ -21,10 +21,13 @@ export default function ErrorReport() { const [questionName, setQuestionName] = useState(""); const [detailContent, setDetailContent] = useState(""); - const isQuestionNameVisible = errorCategory !== "" && errorCategory !== "error-notCopied"; + const isQuestionNameVisible = + errorCategory !== "" && errorCategory !== "error-notCopied"; const isDetailContentVisible = - errorCategory !== "" && (errorCategory !== "error-wrongAnswer" || questionName !== ""); - const isSubmitBtnDisabled = errorCategory === "error-other" && detailContent === ""; + errorCategory !== "" && + (errorCategory !== "error-wrongAnswer" || questionName !== ""); + const isSubmitBtnDisabled = + errorCategory === "error-other" && detailContent === ""; function handleOtherErrorBtnClick() { setSubmitted(false); @@ -56,14 +59,19 @@ export default function ErrorReport() { {submitted ? ( <> 제보해주셔서 감사합니다. - 다른 오류 제보 + + 다른 오류 제보 + ) : ( 오류 유형 - diff --git a/src/pages/solutionReportPage/SolutionReport.js b/src/pages/solutionReportPage/SolutionReport.js index 0d3cc8b..23da40c 100644 --- a/src/pages/solutionReportPage/SolutionReport.js +++ b/src/pages/solutionReportPage/SolutionReport.js @@ -63,36 +63,37 @@ export default function SolutionReport() { placeholder="문제 이름을 검색하세요." defaultValue={questionName} onInput={handleQuestionNameInput} - > - - - 1번문제 - - - 2번문제 - - - 3번문제 - - - 4번문제 - - - 5번문제 - - - 6번문제 - - - 7번문제 - - - 8번문제 - - + /> + {/**/} + {/* */} + {/* 1번문제*/} + {/* */} + {/* */} + {/* 2번문제*/} + {/* */} + {/* */} + {/* 3번문제*/} + {/* */} + {/* */} + {/* 4번문제*/} + {/* */} + {/* */} + {/* 5번문제*/} + {/* */} + {/* */} + {/* 6번문제*/} + {/* */} + {/* */} + {/* 7번문제*/} + {/* */} + {/* */} + {/* 8번문제*/} + {/* */} + {/**/} - {isDetailContentVisible && ( + {/*isDetailContentVisible &&*/} + {true && ( <> 기여자 등록 From 4a1ce6fce6cd1c75c3a6e180dca1abb70e4ddfc7 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:27:21 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20env=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e..bc37b7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.env +.env.local From 4982296b9f86e83ff3258c06dd586bee97668741 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:39:06 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20env=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bc37b7d..f661b37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .env -.env.local +.env.development +.idea From 5e8efee111e32c4d27a281cf2c88e6c48043bad1 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:39:38 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20github=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=9D=84=20=EC=9C=84=ED=95=9C=20accessToken=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD,=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solutionReportPage/utils/gitHubLogin.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/pages/solutionReportPage/utils/gitHubLogin.js diff --git a/src/pages/solutionReportPage/utils/gitHubLogin.js b/src/pages/solutionReportPage/utils/gitHubLogin.js new file mode 100644 index 0000000..a0e7408 --- /dev/null +++ b/src/pages/solutionReportPage/utils/gitHubLogin.js @@ -0,0 +1,27 @@ +export const LOGIN_URL = + "https://github.com/login/oauth/authorize?client_id=" + + process.env.REACT_APP_CLIENT_ID; + +export const requestAccessToken = async (code) => { + const client_secret = process.env.REACT_APP_CLIENT_SECRET; + const client_id = process.env.REACT_APP_CLIENT_ID; + const response = await fetch( + `https://github.com/login/oauth/access_token?client_id=${client_id}&client_secret=${client_secret}&code=${code}`, + { + method: "POST", + headers: { + Accept: "application/json", + }, + } + ); + return response.json(); +}; +export const requestLogin = async (access_token) => { + const userInfo = await fetch("https://api.github.com/user", { + headers: { + Accept: "application/vnd.github+json", + Authorization: `token ${access_token}`, + }, + }); + return userInfo.json(); +}; From daaa44361b773beec93ce971a6f8bd22957681c9 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Tue, 19 Jul 2022 22:41:33 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=81=B4=EB=A6=AD=EC=8B=9C=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EA=B5=AC=ED=98=84=20-=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=EC=97=90=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9D=B4=20=EC=9E=88=EB=8B=A4=EB=A9=B4:=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20?= =?UTF-8?q?code=EC=99=80=20=ED=95=A8=EA=BB=98=20=EB=A6=AC=EB=94=94?= =?UTF-8?q?=EB=A0=89=EC=85=98=EB=90=A8=20-=20=EA=B8=B0=EC=A1=B4=EC=97=90?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=9C=20=EC=A0=81=EC=9D=B4?= =?UTF-8?q?=20=EC=97=86=EB=8B=A4=EB=A9=B4:=20=EA=B9=83=ED=97=88=EB=B8=8C?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=A1=9C=20=EC=97=B0=EA=B2=B0=EB=90=98=EA=B3=A0=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=99=84=EB=A3=8C=EC=8B=9C=20code=EC=99=80=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=EB=A6=AC=EB=94=94=EB=A0=89=EC=85=95?= =?UTF-8?q?=EB=90=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solutionReportPage/SolutionReport.js | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/pages/solutionReportPage/SolutionReport.js b/src/pages/solutionReportPage/SolutionReport.js index 23da40c..b8c0a18 100644 --- a/src/pages/solutionReportPage/SolutionReport.js +++ b/src/pages/solutionReportPage/SolutionReport.js @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import styled from "styled-components"; import Header from "../../components/Header"; import { @@ -15,12 +15,32 @@ import { SubmitBtn, } from "../../style/styledComponents"; import gitHubLogoSrc from "../../images/github-logo-white.png"; +import { useSearchParams } from "react-router-dom"; +import { + LOGIN_URL, + requestAccessToken, + requestLogin, +} from "./utils/gitHubLogin"; export default function SolutionReport() { const [submitted, setSubmitted] = useState(false); const [questionName, setQuestionName] = useState(""); const [detailContent, setDetailContent] = useState(""); + const [searchParams, setSearchParams] = useSearchParams(); + const [userInfo, setUserInfo] = useState({}); + useEffect(() => { + if (searchParams.get("code")) { + const code = searchParams.get("code"); + requestAccessToken(code) + .then((response) => requestLogin(response.access_token)) + .then((response) => { + setUserInfo(response); + console.log(response); + }); + } + }, [searchParams]); + const handleGitHubLogin = async () => {}; const isDetailContentVisible = questionName !== ""; const isSubmitBtnDisabled = detailContent === ""; @@ -93,13 +113,22 @@ export default function SolutionReport() { {/*isDetailContentVisible &&*/} - {true && ( + { <> 기여자 등록 - - GitHub 로그인 - + {userInfo.hasOwnProperty("avatar_url") ? ( + + ) : ( + + + GitHub 로그인 + + + )} 내용 @@ -122,7 +151,7 @@ export default function SolutionReport() { - )} + } )} @@ -148,3 +177,4 @@ const GitHubLoginBtn = styled.button` const Msg = styled.span` color: ${(props) => props.theme.programmersBlue}; `; +const UserInfo = styled.div``; From d6a9158234b6419464547bc17651a017269b1325 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Wed, 20 Jul 2022 11:17:14 +0900 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20RecoilState=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=84=B8=EC=85=98=20=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=A7=80=EB=A1=9C=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20effect=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/state/user.js | 8 ++++++++ src/state/utils/sessionStorageEffect.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/state/user.js create mode 100644 src/state/utils/sessionStorageEffect.js diff --git a/src/state/user.js b/src/state/user.js new file mode 100644 index 0000000..4416b26 --- /dev/null +++ b/src/state/user.js @@ -0,0 +1,8 @@ +import { atom } from "recoil"; +import { sessionStorageEffect } from "./utils/sessionStorageEffect"; + +const userState = atom({ + key: "userState", + default: {}, + effects: [sessionStorageEffect("userState")], +}); diff --git a/src/state/utils/sessionStorageEffect.js b/src/state/utils/sessionStorageEffect.js new file mode 100644 index 0000000..f994c05 --- /dev/null +++ b/src/state/utils/sessionStorageEffect.js @@ -0,0 +1,14 @@ +export const sessionStorageEffect = + (key) => + ({ setSelf, onSet }) => { + const savedValue = sessionStorage.getItem(key); + if (savedValue != null) { + setSelf(JSON.parse(savedValue)); + } + + onSet((newValue, _, isReset) => { + isReset + ? sessionStorage.removeItem(key) + : sessionStorage.setItem(key, JSON.stringify(newValue)); + }); + }; From 6d47c2e4940cbdd9ec0f5607815bfbe6ad8717c0 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Wed, 20 Jul 2022 19:01:09 +0900 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20userState=20=EC=9D=98=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C=20Object=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 ++ src/state/user.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..9bf315f --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +REACT_APP_CLIENT_ID=c313b0e560ae722655f1 +REACT_APP_CLIENT_SECRET=f1f8dc2e62bff607b1fd7478511ae67ca412c12a diff --git a/src/state/user.js b/src/state/user.js index 4416b26..71fd64d 100644 --- a/src/state/user.js +++ b/src/state/user.js @@ -6,3 +6,43 @@ const userState = atom({ default: {}, effects: [sessionStorageEffect("userState")], }); +export default userState; + +const userObject = { + avatar_url: "https://avatars.githubusercontent.com/u/54318460?v=4", + bio: null, + blog: "", + company: null, + created_at: "2019-08-20T13:16:15Z", + email: "codeisneverodd@gmail.com", + events_url: "https://api.github.com/users/codeisneverodd/events{/privacy}", + followers: 73, + followers_url: "https://api.github.com/users/codeisneverodd/followers", + following: 168, + following_url: + "https://api.github.com/users/codeisneverodd/following{/other_user}", + gists_url: "https://api.github.com/users/codeisneverodd/gists{/gist_id}", + gravatar_id: "", + hireable: null, + html_url: "https://github.com/codeisneverodd", + id: 54318460, + location: null, + login: "codeisneverodd", + name: "codeisneverodd", + node_id: "MDQ6VXNlcjU0MzE4NDYw", + organizations_url: "https://api.github.com/users/codeisneverodd/orgs", + public_gists: 1, + public_repos: 9, + received_events_url: + "https://api.github.com/users/codeisneverodd/received_events", + repos_url: "https://api.github.com/users/codeisneverodd/repos", + site_admin: false, + starred_url: + "https://api.github.com/users/codeisneverodd/starred{/owner}{/repo}", + subscriptions_url: + "https://api.github.com/users/codeisneverodd/subscriptions", + twitter_username: null, + type: "User", + updated_at: "2022-07-15T04:07:10Z", + url: "https://api.github.com/users/codeisneverodd", +}; From 9ecb600effbc81db42dded9e86f85a64fda99674 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Wed, 20 Jul 2022 19:01:42 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20userState=EB=A5=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=ED=9B=85=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/user/useSetUser.js | 7 +++++++ src/hooks/user/useUserLogin.js | 26 ++++++++++++++++++++++++++ src/hooks/user/useUserProfile.js | 11 +++++++++++ src/hooks/user/useUserValue.js | 7 +++++++ 4 files changed, 51 insertions(+) create mode 100644 src/hooks/user/useSetUser.js create mode 100644 src/hooks/user/useUserLogin.js create mode 100644 src/hooks/user/useUserProfile.js create mode 100644 src/hooks/user/useUserValue.js diff --git a/src/hooks/user/useSetUser.js b/src/hooks/user/useSetUser.js new file mode 100644 index 0000000..d3e8a5e --- /dev/null +++ b/src/hooks/user/useSetUser.js @@ -0,0 +1,7 @@ +import { useSetRecoilState } from "recoil"; +import userState from "../../state/user"; + +const useSetUser = () => { + return useSetRecoilState(userState); +}; +export default useSetUser; diff --git a/src/hooks/user/useUserLogin.js b/src/hooks/user/useUserLogin.js new file mode 100644 index 0000000..828460d --- /dev/null +++ b/src/hooks/user/useUserLogin.js @@ -0,0 +1,26 @@ +import { + requestAccessTokenAPI, + requestLoginAPI, +} from "../../pages/solutionReportPage/utils/gitHubLogin"; +import useSetUser from "./useSetUser"; +import { useState } from "react"; +import useUserValue from "./useUserValue"; + +const useUserLogin = () => { + const [isLoggedIn, setIsLoggedIn] = useState(false); + const userInfo = useUserValue(); + const setUserInfo = useSetUser(); + const requestLogin = (code) => { + requestAccessTokenAPI(code) + .then((response) => requestLoginAPI(response.access_token)) + .then((response) => { + if (response.hasOwnProperty("login")) { + setIsLoggedIn(true); + setUserInfo(response); + } + if (userInfo) setIsLoggedIn(true); + }); + }; + return { isLoggedIn, requestLogin }; +}; +export default useUserLogin; diff --git a/src/hooks/user/useUserProfile.js b/src/hooks/user/useUserProfile.js new file mode 100644 index 0000000..d5ae9ea --- /dev/null +++ b/src/hooks/user/useUserProfile.js @@ -0,0 +1,11 @@ +import useUserValue from "./useUserValue"; + +const useUserProfile = () => { + const user = useUserValue(); + return { + profileImg: user.avatar_url ?? "", + username: user.name ?? "", + gitHubUrl: user.html_url ?? "", + }; +}; +export default useUserProfile; diff --git a/src/hooks/user/useUserValue.js b/src/hooks/user/useUserValue.js new file mode 100644 index 0000000..7db3079 --- /dev/null +++ b/src/hooks/user/useUserValue.js @@ -0,0 +1,7 @@ +import { useRecoilValue } from "recoil"; +import userState from "../../state/user"; + +const useUserValue = () => { + return useRecoilValue(userState); +}; +export default useUserValue; From 46c8beb00e180a902d6e1b1d0f5723abe53792b1 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Wed, 20 Jul 2022 19:02:43 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=A7=81=20=EB=B0=8F=20API=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solutionReportPage/utils/gitHubLogin.js | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/pages/solutionReportPage/utils/gitHubLogin.js b/src/pages/solutionReportPage/utils/gitHubLogin.js index a0e7408..e2e39b6 100644 --- a/src/pages/solutionReportPage/utils/gitHubLogin.js +++ b/src/pages/solutionReportPage/utils/gitHubLogin.js @@ -2,26 +2,34 @@ export const LOGIN_URL = "https://github.com/login/oauth/authorize?client_id=" + process.env.REACT_APP_CLIENT_ID; -export const requestAccessToken = async (code) => { - const client_secret = process.env.REACT_APP_CLIENT_SECRET; - const client_id = process.env.REACT_APP_CLIENT_ID; - const response = await fetch( - `https://github.com/login/oauth/access_token?client_id=${client_id}&client_secret=${client_secret}&code=${code}`, - { - method: "POST", +export const requestAccessTokenAPI = async (code) => { + try { + const client_secret = process.env.REACT_APP_CLIENT_SECRET; + const client_id = process.env.REACT_APP_CLIENT_ID; + const response = await fetch( + `https://github.com/login/oauth/access_token?client_id=${client_id}&client_secret=${client_secret}&code=${code}`, + { + method: "POST", + headers: { + Accept: "application/json", + }, + } + ); + return response.json(); + } catch (e) { + console.log(e); + } +}; +export const requestLoginAPI = async (access_token) => { + try { + const userInfo = await fetch("https://api.github.com/user", { headers: { - Accept: "application/json", + Accept: "application/vnd.github+json", + Authorization: `token ${access_token}`, }, - } - ); - return response.json(); -}; -export const requestLogin = async (access_token) => { - const userInfo = await fetch("https://api.github.com/user", { - headers: { - Accept: "application/vnd.github+json", - Authorization: `token ${access_token}`, - }, - }); - return userInfo.json(); + }); + return userInfo.json(); + } catch (e) { + console.log(e); + } }; From 728f895159940d55b37199528fe4d1f888a21121 Mon Sep 17 00:00:00 2001 From: codeisneverodd Date: Wed, 20 Jul 2022 19:04:12 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EA=B2=80=EC=83=89=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A3=BC=EC=84=9D=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solutionReportPage/SolutionReport.js | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/pages/solutionReportPage/SolutionReport.js b/src/pages/solutionReportPage/SolutionReport.js index b8c0a18..edf02ed 100644 --- a/src/pages/solutionReportPage/SolutionReport.js +++ b/src/pages/solutionReportPage/SolutionReport.js @@ -2,42 +2,33 @@ import { useEffect, useState } from "react"; import styled from "styled-components"; import Header from "../../components/Header"; import { - ThanksMsg, - OtherReportBtn, + InputLabel, MainContetnWrapper, + OtherReportBtn, StepByStepInputItem, - InputLabel, - TextInput, - QuestionList, - QuestionItem, - QuestionBtn, - TextArea, SubmitBtn, + TextArea, + TextInput, + ThanksMsg, } from "../../style/styledComponents"; import gitHubLogoSrc from "../../images/github-logo-white.png"; import { useSearchParams } from "react-router-dom"; -import { - LOGIN_URL, - requestAccessToken, - requestLogin, -} from "./utils/gitHubLogin"; +import { LOGIN_URL } from "./utils/gitHubLogin"; +import useUserProfile from "../../hooks/user/useUserProfile"; +import useUserLogin from "../../hooks/user/useUserLogin"; export default function SolutionReport() { const [submitted, setSubmitted] = useState(false); const [questionName, setQuestionName] = useState(""); const [detailContent, setDetailContent] = useState(""); const [searchParams, setSearchParams] = useSearchParams(); - const [userInfo, setUserInfo] = useState({}); + const userInfo = useUserProfile(); + const { isLoggedIn, requestLogin } = useUserLogin(); useEffect(() => { if (searchParams.get("code")) { const code = searchParams.get("code"); - requestAccessToken(code) - .then((response) => requestLogin(response.access_token)) - .then((response) => { - setUserInfo(response); - console.log(response); - }); + requestLogin(code); } }, [searchParams]); const handleGitHubLogin = async () => {}; @@ -45,7 +36,6 @@ export default function SolutionReport() { const isSubmitBtnDisabled = detailContent === ""; function handleOtherSolutionBtnClick() { - console.log("!"); setSubmitted(false); setQuestionName(""); setDetailContent(""); @@ -117,8 +107,11 @@ export default function SolutionReport() { <> 기여자 등록 - {userInfo.hasOwnProperty("avatar_url") ? ( - + {isLoggedIn ? ( + + 이름: {userInfo.username} + 이미지: {userInfo.profileImg} + ) : ( Date: Wed, 20 Jul 2022 19:19:15 +0900 Subject: [PATCH 12/12] =?UTF-8?q?feat:=20env=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 -- .gitignore | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 9bf315f..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -REACT_APP_CLIENT_ID=c313b0e560ae722655f1 -REACT_APP_CLIENT_SECRET=f1f8dc2e62bff607b1fd7478511ae67ca412c12a diff --git a/.gitignore b/.gitignore index f661b37..e1cc852 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules + .env + .env.development .idea