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

fix: 헤더 sticky 적용 안되던 오류 수정, 스크롤 유지 되도록 수정 #277

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/bookmarks/service/hooks/home/useBookmarkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ const useBookmarkList = ({
isLoading,
fetchNextPage,
isFetchingNextPage,
remove,
refetch,
} = useGETBookMarkListQuery({
readByUser,
categoryId,
memberId,
});

useEffect(() => {
if (categoryId) remove();
if (categoryId) refetch();
}, [categoryId]);

const { initializeUrlAndTitle } = useBookmarkStore();

useEffect(() => {
initializeUrlAndTitle();
remove();
refetch();
}, [navigate]);

return {
Expand Down
39 changes: 36 additions & 3 deletions src/common-ui/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from 'react';
import { ReactNode, useEffect, useRef } from 'react';
import styled from '@emotion/styled';
import BottomNavigation from '@/common-ui/BottomNavigation';
import { navigatePath, NavigatePath } from '@/constants/navigatePath';
Expand All @@ -17,9 +17,43 @@ const Layout = ({ children }: { children: ReactNode }) => {
pathname as NavigatePath,
);

const ref = useRef<HTMLDivElement>(null);

const loadScroll = () => {
const scroll = sessionStorage.getItem('scroll');
if (scroll && ref.current && pathname === '/') {
ref.current?.scrollTo({
top: Number(scroll),
behavior: 'instant',
});
}
};

useEffect(() => {
const handleScroll = () => {
if (ref.current && ref.current.scrollTop > 0) {
sessionStorage.setItem('scroll', ref.current.scrollTop.toString());
}
};

if (ref.current && pathname === '/') {
ref.current.addEventListener('scroll', handleScroll);
}

return () => {
if (ref.current && pathname === '/') {
ref.current.removeEventListener('scroll', handleScroll);
}
};
}, [pathname]);

useEffect(() => {
loadScroll();
}, [pathname]);

return (
<LayoutContainer>
<InnerWrapper>{children}</InnerWrapper>
<InnerWrapper ref={ref}>{children}</InnerWrapper>
{isShowBottomNavigation && <BottomNavigation />}
</LayoutContainer>
);
Expand All @@ -31,7 +65,6 @@ const LayoutContainer = styled.div`
position: relative;
max-width: 480px;
margin: 0 auto;
overflow: hidden;
`;

const InnerWrapper = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/common-ui/PullToRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const PullToRefresh = ({
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
onTouchMove={onTouchMove}
style={{ overflow: 'hidden' }}
>
<IconContainer
style={{
Expand Down Expand Up @@ -110,6 +109,7 @@ const IconContainer = styled.div`
z-index: 10;
top: 0;
transition: transform 0.3s;
background-color: ${theme.colors.black};
`;

const fade = keyframes`
Expand Down
Loading