Skip to content

Commit

Permalink
Merge pull request #90 from 2022-2-Graduation-Project/feature/86-user…
Browse files Browse the repository at this point in the history
…-screen

[#86] fix: fix GET error
  • Loading branch information
hee-suh authored Mar 15, 2023
2 parents 36b7e7e + ce377c8 commit 8990e22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 9 additions & 5 deletions bowwowcare/src/context/ThemeProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext, useState, useEffect } from "react";
import userService from "../services/user.service";
import { isLogin } from "../utils/isLogin";

export const ThemeContext = createContext({});

Expand All @@ -8,14 +9,17 @@ function ThemeProvider({ children }) {
const [myTheme, setMyTheme] = useState(0);
const [ThemeMode, setThemeMode] = useState(theme[0]);


useEffect(() => {
userService.getUserBoard().then((response) => {
if(response.status === 200) {
const user = response.data;
setMyTheme(user.theme);
if(isLogin()){
userService.getUserBoard().then((response) => {
if(response.status === 200) {
const user = response.data;
setMyTheme(user.theme);
}
}
).catch((e) => {console.log(e.response.data)})
}
).catch((e) => {console.log(e.response.data)})
},[]);

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions bowwowcare/src/utils/isLogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isLogin = () => !!localStorage.getItem("user");
3 changes: 2 additions & 1 deletion bowwowcare/src/views/HomePage/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
import axios from "axios";
import { API_URL } from "../../Config";
import authHeader from "../../services/auth-header";
import { isLogin } from "../../utils/isLogin";

import Header from "../../components/Header";
import PetList from "./PetList/PetList";
Expand Down Expand Up @@ -39,7 +40,7 @@ function HomePage() {
};

useEffect(() => {
getPetList();
isLogin() && getPetList();
}, []);

return (
Expand Down

0 comments on commit 8990e22

Please sign in to comment.