-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feat] 스크롤 관련 구현 #68
Merged
+111
−19
Merged
[feat] 스크롤 관련 구현 #68
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c3453fb
Merge branch 'dev' of https://github.com/softeerbootcamp4th/Team6-Awe…
darkdulgi 2b9d80f
[feat] 스크롤 상태 정의와 헤더바 섹션을 클릭하면 스크롤 이동하는 scrollTo 함수 구현
darkdulgi 062fb92
[feat] 화면에 보이는 현재 섹션 상태를 변경하는 로직 구현, 이를 훅으로 뺌
darkdulgi e6e3743
[file] 인터랙션 페이지 파일 정의
darkdulgi fa33c49
Merge branch 'dev' into feature/64-scroll
darkdulgi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useRef } from "react"; | ||
import useSectionInitialize from "../scroll/useSectionInitialize"; | ||
|
||
export default function InteractionPage() { | ||
const SECTION_IDX = 0; | ||
const sectionRef = useRef(null); | ||
useSectionInitialize(SECTION_IDX, sectionRef); | ||
|
||
return <div ref={sectionRef} className="bg-black h-[2017px]"></div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useSectionStore } from "./store"; | ||
|
||
export default function scrollTo(scrollIndex) { | ||
const state = useSectionStore.getState(); | ||
const sectionDOM = state.sectionList[scrollIndex]; | ||
sectionDOM.scrollIntoView({ behavior: "smooth" }); | ||
} | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { create } from "zustand"; | ||
|
||
export const useSectionStore = create((set) => ({ | ||
sectionList: [null, null, null, null], | ||
currentSection: -1, | ||
setCurrentSection: (newSection) => set({ currentSection: newSection }), | ||
uploadSection: (index, section) => | ||
set((state) => { | ||
const updatedList = [...state.sectionList]; | ||
updatedList[index] = section; | ||
return { sectionList: updatedList }; | ||
}), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect } from "react"; | ||
import { useSectionStore } from "./store"; | ||
|
||
export default function useSectionInitialize(SECTION_IDX, sectionRef) { | ||
const uploadSection = useSectionStore((state) => state.uploadSection); | ||
const setCurrentSection = useSectionStore((state) => state.setCurrentSection); | ||
const currentSection = useSectionStore((state) => state.currentSection); | ||
|
||
useEffect(() => { | ||
const sectionDOM = sectionRef.current; | ||
if (sectionDOM) { | ||
uploadSection(SECTION_IDX, sectionRef.current); | ||
} | ||
|
||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
// 미구현 | ||
} | ||
}); | ||
}, | ||
{ threshold: 0.05 }, | ||
); | ||
|
||
if (sectionDOM) { | ||
observer.observe(sectionDOM); | ||
} | ||
return () => { | ||
if (sectionDOM) { | ||
observer.unobserve(sectionDOM); | ||
} | ||
}; | ||
}, [ | ||
SECTION_IDX, | ||
sectionRef, | ||
uploadSection, | ||
setCurrentSection, | ||
currentSection, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0~3까지, 즉 useSectionInitialize가 사용하는 매직넘버를 별도의 상수로 분리해서 관리한다면, 모달 등 다른 페이지에서 명시적으로 쓰기 편할 겁니다.