Skip to content

Commit 1663ca8

Browse files
committed
clean comment and modify page navigation
1 parent 8dfd46b commit 1663ca8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

app/routes/read.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ export async function loader({ request }: LoaderFunctionArgs) {
2525

2626
export default function Read() {
2727
const { images, files } = useLoaderData<typeof loader>()
28-
const [index, setIndex] = useState(0)
28+
const [params, setParas] = useSearchParams({ index: '0' })
29+
const index = Number(params.get('index'))
30+
31+
function setIndex(index: number) {
32+
params.set('index', index.toString())
33+
setParas(params)
34+
}
35+
2936
const [showControls, setShowControls] = useState(true)
3037
const [isFullscreen, setIsFullscreen] = useState(false)
3138
const image = images[index]
3239
const [searchParams] = useSearchParams()
3340
const fileParam = encodeURIComponent(searchParams.get('file') || '')
3441

35-
// Ocultar controles automáticamente después de 3 segundos
3642
useEffect(() => {
3743
if (!showControls) return
3844

@@ -43,7 +49,6 @@ export default function Read() {
4349
return () => clearTimeout(timer)
4450
}, [showControls, index])
4551

46-
// Navegación con teclado
4752
useEffect(() => {
4853
const handleKeyPress = (e: KeyboardEvent) => {
4954
switch (e.key) {
@@ -80,14 +85,12 @@ export default function Read() {
8085
function goToNext() {
8186
if (index < images.length - 1) {
8287
setIndex(index + 1)
83-
// setShowControls(true)
8488
}
8589
}
8690

8791
function goToPrevious() {
8892
if (index > 0) {
8993
setIndex(index - 1)
90-
// setShowControls(true)
9194
}
9295
}
9396

@@ -113,7 +116,7 @@ export default function Read() {
113116

114117
return `/read?file=${encodeURIComponent(
115118
`${nextFile.path}/${nextFile.name}`,
116-
)}`
119+
)}&index=0`
117120
}, [files, fileParam])
118121

119122
const previousChapterLink = useMemo(() => {
@@ -138,7 +141,7 @@ export default function Read() {
138141

139142
return `/read?file=${encodeURIComponent(
140143
`${previousFile.path}/${previousFile.name}`,
141-
)}`
144+
)}&index=0`
142145
}, [files, fileParam])
143146

144147
function toggleFullscreen() {
@@ -186,7 +189,7 @@ export default function Read() {
186189

187190
return (
188191
<div className="relative w-screen h-screen bg-black overflow-hidden">
189-
{/* Imagen principal */}
192+
{/* Main image */}
190193
<div
191194
className="w-full h-full flex items-center justify-center cursor-pointer"
192195
onClick={handleImageClick}
@@ -204,13 +207,13 @@ export default function Read() {
204207
/>
205208
</div>
206209

207-
{/* Overlay de controles */}
210+
{/* Overlay controls */}
208211
<div
209212
className={`absolute inset-0 bg-gradient-to-b from-black/50 via-transparent to-black/50 transition-opacity duration-300 pointer-events-none ${
210213
showControls ? 'opacity-100' : 'opacity-0'
211214
}`}
212215
>
213-
{/* Barra superior */}
216+
{/* Top bar */}
214217
<div
215218
className="absolute top-0 left-0 right-0 h-16 bg-gradient-to-b from-black/80 to-transparent pointer-events-auto"
216219
aria-label="Barra superior"
@@ -279,7 +282,7 @@ export default function Read() {
279282
</div>
280283
</div>
281284

282-
{/* Barra inferior */}
285+
{/* Bottom bar */}
283286
<div
284287
className="absolute bottom-0 left-0 right-0 h-16 bg-gradient-to-t from-black/80 to-transparent pointer-events-auto"
285288
aria-label="Barra inferior"
@@ -313,7 +316,7 @@ export default function Read() {
313316
</div>
314317
</div>
315318

316-
{/* Indicador de progreso */}
319+
{/* Progress indicator */}
317320
<div className="absolute bottom-0 left-0 right-0 h-1 bg-pink-500/25">
318321
<div
319322
className="h-full bg-pink-500 transition-all duration-300"

0 commit comments

Comments
 (0)