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

[FE] feat: 뒤로 가기 버튼 구현 #1040

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
3 changes: 3 additions & 0 deletions frontend/src/assets/backButton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions frontend/src/components/common/BackButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { NavigateOptions, useNavigate } from 'react-router';

import BackButtonIcon from '@/assets/backButton.svg';

import * as S from './styles';

interface BackButtonProps {
prevPath: string;
options?: NavigateOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigateOptions라고 명시하면 BackButton을 사용할 때 무엇을 전달해야 하는지 고민하지 않아도 될 것 같아요!
(이걸 보니 제 로그인 버튼 스타일 이름을 확실히 고쳐야겠다는 생각이 드네요ㅋㅋㅋ)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

명시하는 것이 나을 것 같네요!

buttonStyle?: React.CSSProperties;
wrapperStyle?: React.CSSProperties;
}

const BackButton = ({ prevPath, options, buttonStyle, wrapperStyle }: BackButtonProps) => {
const navigate = useNavigate();

const handleBackButtonClick = () => {
navigate(prevPath, options);
};

return (
<S.BackButtonWrapper $style={wrapperStyle}>
<S.BackButton onClick={handleBackButtonClick} $style={buttonStyle}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금은 BackButton을 레이아웃과 엮어서 사용하고 있지만, Wrapper 없이 딱 BackButton만 필요할 때도 있을 것 같아요. 둘을 분리하는 것에 대해 어떻게 생각하시나요? (Checkbox와 CheckboxItem처럼) '뒤로가기' 자체가 레이아웃과 엮일 일이 많으니 그냥 묶어둬도 좋을 것 같고... 😶

그리고 버튼 type은 굳이 지정하지 않아도 되는지 궁금해요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원래는 레이아웃으로 만들려고 했던 만큼, 뒤로 가기 버튼을 사용하게 된다면 거의 레이아웃 용도로 사용하게 될 것 같아요. 만약 BackButton 자체만 필요한 경우가 생긴다면 그때 두 가지를 모두 지원하는 것은 어떨까요?

버튼 type의 경우 기본값이 submit이기 때문에 button으로 지정했습니다! 👍

<img src={BackButtonIcon} alt="뒤로가기 버튼" />
</S.BackButton>
</S.BackButtonWrapper>
);
};

export default BackButton;
20 changes: 20 additions & 0 deletions frontend/src/components/common/BackButton/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import styled from '@emotion/styled';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

올라온 styles.tsx에 BackButtonWrapper는 없네요 😲

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉 스타일 코드가 빠졌네요.. 누락된 코드 추가했습니다


interface BackButtonStyleProps {
$style?: React.CSSProperties;
}

export const BackButtonWrapper = styled.div<BackButtonStyleProps>`
display: flex;
justify-content: flex-start;
width: 100%;

${({ $style }) => $style && { ...$style }}
`;

export const BackButton = styled.button<BackButtonStyleProps>`
width: 3.5rem;
height: 3.5rem;

${({ $style }) => $style && { ...$style }}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const DetailedReviewPageContents = () => {
};
}, [detailedReview]);

// TODO: 리뷰 공개/비공개 토글 버튼 기능
return (
<S.DetailedReviewPageContents>
<ReviewDescription
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/ReviewCollectionPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthAndServerErrorFallback, ErrorSuspenseContainer, TopButton } from '@/components';
import { AuthAndServerErrorFallback, ErrorSuspenseContainer } from '@/components';
import ReviewDisplayLayout from '@/components/layouts/ReviewDisplayLayout';

import ReviewCollectionPageContents from './components/ReviewCollectionPageContents';
Expand All @@ -8,7 +8,6 @@ const ReviewCollectionPage = () => {
<ErrorSuspenseContainer fallback={AuthAndServerErrorFallback}>
<ReviewDisplayLayout isReviewList={false}>
<ReviewCollectionPageContents />
<TopButton />
</ReviewDisplayLayout>
</ErrorSuspenseContainer>
);
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/ReviewListPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorSuspenseContainer, AuthAndServerErrorFallback, TopButton } from '@/components';
import { ErrorSuspenseContainer, AuthAndServerErrorFallback } from '@/components';
import ReviewDisplayLayout from '@/components/layouts/ReviewDisplayLayout';

import ReviewListPageContents from './components/ReviewListPageContents';
Expand All @@ -8,7 +8,6 @@ const ReviewListPage = () => {
<ErrorSuspenseContainer fallback={AuthAndServerErrorFallback}>
<ReviewDisplayLayout isReviewList={true}>
<ReviewListPageContents />
<TopButton />
</ReviewDisplayLayout>
</ErrorSuspenseContainer>
);
Expand Down
Loading