Skip to content

Commit f5710c4

Browse files
committed
feat: fix bug
1 parent 872b0a4 commit f5710c4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/client/page/comic/ChapterComic.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ const ChapterComic: React.FC<{ chapterList: IImgListForMultipleChapter }> = ({
162162

163163
return (
164164
<>
165-
<div className="flex grow relative">
165+
<div className="flex relative">
166166
<ChapterList
167167
toggleChapter={toggleChapter}
168168
imgList={chapterList}
169169
value={chapter}
170170
onChange={setChapter}
171171
/>
172-
<div className="grow relative flex">
172+
<div className="grow relative flex w-[calc(100%-320px)]">
173173
<ImgList
174174
tag={chapter.name}
175175
onVisitPosition={onVisitPositionChange}

src/client/page/comic/imgList.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,19 @@ function useImgLoadAutoScrollIntoView(
9494
const containerRef = useRef(container);
9595
const firstElementOnLoadRef = useRef(firstElementOnLoad);
9696
containerRef.current = container;
97+
const firstElePositionRef = useRef<number>(firstElePosition);
98+
firstElePositionRef.current = firstElePosition;
9799

98100
useEffect(() => {
99-
if (firstElePosition < 0 || firstElePosition > imgList.length) {
101+
if (firstElePosition < 0 || firstElePositionRef.current > imgList.length) {
100102
if (firstElementOnLoadRef.current) {
101103
firstElementOnLoadRef.current();
102104
}
103105
}
104106
}, []);
105107

106108
const onLoad = useCallback((e) => {
107-
if (Number(e.currentTarget.dataset.index) === firstElePosition) {
109+
if (Number(e.currentTarget.dataset.index) === firstElePositionRef.current) {
108110
const target = e.currentTarget;
109111
if (containerRef.current) {
110112
containerRef.current.classList.add("scroll-smooth");
@@ -310,6 +312,7 @@ const HorizonImgList: React.FC<ImgListProps> = ({
310312
const [scrollingDone, setScrollingDone] = useState(false);
311313
const containerRef = useRef<HTMLDivElement>(null);
312314
useWatchComicPositionChange(!loading && scrollingDone, onVisitPosition);
315+
313316
const { onLoad: onImgLoad } = useImgLoadAutoScrollIntoView(
314317
imgList,
315318
firstElePosition,

0 commit comments

Comments
 (0)