-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from kakao-tech-campus-2nd-step3/Feature/카드_리…
- Loading branch information
Showing
14 changed files
with
143 additions
and
63 deletions.
There are no files selected for viewing
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
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,19 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useLocation } from "react-router-dom"; | ||
import useScrollSaver from "@hooks/useScrollSaver"; | ||
|
||
const ScrollSaver = () => { | ||
const location = useLocation(); | ||
const [prevLocation, setPrevLocation] = useState(location.pathname); | ||
const { getScroll, setScroll } = useScrollSaver(); | ||
|
||
useEffect(() => { | ||
setScroll(prevLocation, window.scrollY); | ||
setPrevLocation(location.pathname); | ||
window.scrollTo(0, getScroll(location.pathname)); | ||
}, [location]); | ||
|
||
return null; | ||
}; | ||
|
||
export default ScrollSaver; |
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,26 @@ | ||
const useScrollSaver = () => { | ||
const initScroll = () => { | ||
const originScrolls = sessionStorage.getItem("poomasi-scroll-index"); | ||
if (!originScrolls) { | ||
sessionStorage.setItem("poomasi-scroll-index", JSON.stringify({})); | ||
} | ||
}; | ||
|
||
const setScroll = (location: string, scroll: number) => { | ||
initScroll(); | ||
const scrolls = sessionStorage.getItem("poomasi-scroll-index"); | ||
const scrollsObj = JSON.parse(scrolls || "{}"); | ||
scrollsObj[location] = scroll; | ||
sessionStorage.setItem("poomasi-scroll-index", JSON.stringify(scrollsObj)); | ||
}; | ||
|
||
const getScroll = (location: string) => { | ||
const scrolls = sessionStorage.getItem("poomasi-scroll-index"); | ||
const scroll = JSON.parse(scrolls || "{}")[location]; | ||
return scroll || 0; | ||
}; | ||
|
||
return { initScroll, setScroll, getScroll }; | ||
}; | ||
|
||
export default useScrollSaver; |
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