Skip to content

Commit

Permalink
Merge pull request #108 from Goldchae/apiTest
Browse files Browse the repository at this point in the history
Api test
  • Loading branch information
Goldchae authored Sep 10, 2024
2 parents 7ef7675 + adf69e3 commit 5f6d969
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 113 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BASE_URL = https://api.kaboo.site:8081
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-markdown": "^9.0.1",
"react-query": "^3.39.3",
"react-router-dom": "^6.26.1",
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
Expand Down
20 changes: 13 additions & 7 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { useState } from "react";
import {
BrowserRouter as Router,
Routes,
Route,
Link,
useLocation,
} from "react-router-dom";
import Header from "./components/Common/Header";
import HomeMain from "./pages/homepages/HomeMain";
import GlobalStyle from "./components/Common/GlobalStyle";
import { PeopleListPage } from "./pages/PeopleListPage/PeopleListPage.jsx";
import { PeopleDetailPage } from "./pages/PeopleDetailPage/PeopleDetailPage.jsx";
import ChatPage from "./pages/chat/ChatPage";
import KakaoLogin from "./pages/join/KakaoLogin.jsx";
import KakaoRedirect from "./pages/join/KakoRedirect.jsx";
import JoinPage from "./pages/join/JoinPage.jsx";
import RTCPage from "./pages/WebRTC/VideoPage.jsx";
import LoginPage from "./pages/LoginPage.jsx";
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from 'react-query';
import { PeopleListPage } from './pages/PeopleListPage/PeopleListPage.jsx';
import { PeopleDetailPage } from './pages/PeopleDetailPage/PeopleDetailPage.jsx';
import ChatPage from './pages/chat/ChatPage';
import RTCPage from './pages/VideoPage';
import LoginPage from "./pages/kakaologin/LoginPage.jsx";
// QueryClient 인스턴스 생성
const queryClient = new QueryClient();

function App() {
return (
<QueryClientProvider client={queryClient}>
<Router>
<Routes>
<Route path="/" element={<PeopleListPage />}></Route>
Expand All @@ -31,6 +36,7 @@ function App() {
<Route path="/join" element={<JoinPage />} />
</Routes>
</Router>
</QueryClientProvider>
);
}

Expand Down
13 changes: 5 additions & 8 deletions src/components/Common/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ function Header() {
<styles.HeaderSubContainer>
<styles.LogoWrapper
onClick={() => {
navigate("/list");
navigate("/");
}}
>
<styles.Logo src={logo} alt="Logo" />
<styles.ServiceName>카부커넥션</styles.ServiceName>
</styles.LogoWrapper>

<styles.NavBar>
<styles.NavItem href="/list">카부 게시판</styles.NavItem>
<styles.NavItem href="/list">카부 프로젝트</styles.NavItem>
<styles.NavItem href="/list">카부 편의</styles.NavItem>
<styles.NavItem href="/">카부 게시판</styles.NavItem>
<styles.NavItem href="/login">카부 프로젝트</styles.NavItem>
<styles.NavItem href="/">카부 편의</styles.NavItem>
<styles.NavItem href="/chat">카부 커넥션</styles.NavItem>
</styles.NavBar>
</styles.HeaderSubContainer>
<styles.PeopleLogoWrapper>
<styles.PeopleLogo src={peoplelogo}
onClick={() => {
navigate("/login");
}}/>
<styles.PeopleLogo src={peoplelogo} />
</styles.PeopleLogoWrapper>
</styles.HeaderContainer>
);
Expand Down
48 changes: 33 additions & 15 deletions src/pages/PeopleDetailPage/PeopleDetailPage.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import React from "react";
import React, { useEffect, useState } from "react";
import Layout from "../../components/Common/Layout.jsx";
import RoundBox from "../../components/Common/RoundBox.jsx";
import MarkdownEditor from "../../components/PeopleDetailComponents/MarkdownEditor/MarkdownEditor.jsx";
import Line from "../../components/Common/Line/Line.jsx"
import {ColumnContainer, TeamTextStyle,RowContainer} from "./PeopleDetailPage.style.js"
import Text from "../../components/Common/Text.jsx"
import ImageCircle from "../../components/PeopleDetailComponents/CircleImage/CircleImage.jsx"
import Line from "../../components/Common/Line/Line.jsx";
import { ColumnContainer, TeamTextStyle, RowContainer } from "./PeopleDetailPage.style.js";
import Text from "../../components/Common/Text.jsx";
import ImageCircle from "../../components/PeopleDetailComponents/CircleImage/CircleImage.jsx";
import {TalkButton} from "../../components/PeopleDetailComponents/TalkButton/TalkButton.jsx";
import {LogoutButton} from "../../components/PeopleDetailComponents/LogoutButton/LogoutButton.jsx";
import fetchMemberByName from '../../services/fetchMemberByName.js';

export const PeopleDetailPage = () => {
const myPage = true; // 임시
const [member, setMember] = useState({});
const myPage = true;

useEffect(() => {
const loadMemberData = async () => {
try {
const response = await fetchMemberByName();
if (response.data.success) {
setMember(response.data.data);
} else {
console.error('member data 로드 실패:', response.data.message);
}
} catch (error) {
console.error("'member data 로드 에러", error.message);
}
};

//loadMemberData();
}, []);

return (
<Layout>
<br></br><br></br><br></br>
<div className="spacing-top" />
<RoundBox width="70%" height="1000px" borderRadius="20px">
<RowContainer>
<ImageCircle imageUrl="src/assets/dummyImages/peopleList3.png" />
Expand All @@ -41,15 +60,14 @@ export const PeopleDetailPage = () => {
/>
</RowContainer>
</ColumnContainer>
{ myPage ? <LogoutButton/> : <TalkButton/>} {/*내 페이지 / 다른 사람 페이지 구분*/}
{myPage ? <LogoutButton /> : <TalkButton />}
</RowContainer>

<Line width = "95%"/>
<br/>

<MarkdownEditor/>
<Line width="95%" />
<MarkdownEditor />
</RoundBox>
<br></br><br></br><br></br>
<div className="spacing-bottom" />
</Layout>
);
};
};

export default PeopleDetailPage;
136 changes: 53 additions & 83 deletions src/pages/PeopleListPage/PeopleListPage.jsx
Original file line number Diff line number Diff line change
@@ -1,91 +1,61 @@
import React from "react";
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import Layout from "../../components/Common/Layout.jsx";
import MiniLayout from "../../components/Common/miniLayout.jsx";
import PeopleCard from "../../components/PeopleListComponents/PeopleCard/peopleCard.jsx";
import fetchMembersList from "../../services/fetchMembersList.js";
import dummyImages1 from "../../assets/dummyImages/peopleList.jpeg"

export const PeopleListPage = () => {
const navigate = useNavigate();
const handleCardClick = () => {
navigate('/details');
};
const navigate = useNavigate();
const [members, setMembers] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);

return (
<Layout>
<MiniLayout text="카부인 전당" layerWidth="80%">
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList.jpeg" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
<PeopleCard
image="src/assets/dummyImages/peopleList2.png" // 더미이미지
name="celina.jung (정은체)" // 임시 하드코딩
affiliation="카카오 부트캠프 1기 : AI"
onClick={handleCardClick}
/>
</MiniLayout>
</Layout>
);
useEffect(() => {
const displayMembers = async () => {
setIsLoading(true);
try {
const membersData = await fetchMembersList();
console.log('Fetched Members:', membersData.data); // 데이터 구조를 확인하기 위해 콘솔에 출력
if (membersData && membersData.data && membersData.data.memberList) {
setMembers(membersData.data.memberList);
} else {
console.error('Invalid data structure:', membersData);
setMembers([]); // 데이터 구조가 올바르지 않을 경우 빈 배열 설정
}
setIsLoading(false);
} catch (error) {
console.error('Failed to fetch members:', error);
setError(error);
setIsLoading(false);
}
};

displayMembers();
}, []);
;

const handleCardClick = () => {
navigate('/details');
};

if (isLoading) return <div>로딩 중...</div>;
if (error) return <div>에러 발생: {error.message}</div>;

return (
<Layout>
<MiniLayout text="카부인 전당" layerWidth="80%">
{members.map((member, index) => (
<PeopleCard
key={index}
image={dummyImages1} // 임시 이미지
name={`${member.englishName} (${member.koreaName})`}
affiliation={`카카오 부트캠프 1기 : ${member.course}`}
onClick={handleCardClick}
/>
))}
</MiniLayout>
</Layout>
);
};
30 changes: 30 additions & 0 deletions src/pages/kakaologin/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

function LoginPage() {
const handleLogin = () => {
try {
console.log('Attempting to redirect to OAuth provider...');

// Redirection URL 로그 추가
// const redirectUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${kakaoClientId}&redirect_uri=${redirectUri}&response_type=code`;
const redirectUrl = "http://localhost:8081/oauth2/authorization/kakao";
console.log('Redirect URL:', redirectUrl);

window.location.href = redirectUrl;
console.log('Redirection triggered.');
} catch (error) {
console.error('Error during redirection:', error);
}
};



return (
<div>
<h2>Login Page</h2>
<button onClick={handleLogin}>Login with kakao</button>
</div>
);
}

export default LoginPage;
20 changes: 20 additions & 0 deletions src/services/fetchMemberByName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { instance } from './../api/instance.js';

const fetchMemberByName = async (koreanName) => {
try {
const encodedName = encodeURIComponent(koreanName);
const response = await instance.get(`/api/auth/member?name=${encodedName}`);
console.log('Received response:', response);

if (response.data.success) {
return response.data.data;
} else {
throw new Error(response.data.message || "Failed to fetch member data");
}
} catch (error) {
console.error("Error fetching member data:", error.message);
throw error;
}
};

export default fetchMemberByName;
18 changes: 18 additions & 0 deletions src/services/fetchMembersList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {instance} from './../api/instance.js';

const fetchMembersList = async () => {
try {
const cookies = document.cookie;
console.log('Sending cookies:', cookies);

const response = await instance.get('api/auth/member/all', {
});
console.log('들어오는 응답',response);
return response;
} catch (error) {
console.error("Error fetching chat list!:", error.message);
throw error;
}
};

export default fetchMembersList;

0 comments on commit 5f6d969

Please sign in to comment.