Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 로그인 로직 수정 및 미흡한 API 연결 수정 #78

Merged
merged 21 commits into from
Jun 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4ee60fa
refactor: 토큰 관리 로직 수정 (#77)
AAminha Jun 3, 2024
2144f44
design: 80% 적용 (#77)
AAminha Jun 3, 2024
b193bb5
fix: 푸터 스타일 오류 수정 및 하단 사이트 이동 방식 수정 (#77)
AAminha Jun 4, 2024
16ec99c
fix: 네비게이션 디자인 수정 및 마이페이지 연결 (#77)
AAminha Jun 4, 2024
032e4d6
fix: 토큰 관리 방식 및 라우팅 제한 방식 수정 (#77)
AAminha Jun 4, 2024
45878b5
fix: 프로그램 링크 이동 방식 수정 (#77)
AAminha Jun 4, 2024
4e87801
design: 로그인 페이지 & 온보딩 페이지 디자인 수정 (#77)
AAminha Jun 4, 2024
a17f19d
fix: 마이페이지 구조 및 디자인 수정 (#77)
AAminha Jun 4, 2024
713b3c1
fix: 브랜드 관리 뷰 수정 (#77)
AAminha Jun 4, 2024
a0bdcb5
feat: 마이페이지 환경설정 부분 수정 및 TopNavigation 높이 수정 (#77)
AAminha Jun 5, 2024
f72065b
fix: 자기이해 홈에서 Discover 결과뷰 수정 및 api 오류 수정 (#77)
AAminha Jun 5, 2024
eb6737a
fix: styled-components 에러 수정 (#77)
AAminha Jun 5, 2024
06ea1e9
refactor: Define 테스트 페이지 리팩토링 (#77)
AAminha Jun 5, 2024
ff0babc
fix: Define 테스트 중 진행 중인 페이지로 이동하는 로직 오류 수정 (#77)
AAminha Jun 7, 2024
6a82900
fix: Discover 결과 페이지 조회 로직 수정 (#77)
AAminha Jun 7, 2024
ce74916
fix: 전시회를 위해 임시 라우팅 (#77)
AAminha Jun 7, 2024
905399c
fix: Discover 조회 방식 수정 (#77)
AAminha Jun 7, 2024
40d8f2c
fix: Discover 채팅 내용 중 줄바꿈은 다른 말풍선으로 보이도록 수정 (#77)
AAminha Jun 7, 2024
980482e
refactor: 챗봇 로직 리팩토링 (#77)
AAminha Jun 7, 2024
d7c7a7b
Merge branch 'develop' of https://github.com/KUSITMS-29th-TEAM-D/Fron…
AAminha Jun 7, 2024
4cca9b5
design: 테스트는 zoom 기본으로 수정 (#77)
AAminha Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Discover 결과 페이지 조회 로직 수정 (#77)
AAminha committed Jun 7, 2024
commit 6a82900a4172d2ab639fd20cfd3b2187a03f5002
11 changes: 5 additions & 6 deletions src/apis/personaAPI.ts
Original file line number Diff line number Diff line change
@@ -77,14 +77,13 @@ export const personaAPI = {
return response.data;
},

// Discover 페르소나 키워드 전체 조회
getDiscoverAllKeyword: async () => {
const response = await authClient.get('/api/personas/discover/all-keywords');
return response.data;
},

// Discover 페르소나 키워드 카테고리별 조회
getDiscoverCategoryKeyword: async (category: string) => {
if (category === 'all') {
const response = await authClient.get('/api/personas/discover/all-keywords');
return response.data;
}

const response = await authClient.get(
`/api/personas/discover/keywords?category=${CATEGORY_TYPE[category].title}`
);
113 changes: 57 additions & 56 deletions src/components/DiscoverResultPage/ResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';

import { useNavigate } from 'react-router-dom';
import styled, { css } from 'styled-components';

import { personaAPI } from '@/apis/personaAPI';
import { SummaryCard } from '@/components/DiscoverTestPage/SummaryCard';
import { CategoryButton } from '@/components/common/Button/CategoryButton';
import { PlainButton } from '@/components/common/Button/PlainButton';
import { useGetDiscoverKeywordResult } from '@/hooks/useGetDiscoverResult';
import { userService } from '@/services/UserService';
import { moveDown, moveLeft, moveRight, moveUp } from '@/styles';

const CATEGORY_LIST: { [key: string]: string } = {
export const DISCOVER_CATEGORY_LIST: { [key: string]: string } = {
all: '전체',
health: '건강',
career: '커리어',
@@ -20,17 +19,16 @@ const CATEGORY_LIST: { [key: string]: string } = {

export const ResultView = ({ showSummary = false }: { showSummary?: boolean }) => {
const [selectedCategory, setSelectedCategory] = useState<string>('all');
const [categoryKeywords, setCategoryKeywords] = useState<{ [key: string]: string[] }>({
all: [],
health: [],
career: [],
love: [],
leisure: [],
});
const [summary, setSummary] = useState<{ [key: string]: string[] } | undefined>(undefined);
const navigate = useNavigate();

useEffect(() => {
const { data: allKeywords, loading: allKeywordsLoading } = useGetDiscoverKeywordResult();

if (allKeywordsLoading) {
return <div>Loading...</div>;
}

/* useEffect(() => {
const fetchAllKeywords = async () => {
try {
const response = await personaAPI.getDiscoverAllKeyword();
@@ -51,9 +49,9 @@ export const ResultView = ({ showSummary = false }: { showSummary?: boolean }) =
fetchAllKeywords();
fetchSummary();
}, []);
}, []); */

useEffect(() => {
/*useEffect(() => {
const fetchCategoryKeywords = async (category: string) => {
if (categoryKeywords[category]) {
try {
@@ -71,7 +69,7 @@ export const ResultView = ({ showSummary = false }: { showSummary?: boolean }) =
if (selectedCategory !== 'all') {
fetchCategoryKeywords(selectedCategory);
}
}, [selectedCategory, categoryKeywords]);
}, [selectedCategory, categoryKeywords]); */

return (
<StyledContainer $showSummary={showSummary}>
@@ -84,38 +82,39 @@ export const ResultView = ({ showSummary = false }: { showSummary?: boolean }) =
은, 이런 사람이에요.
</div>
<StyledChipContainer>
{Object.keys(CATEGORY_LIST).map((category) => (
{Object.keys(DISCOVER_CATEGORY_LIST).map((category) => (
<CategoryButton
key={category}
active={selectedCategory === category}
onClick={() => setSelectedCategory(category)}
>
{CATEGORY_LIST[category]}
{DISCOVER_CATEGORY_LIST[category]}
</CategoryButton>
))}
</StyledChipContainer>
</StyledHeader>
<StyledContent>
{categoryKeywords[selectedCategory].length !== 0 ? (
<div className="result">
{showSummary && (
<div className="description">
<span className="highlight">상위 6개</span>만 보여주고 있어요!
</div>
)}
<BubbleSection $noResult={categoryKeywords[selectedCategory].length === 0}>
{categoryKeywords[selectedCategory].map((keyword, index) => (
<StyledBubble key={keyword} className={`b${index}`} $weight={1 - 0.1 * index}>
<span>{keyword}</span>
</StyledBubble>
))}
</BubbleSection>
{!showSummary && (
<div className="description">
<span className="highlight">상위 6개</span>만 보여주고 있어요!
</div>
)}
{showSummary && (
{allKeywords && (
<StyledContent>
{allKeywords[selectedCategory].length !== 0 ? (
<div className="result">
{showSummary && (
<div className="description">
<span className="highlight">상위 6개</span>만 보여주고 있어요!
</div>
)}
<BubbleSection $noResult={allKeywords[selectedCategory].length === 0}>
{allKeywords[selectedCategory].map((keyword, index) => (
<StyledBubble key={keyword} className={`b${index}`} $weight={1 - 0.1 * index}>
<span>{keyword}</span>
</StyledBubble>
))}
</BubbleSection>
{!showSummary && (
<div className="description">
<span className="highlight">상위 6개</span>만 보여주고 있어요!
</div>
)}
{/* {showSummary && (
<ResultSection>
<div className="title">{`${userService.getUserNickname()}님과의 대화한 내용을 요약했어요!`}</div>
<div className="card-container">
@@ -140,24 +139,26 @@ export const ResultView = ({ showSummary = false }: { showSummary?: boolean }) =
))}
</div>
</ResultSection>
)}
</div>
) : (
<div className="no-result">
<NoResultText>
<div className="title">
아직 <span className="highlight">{CATEGORY_LIST[selectedCategory]}</span> 테스트를
완료하지 않았어요!
</div>
<div className="subtitle">남은 테스트를 진행해주세요.</div>
</NoResultText>
<StyledNoBubble>
<span>?</span>
</StyledNoBubble>
</div>
)}
</StyledContent>
{categoryKeywords[selectedCategory].length === 0 && (
)} */}
</div>
) : (
<div className="no-result">
<NoResultText>
<div className="title">
아직{' '}
<span className="highlight">{DISCOVER_CATEGORY_LIST[selectedCategory]}</span>{' '}
테스트를 완료하지 않았어요!
</div>
<div className="subtitle">남은 테스트를 진행해주세요.</div>
</NoResultText>
<StyledNoBubble>
<span>?</span>
</StyledNoBubble>
</div>
)}
</StyledContent>
)}
{allKeywords && allKeywords[selectedCategory].length === 0 && (
<PlainButton
width="376px"
height="48px"
30 changes: 4 additions & 26 deletions src/components/SelfUnderstandPage/DiscoverResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import { useEffect, useState } from 'react';

import axios from 'axios';

import { personaAPI } from '@/apis/personaAPI';
import { ResultView } from '@/components/DiscoverResultPage/ResultView';
import { NoResultSection } from '@/components/SelfUnderstandPage/NoResultTemplate';
import { userService } from '@/services/UserService';
import { useGetDiscoverResult } from '@/hooks/useGetDiscoverResult';

export const DiscoverResultView = () => {
const [isTest, setIsTest] = useState(false);

useEffect(() => {
const fetchAllKeywords = async () => {
try {
await personaAPI.getDiscoverAllKeyword();
setIsTest(true);
} catch (error) {
if (axios.isAxiosError(error) && error.response && error.response.status === 404) {
setIsTest(false);
}
}
};
const { loading, error, isTest } = useGetDiscoverResult();

if (userService.getUserState() === 'MEMBER') {
fetchAllKeywords();
}
}, []);
if (loading || error) return null;

if (isTest) {
return <ResultView />;
}
if (isTest) return <ResultView />;

return <NoResultSection tab="Discover" />;
};
107 changes: 107 additions & 0 deletions src/hooks/useGetDiscoverResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { useEffect, useState } from 'react';

import { personaAPI } from '@/apis/personaAPI';
import { DISCOVER_CATEGORY_LIST } from '@/components/DiscoverResultPage/ResultView';
import { userService } from '@/services/UserService';

export const useGetDiscoverResult = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [isTest, setIsTest] = useState(false);
const userState = userService.getUserState();

useEffect(() => {
const fetchKeywords = async () => {
setLoading(true);
try {
const response = await personaAPI.getDiscoverCategoryKeyword('all');
if (response.payload.keywords.length > 0) {
setIsTest(true);
}
} catch (error) {
setError(true);
} finally {
setLoading(false);
}
};

if (userState === 'MEMBER') {
fetchKeywords();
}
}, []);

return { loading, error, isTest };
};

export const useGetDiscoverKeywordResult = () => {
const [data, setData] = useState<{ [key: keyof typeof DISCOVER_CATEGORY_LIST]: string[] }>({
all: [],
health: [],
career: [],
love: [],
leisure: [],
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);

useEffect(() => {
const fetchKeywords = async () => {
setLoading(true);
try {
const responses = await Promise.allSettled(
Object.keys(DISCOVER_CATEGORY_LIST).map((category) =>
personaAPI.getDiscoverCategoryKeyword(category)
)
);

const updatedData: { [key: keyof typeof DISCOVER_CATEGORY_LIST]: string[] } = {};

responses.forEach((response, index) => {
const categoryKey = Object.keys(DISCOVER_CATEGORY_LIST)[index];
console.log('Category:', categoryKey, 'Response:', response);
if (response.status === 'fulfilled' && categoryKey) {
updatedData[categoryKey] = response.value.payload.keywords;
}
});

setData((prevData) => ({
...prevData,
...updatedData,
}));
} catch (error) {
setError(true);
} finally {
setLoading(false);
}
};

fetchKeywords();
}, []);

return { data, loading, error };
};

export const useGetDiscoverSummary = () => {
//
const [data, setData] = useState<string[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);

useEffect(() => {
const fetchSummary = async () => {
setLoading(true);
try {
const response = await personaAPI.getDefaultSummary();
setData(response.payload.summary);
} catch (error) {
setError(true);
} finally {
setLoading(false);
}
};

fetchSummary();
}, []);

return { data, loading, error };
};