Skip to content

Commit

Permalink
Merge pull request #107 from capstone-five-ai/develop
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
AAminha authored Jun 3, 2024
2 parents 800aa87 + 85d839b commit 0e308af
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
23 changes: 10 additions & 13 deletions src/components/Navigation/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ import AnnouncementTooltip from '@/components/Tooltip/AnnouncementTooltip';
import { HEADER_MENU_LIST } from '@/constants';
import authState from '@/recoils/atoms/authState';
import tooltipState from '@/recoils/atoms/tooltipState';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
import styled, { css } from 'styled-components';

function MenuBar() {
const isAuthenticated = useRecoilValue(authState);
const location = useLocation();
const [showTooltip, setShowTooltip] = useRecoilState(tooltipState);
const [, setShowTooltip] = useRecoilState(tooltipState);
const [showModal, setShowModal] = useState(false);
const navigate = useNavigate();
const lastMajorPath = useRef('');

useEffect(() => {
const majorPaths = ['quiz', 'summary', 'management'];
const majorPaths = ['/quiz', '/summary', '/management'];
const isMajorPath = majorPaths.some((path) =>
location.pathname.startsWith(`${path}`)
location.pathname.startsWith(path)
);
const currentPath = location.pathname.split('/')[1];

if (isMajorPath) {
let timeout: number;
if (isMajorPath && lastMajorPath.current !== currentPath) {
setShowTooltip(true);
timeout = setTimeout(() => {
setShowTooltip(false);
}, 2000);

return () => clearTimeout(timeout);
lastMajorPath.current = currentPath;
}
}, [location.pathname]);
}, [location, setShowTooltip]);

const isActivePath = (menuPath: string) => {
const currentPath = location.pathname;
Expand Down Expand Up @@ -65,7 +62,7 @@ function MenuBar() {
<StyledActiveIcon $isActive={isActivePath(menu.path)} />
</StyledMenuButton>
))}
{showTooltip && <AnnouncementTooltip />}
<AnnouncementTooltip />
</StyledContainer>
</>
);
Expand Down
40 changes: 31 additions & 9 deletions src/components/Tooltip/AnnouncementTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import TooltipTail from '@/assets/images/tooltip-tail.svg';
import tooltipState from '@/recoils/atoms/tooltipState';
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import styled, { keyframes } from 'styled-components';

function AnnouncementTooltip() {
const [show, setShow] = useState(true);
const [showTooltip, setShowTooltip] = useRecoilState(tooltipState);
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
setTimeout(() => {
setShow(false);
}, 5000);
}, []);
if (showTooltip) {
setIsVisible(true);
// Reset timeout to hide tooltip state after all animations have completed
const timeout = setTimeout(() => {
setShowTooltip(false);
}, 4000);
return () => clearTimeout(timeout);
}
}, [showTooltip, setShowTooltip]);

useEffect(() => {
if (isVisible) {
const fadeOutTimeout = setTimeout(() => {
setIsVisible(false);
}, 3700);
return () => clearTimeout(fadeOutTimeout);
}
}, [isVisible]);

return (
<StyledContainer $isVisible={show}>
<StyledContainer $showTooltip={showTooltip} $isVisible={isVisible}>
<StyledInnerContainer>
<TooltipText>생성 후에는 여기서 편집이 가능해요!</TooltipText>
</StyledInnerContainer>
Expand All @@ -25,7 +42,7 @@ export default AnnouncementTooltip;
const fadeIn = keyframes`
from {
opacity: 0;
transform: translateY(-20px);
transform: translateY(-5px);
}
to {
opacity: 1;
Expand All @@ -40,11 +57,16 @@ const fadeOut = keyframes`
}
to {
opacity: 0;
transform: translateY(-20px);
transform: translateY(-5px);
}
`;

const StyledContainer = styled.div<{ $isVisible: boolean }>`
const StyledContainer = styled.div<{
$showTooltip: boolean;
$isVisible: boolean;
}>`
display: ${(props) =>
props.$showTooltip ? 'block' : 'none'}; /* display 관리 추가 */
opacity: 0;
animation: ${(props) => (props.$isVisible ? fadeIn : fadeOut)} 0.3s
ease-in-out forwards;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/CategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function CategoryPage() {
redirect('/management/category');
}, [type, fetchedQuizCategoryList, fetchedSummaryCategoryList]);

if (!fetchedQuizCategoryList || !fetchedSummaryCategoryList) return null;

if (
!type &&
(fetchedQuizCategoryList?.data?.length || 0) +
Expand Down
30 changes: 13 additions & 17 deletions src/pages/HistoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@ interface HistoryPageType {

const HistoryPage = () => {
const [filter, setFilter] = useState<ServiceType>('QUIZ');
const [quizzes, setQuizzes] = useState<HistoryPageType>({
histories: [],
totalPages: 0,
});
const [summaries, setSummaries] = useState<HistoryPageType>({
histories: [],
totalPages: 0,
});
const [quizes, setQuizes] = useState<HistoryPageType>();
const [summaries, setSummaries] = useState<HistoryPageType>();

const getQuizzes = async (quizPage: number) => {
const getQuizes = async (quizPage: number) => {
const response = await getAIQuizAllFile(quizPage);
const newHistories = response.content.map((item: HistoryType) =>
item.dtype === 'PROBLEM' ? { ...item, dtype: 'QUIZ' } : item
);

setQuizzes({ histories: newHistories, totalPages: response.totalPages });
setQuizes({ histories: newHistories, totalPages: response.totalPages });
};

const getSummaries = async (summaryPage: number) => {
Expand All @@ -41,21 +35,23 @@ const HistoryPage = () => {

const updateList = useCallback(
(updatePage: number) => {
if (filter === 'QUIZ') getQuizzes(updatePage);
if (filter === 'QUIZ') getQuizes(updatePage);
if (filter === 'SUMMARY') getSummaries(updatePage);
},
[filter]
);

useEffect(() => {
getQuizzes(1);
getQuizes(1);
getSummaries(1);
}, []);

if (!quizes || !summaries) return null;

return (
<Wrapper>
<Header>
{(filter === 'QUIZ' && quizzes.histories.length > 0) ||
{(filter === 'QUIZ' && quizes.histories.length > 0) ||
(filter === 'SUMMARY' && summaries.histories.length > 0) ? (
<Title>
<Typography variant="button">
Expand All @@ -65,7 +61,7 @@ const HistoryPage = () => {
) : (
<div />
)}
{quizzes.histories.length + summaries.histories.length > 0 && (
{quizes.histories.length + summaries.histories.length > 0 && (
<ChipWrapper>
<FileTypeChip
selected={filter === 'QUIZ'}
Expand All @@ -84,14 +80,14 @@ const HistoryPage = () => {
</Header>
<HistoryPagination
type={
quizzes.histories.length + summaries.histories.length === 0
quizes.histories.length + summaries.histories.length === 0
? 'ALL'
: filter
}
fetchPage={updateList}
histories={filter === 'QUIZ' ? quizzes.histories : summaries.histories}
histories={filter === 'QUIZ' ? quizes.histories : summaries.histories}
totalPages={
filter === 'QUIZ' ? quizzes.totalPages : summaries.totalPages
filter === 'QUIZ' ? quizes.totalPages : summaries.totalPages
}
/>
</Wrapper>
Expand Down

0 comments on commit 0e308af

Please sign in to comment.