Skip to content

Commit

Permalink
Merge: merge feature/126 to main
Browse files Browse the repository at this point in the history
Feat: implement username using recoil #126
  • Loading branch information
hummingbbird authored May 28, 2024
2 parents 5bbaa29 + 5e50227 commit c49d3b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pages/MainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import TagImgList from "../components/common/TagImgList";
import AddTripDialog from "../components/common/AddTripDialog";
import { React, useEffect, useState } from "react";
import { useRecoilState } from "recoil";
import { dialogState } from "../recoil/commonState";
import { dialogState, userNameState } from "../recoil/commonState";
import BottomNav from "../layout/BottomNav";
import axios from "axios";

const MainPage = () => {
//db에서 get 해온 username or recoil에 저장한 내 정보
const dummyName = "^get예정^";
const [userName, setUserName] = useRecoilState(userNameState);

const [dialog, setDialog] = useRecoilState(dialogState);
const handleOpen = () => {
Expand All @@ -23,6 +24,16 @@ const MainPage = () => {
const [tagNames, setTagNames] = useState([]);
const [tagImages, setTagImages] = useState([]);

useEffect(() => {
axios.get("http://localhost:5000/user", { withCredentials: true})
.then((res) => {
setUserName(res.data.userinfo.name);
})
.catch((error) => {
console.log(error);
});
}, []);

useEffect(() => {
axios.get("http://localhost:5000/tag", { withCredentials: true})
.then((res) => {
Expand All @@ -45,7 +56,7 @@ const MainPage = () => {
return (
<StMainPage>
<IntroDiv>
<HiP>{dummyName}님&nbsp;반가워요!</HiP>
<HiP>{userName}님&nbsp;반가워요!</HiP>
<WelcomeP>트립토리와 함께 여행을 기록해요.</WelcomeP>
</IntroDiv>
<MainDiv>
Expand Down
4 changes: 4 additions & 0 deletions src/recoil/commonState.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export const diaryIdState = atom ({
default: "",
});

export const userNameState = atom ({
key: "userName",
default: "",
});

0 comments on commit c49d3b2

Please sign in to comment.