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_임지환 2주차 과제 #51

Open
wants to merge 32 commits into
base: dlawlghks
Choose a base branch
from

Conversation

dlawlghks
Copy link

안녕하세요, 멘토님.
전남대 FE_임지환 입니다!

2주차 과제를 해보았는데 어려움을 많이 느꼈습니다..
혹시 코드에서 부족한 부분이나 잘못된 점이 있으면 바로 고쳐보겠습니다!!
그리고 폴더 구조를 나름대로 해보았는데 괜찮은지 봐주시면 감사하겠습니다.

항상 감사합니다!

dlawlghks added 23 commits July 5, 2024 21:28
- Header 컴포넌트에서 로그인 페이지로 이동하기 전에 현재 경로 저장
- LoginPage 컴포넌트에서 로그인 성공 후 저장된 경로로 리디렉션
- ProtectedRoute에서 사용자가 인증되지 않았을 때 현재 경로 저장
@dlawlghks dlawlghks changed the base branch from main to dlawlghks July 8, 2024 05:40
logout: () => {},
});

export const useAuth = () => useContext(AuthContext);
Copy link

Choose a reason for hiding this comment

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

Suggested change
export const useAuth = () => useContext(AuthContext);
export const useAuth = () => useContext<AuthContextType>(AuthContext);

path: RouterPath.root,
element: (
<>
<Header />
Copy link

Choose a reason for hiding this comment

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

Header, Footer 등 반복되는 컴포넌트는 Layout 으로 구성할 수 있을거 같습니다.
아래 참고 하셔서 Layout 컴포넌트로 구성해보실 수 있을거 같아요.
ref. https://reactrouter.com/en/main/components/outlet

element: (
<>
<Header />
<ProtectedRoute>
Copy link

Choose a reason for hiding this comment

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

ProtectedRoute 도 Outlet 사용해서 공통으로 적용할 수 있을거 같습니다.
ref. https://reactrouter.com/en/main/components/outlet

import { Container } from '@/components/common/layouts/Container';
import { Grid } from '@/components/common/layouts/Grid';

type Props = {
Copy link

Choose a reason for hiding this comment

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

Suggested change
type Props = {
interface Props extends ComponentProps<'div'> {

activeType: string;
}) => {
const [visibleProducts, setVisibleProducts] = useState<number>(6);
const [filteredProducts, setFilteredProducts] = useState<Product[]>([]);
Copy link

Choose a reason for hiding this comment

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

useEffect 내부에서 처리하는 것이 아니라 필터 함수를 작성해서 filteredProducts 초기값을 아래와 같이 지정해 줄 수 있습니다.

Suggested change
const [filteredProducts, setFilteredProducts] = useState<Product[]>([]);
const [filteredProducts, setFilteredProducts] = useState<Product[]>(() => products.filter(
(product) =>
(activeCategory === 'all' || product.category === activeCategory) &&
product.type === activeType,
));


const GiftRankingPage = () => {
const [activeCategory, setActiveCategory] = useState<string>('all');
const [activeType, setActiveType] = useState<string>('wanted');
Copy link

Choose a reason for hiding this comment

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

여기도 마찬가지입니다.

Suggested change
const [activeType, setActiveType] = useState<string>('wanted');
const [activeType, setActiveType] = useState<Type>('wanted');

const location = useLocation();

const handleLoginClick = () => {
sessionStorage.setItem('redirectPath', location.pathname + location.search);
Copy link

Choose a reason for hiding this comment

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

이거는 왜 세션 스토리지에 저장하나요 ?

Copy link

Choose a reason for hiding this comment

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

바로 로그인 페이지로 이동하면 될 거 같습니다.

const handleLogin = () => {
if (username && password) {
login(username); // 로그인 상태 변경
const redirectPath = sessionStorage.getItem('redirectPath') || '/';
Copy link

Choose a reason for hiding this comment

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

Suggested change
const redirectPath = sessionStorage.getItem('redirectPath') || '/';

login(username); // 로그인 상태 변경
const redirectPath = sessionStorage.getItem('redirectPath') || '/';
sessionStorage.removeItem('redirectPath'); // 리디렉션 후 경로 삭제
console.log('Login successful. Redirecting to:', redirectPath);
Copy link

Choose a reason for hiding this comment

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

Suggested change
console.log('Login successful. Redirecting to:', redirectPath);

const redirectPath = sessionStorage.getItem('redirectPath') || '/';
sessionStorage.removeItem('redirectPath'); // 리디렉션 후 경로 삭제
console.log('Login successful. Redirecting to:', redirectPath);
navigate(redirectPath, { replace: true });
Copy link

Choose a reason for hiding this comment

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

Suggested change
navigate(redirectPath, { replace: true });
navigate('/login', { replace: true });

@dlawlghks
Copy link
Author

멘토님 수정해보았습니다!!
감사합니다 ㅎㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants