Initial
This commit is contained in:
161
resources/js/Pages/Comic/Chapters.jsx
Normal file
161
resources/js/Pages/Comic/Chapters.jsx
Normal file
@@ -0,0 +1,161 @@
|
||||
import { useState } from 'react';
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { Moon, Plus, Star, ArrowDownNarrowWide, ArrowUpNarrowWide } from 'lucide-react';
|
||||
|
||||
import AppLayout from '@/Layouts/AppLayout.jsx';
|
||||
|
||||
import { BreadcrumbItem, BreadcrumbPage, BreadcrumbSeparator } from '@/components/ui/breadcrumb';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { Badge } from "@/Components/ui/badge.jsx";
|
||||
|
||||
export default function Chapters({ auth, comic, chapters }) {
|
||||
|
||||
const [group, setGroup] = useState('default');
|
||||
const [favourites, setFavourites] = useState(auth.user.favourites);
|
||||
const [ascending, setAscending] = useState(true);
|
||||
|
||||
const { toast } = useToast();
|
||||
|
||||
const favouriteOnClickHandler = (pathword) => {
|
||||
axios.post(route('comics.postFavourite'), { pathword: pathword }).then(res => {
|
||||
setFavourites(res.data);
|
||||
});
|
||||
|
||||
toast({
|
||||
title: "All set",
|
||||
description: `${comic.comic.name} is now in / remove your favorite list.`,
|
||||
});
|
||||
}
|
||||
|
||||
const groupOnClickHandler = (pathword) => {
|
||||
router.get(`/comic/${ comic.comic.path_word }?group=${ pathword }`, {}, {
|
||||
only: ['chapters'],
|
||||
preserveState: true
|
||||
});
|
||||
setGroup(pathword);
|
||||
setAscending(true);
|
||||
}
|
||||
|
||||
const ComicChapterLink = (props) => {
|
||||
const isNew = Date.now() - Date.parse(props.datetime_created) < 6.048e+8;
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button className="" size="sm" variant="outline" asChild>
|
||||
<Link className="relative" href={ `/comic/${ comic.comic.path_word }/${ props.uuid }` }>
|
||||
{ props.name }
|
||||
{ isNew && <Plus size={ 16 } className="text-xs absolute right-0 top-0" /> }
|
||||
</Link>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>Updated: { props.datetime_created }</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const toggleAscending = (e) => {
|
||||
setAscending(!ascending);
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<AppLayout auth={ auth } header={
|
||||
<>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>{ comic.comic.name }</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</>
|
||||
}>
|
||||
<Head>
|
||||
<title>{ comic.comic.name }</title>
|
||||
</Head>
|
||||
<div className="p-3 pt-1">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex flex-row content-end items-center">
|
||||
<Button onClick={ () => favouriteOnClickHandler(comic.comic.path_word) } size="icon" variant="ghost">
|
||||
<Star fill={ favourites.includes(comic.comic.path_word) ? 'yellow': 'white' } />
|
||||
</Button>
|
||||
<span>{ comic.comic.name }</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex justify-start justify-items-stretch content-start items-start gap-5 flex-wrap">
|
||||
<div className="basis-full lg:basis-2/12">
|
||||
<img className="block object-fill w-full" src={ "/image/" + btoa(comic.comic.cover) }
|
||||
alt={ comic.comic.name } />
|
||||
</div>
|
||||
<div className="basis-full lg:basis-9/12">
|
||||
<table className="table-fixed w-full text-sm">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="text-right w-24 pr-3">Alias</td>
|
||||
<td>{ comic.comic.alias }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="text-right pr-3">Category</td>
|
||||
<td>
|
||||
{ comic.comic.theme.map(t =>
|
||||
<Badge key={ t.path_word } className="m-2" variant="outline">
|
||||
<Link href={ route("comics.index", { tag: t.path_word }) }>{ t.name }</Link>
|
||||
</Badge>
|
||||
) }
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="text-right pr-3">Authors</td>
|
||||
<td>{ comic.comic.author.map(a => <Badge key={ a.path_word } className="m-2" variant="outline"><Link>{ a.name }</Link></Badge>) }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="text-right pr-3">Description</td>
|
||||
<td>{ comic.comic.brief }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="text-right pr-3">Updated At</td>
|
||||
<td>{ comic.comic.datetime_updated }</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardContent>
|
||||
<Tabs defaultValue={ group } className="w-full">
|
||||
<div className="flex">
|
||||
<TabsList className={ `grid w-full grid-cols-${ Object.entries(comic.groups).length } ` }>
|
||||
{ Object.entries(comic.groups).map((g, i) => (
|
||||
<TabsTrigger onClick={ () => groupOnClickHandler(g[1].path_word) }
|
||||
key={ g[1].path_word }
|
||||
value={ g[1].path_word }>
|
||||
{ g[1].name }
|
||||
</TabsTrigger>
|
||||
)) }
|
||||
</TabsList>
|
||||
<div>
|
||||
<Button variant="link" size="icon" onClick={ () => toggleAscending() }>
|
||||
{ ascending ? <ArrowDownNarrowWide /> : <ArrowUpNarrowWide /> }
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<TabsContent value={ group }>
|
||||
<div className="w-full grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 xl:grid-cols-12 gap-1">
|
||||
{ chapters.list.sort((a, b) => ascending ? (a.index - b.index) : (b.index - a.index)).map(c => (
|
||||
<ComicChapterLink key={ c.uuid } { ...c } />
|
||||
) ) }
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
89
resources/js/Pages/Comic/Favourites.jsx
Normal file
89
resources/js/Pages/Comic/Favourites.jsx
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import AppLayout from '@/Layouts/AppLayout.jsx';
|
||||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Star } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
|
||||
import { BreadcrumbItem, BreadcrumbPage, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
|
||||
import { useToast } from "@/hooks/use-toast.js";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function Favourites({ auth, favourites }) {
|
||||
|
||||
const { toast } = useToast();
|
||||
const [stateFavourites, setStateFavourites] = useState(favourites);
|
||||
|
||||
const favouriteOnClickHandler = (pathword) => {
|
||||
axios.post(route('comics.postFavourite'), { pathword: pathword }).then(res => {
|
||||
setStateFavourites(stateFavourites.filter(f => f.pathword !== pathword));
|
||||
console.log(stateFavourites);
|
||||
//setFavourites(res.data);
|
||||
});
|
||||
|
||||
toast({
|
||||
title: "All set",
|
||||
description: `The comic is now removed from your favorite list.`,
|
||||
});
|
||||
}
|
||||
|
||||
const FavouriteCard = (props) => {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="flex gap-2">
|
||||
<div className="basis-1/4 pt-3">
|
||||
<div className="relative">
|
||||
<Link href={ `/comic/${ props.pathword }` }>
|
||||
<img className="block w-100 min-w-full object-fill" src={ "/image/" + btoa(props.cover) }
|
||||
alt={ props.name } />
|
||||
</Link>
|
||||
<Button className="absolute bottom-0 right-0"
|
||||
onClick={ () => favouriteOnClickHandler(props.pathword) } size="icon">
|
||||
<Star fill='yellow' />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="basis-3/4">
|
||||
<CardHeader>
|
||||
<CardTitle><Link href={ `/comic/${ props.pathword }` }>{ props.name }</Link></CardTitle>
|
||||
<div className="flex gap-2 items-end justify-between">
|
||||
<p>
|
||||
{ props.authors.map(a => <Badge key={ a.path_word } variant="outline"><Link>{ a.name }</Link></Badge>) }
|
||||
</p>
|
||||
<p className="text-right text-sm">
|
||||
Updated: { props.upstream_updated_at }
|
||||
</p>
|
||||
</div>
|
||||
<div className="pt-2">{ props.description }</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="relative">
|
||||
<Button className="w-full" asChild>
|
||||
<Link href={ route('comics.read', [props.pathword, props.metadata.comic.last_chapter.uuid])}>
|
||||
Read [{ props.metadata.comic.last_chapter.name }]
|
||||
</Link>
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<AppLayout auth={ auth } header={
|
||||
<>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>Favourites</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</>
|
||||
}>
|
||||
<Head>
|
||||
<title>Favourites</title>
|
||||
</Head>
|
||||
<div className="p-3 pt-1 grid lg:grid-cols-2 sm:grid-cols-1 gap-2">
|
||||
{ stateFavourites.map((favourite, i) => <FavouriteCard key={ i } {...favourite } /> ) }
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
78
resources/js/Pages/Comic/Index.jsx
Normal file
78
resources/js/Pages/Comic/Index.jsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { useState } from 'react';
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
import AppLayout from '@/Layouts/AppLayout.jsx';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Pagination, PaginationContent, PaginationItem, PaginationNext, PaginationPrevious } from '@/components/ui/pagination';
|
||||
import { useToast } from '@/hooks/use-toast.js';
|
||||
|
||||
export default function Index({ comics, offset, auth }) {
|
||||
|
||||
const url = new URL(window.location).searchParams;
|
||||
|
||||
const [favourites, setFavourites] = useState(auth.user.favourites);
|
||||
const { toast } = useToast();
|
||||
|
||||
const favouriteOnClickHandler = (pathword) => {
|
||||
axios.post(route('comics.postFavourite'), { pathword: pathword }).then(res => {
|
||||
setFavourites(res.data);
|
||||
});
|
||||
|
||||
toast({
|
||||
title: "All set",
|
||||
description: `${comics.list.filter(c => c.path_word === pathword)[0].name} is now in / remove your favorite list.`,
|
||||
});
|
||||
}
|
||||
|
||||
const ComicCard = (props) => (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="relative">
|
||||
<Link href={ `/comic/${ props.path_word }` }>
|
||||
<img className="block w-100 min-w-full object-fill" src={ "/image/" + btoa(props.cover) } alt={ props.name } />
|
||||
</Link>
|
||||
<Button className="absolute bottom-0 right-0" onClick={ () => favouriteOnClickHandler(props.path_word) } size="icon">
|
||||
<Star fill={ favourites.includes(props.path_word) ? 'yellow': '' } />
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardTitle><Link href={ `/comic/${ props.path_word }` }>{ props.name }</Link></CardTitle>
|
||||
<CardDescription className="pt-2">
|
||||
{ props.author.map(a => <Badge className="m-1" key={ a.path_word } variant="outline"><Link>{ a.name }</Link></Badge>) }
|
||||
</CardDescription>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
const ComicCards = (comics) => {
|
||||
return comics.list.map((comic, i) => <ComicCard key={ i } { ...comic } />);
|
||||
}
|
||||
|
||||
return (
|
||||
<AppLayout auth={ auth }>
|
||||
<Head>
|
||||
<title>Home</title>
|
||||
</Head>
|
||||
<div className="p-3 pt-1 grid lg:grid-cols-6 sm:grid-cols-2 gap-2">
|
||||
<ComicCards { ...comics } />
|
||||
</div>
|
||||
<Pagination className="justify-end pb-2">
|
||||
<PaginationContent>
|
||||
{ parseInt(offset) !== 0 &&
|
||||
<PaginationItem>
|
||||
<PaginationPrevious href={ `/?${url}` } only={['comics', 'offset']} headers={{ offset: parseInt(offset) - 30 }} />
|
||||
</PaginationItem>
|
||||
}
|
||||
<PaginationItem>
|
||||
<PaginationNext href={ `/?${url}` } only={['comics', 'offset']} headers={{ offset: parseInt(offset) + 30 }} />
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
291
resources/js/Pages/Comic/Read.jsx
Normal file
291
resources/js/Pages/Comic/Read.jsx
Normal file
@@ -0,0 +1,291 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import AppLayout from '@/Layouts/AppLayout.jsx';
|
||||
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import { BreadcrumbItem, BreadcrumbLink, BreadcrumbPage, BreadcrumbSeparator } from "@/Components/ui/breadcrumb.jsx";
|
||||
import { Button } from "@/Components/ui/button.jsx";
|
||||
import { ChevronFirst, ChevronLast, Rows3, Settings } from "lucide-react";
|
||||
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog";
|
||||
import PrimaryButton from "@/Components/PrimaryButton.jsx";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Tooltip, TooltipProvider, TooltipTrigger } from "@radix-ui/react-tooltip";
|
||||
import { TooltipContent } from "@/Components/ui/tooltip.jsx";
|
||||
import { throttle } from "lodash";
|
||||
|
||||
export default function Read({ auth, comic, chapter }) {
|
||||
const [readingMode, setReadingMode] = useState('rtl'); // rtl, utd
|
||||
const [isTwoPagesPerScreen, setIsTwoPagePerScreen] = useState(false);
|
||||
const [currentImage, setCurrentImage] = useState(1);
|
||||
|
||||
const windowSize = useWindowSize();
|
||||
const ref = useRef();
|
||||
|
||||
const [divDimensions, setDivDimensions] = useState([0, 0]);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
function useWindowSize() {
|
||||
const [size, setSize] = useState([0, 0]);
|
||||
useLayoutEffect(() => {
|
||||
function updateSize() {
|
||||
setSize([window.innerWidth, window.innerHeight]);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', updateSize);
|
||||
updateSize();
|
||||
return () => window.removeEventListener('resize', updateSize);
|
||||
}, []);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
const toggleReadingMode = (e) => {
|
||||
if (e) {
|
||||
setReadingMode('utd');
|
||||
} else {
|
||||
setReadingMode('rtl');
|
||||
}
|
||||
}
|
||||
|
||||
const setViewPort = (e) => {
|
||||
//console.log(e.target.childNodes);
|
||||
//console.log(e.target.naturalHeight);
|
||||
}
|
||||
|
||||
const ImageForComic = (img) => {
|
||||
const imgRef = useRef();
|
||||
|
||||
const resizeImage = () => {
|
||||
if (!imgRef.current || !ref.current) return;
|
||||
|
||||
const { naturalWidth, naturalHeight } = imgRef.current;
|
||||
const containerWidth = ref.current.clientWidth;
|
||||
const containerHeight = ref.current.clientHeight;
|
||||
|
||||
let width, height;
|
||||
|
||||
if (readingMode === "rtl") {
|
||||
// Scale for RTL mode
|
||||
const ratioWidth = naturalWidth / containerWidth;
|
||||
const ratioHeight = naturalHeight / containerHeight;
|
||||
const maxRatio = Math.max(ratioWidth, ratioHeight);
|
||||
width = naturalWidth / maxRatio;
|
||||
height = naturalHeight / maxRatio;
|
||||
} else if (readingMode === "utd") {
|
||||
// Scale for UTD mode
|
||||
const ratio = divDimensions[1] < divDimensions[0] ? 0.33 : 1; // Example logic
|
||||
const scaledWidth = containerWidth * ratio;
|
||||
const scaledRatio = naturalWidth / scaledWidth;
|
||||
width = naturalWidth / scaledRatio;
|
||||
height = naturalHeight / scaledRatio;
|
||||
}
|
||||
|
||||
// Apply dimensions directly
|
||||
imgRef.current.style.width = `${width}px`;
|
||||
imgRef.current.style.height = `${height}px`;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
resizeImage();
|
||||
}, [readingMode, divDimensions]); // Recalculate when these dependencies change
|
||||
|
||||
const handleImageClick = (e) => {
|
||||
if (readingMode === "utd") return;
|
||||
|
||||
const bounds = imgRef.current.getBoundingClientRect();
|
||||
const percentage = (e.pageX - bounds.left) / imgRef.current.offsetWidth;
|
||||
|
||||
if (percentage < 0.45) {
|
||||
if (img.innerKey === 0 && chapter.chapter.prev) {
|
||||
router.visit(route('comics.read', [comic.comic.path_word, chapter.chapter.prev]));
|
||||
} else {
|
||||
document.getElementById(`image-${img.innerKey - 1}`)?.scrollIntoView();
|
||||
}
|
||||
} else if (percentage > 0.55) {
|
||||
if (img.innerKey >= chapter.sorted.length - 1 && chapter.chapter.next) {
|
||||
router.visit(route('comics.read', [comic.comic.path_word, chapter.chapter.next]));
|
||||
} else {
|
||||
document.getElementById(`image-${img.innerKey + 1}`)?.scrollIntoView();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (<div className="basis-full">
|
||||
<img
|
||||
id={ `image-${img.innerKey}` }
|
||||
ref={ imgRef }
|
||||
className="m-auto comic-img"
|
||||
src={ `/image/${btoa(img.url)}` }
|
||||
onLoad={ resizeImage } // Resize image immediately on load
|
||||
onClick={ handleImageClick }
|
||||
alt={ comic.comic.name }
|
||||
/>
|
||||
</div>);
|
||||
}
|
||||
|
||||
const Toolbar = () => {
|
||||
return (
|
||||
<>
|
||||
<Dialog>
|
||||
<DialogTrigger>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Button variant="link" size="icon">
|
||||
<Settings />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>Options</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[600px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Options</DialogTitle>
|
||||
<DialogDescription>
|
||||
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm">
|
||||
<div className="space-y-0.5">
|
||||
<label>Reading Mode</label>
|
||||
<p>Turn on for UTD mode</p>
|
||||
</div>
|
||||
<Switch defaultChecked={ readingMode === "utd" }
|
||||
onCheckedChange={ (e) => toggleReadingMode(e) } />
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<PrimaryButton>Done</PrimaryButton>
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Button variant="link" size="icon" asChild>
|
||||
<Link href={ route('comics.chapters', [comic.comic.path_word]) }>
|
||||
<Rows3 />
|
||||
</Link>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>Content Page</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
|
||||
{ chapter.chapter.prev && (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Button variant="link" size="icon" asChild>
|
||||
<Link href={ route('comics.read', [comic.comic.path_word, chapter.chapter.prev]) }>
|
||||
<ChevronFirst />
|
||||
</Link>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>Previous Chapter</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
) }
|
||||
|
||||
{ chapter.chapter.next && (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Button variant="link" size="icon" asChild>
|
||||
<Link href={ route('comics.read', [comic.comic.path_word, chapter.chapter.next]) }>
|
||||
<ChevronLast />
|
||||
</Link>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>Next Chapter</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
) }
|
||||
|
||||
<Button variant="ghost">
|
||||
{ currentImage } / { chapter.sorted.length }
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setDivDimensions([ref.current.clientWidth, ref.current.clientHeight]);
|
||||
}, [windowSize]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
const handleScroll = () => {
|
||||
const containerScrollTop = ref.current.scrollTop; // Current scroll position of the container
|
||||
const images = ref.current.querySelectorAll("img"); // Get all images
|
||||
|
||||
let visibleImageIndex = 0;
|
||||
|
||||
// Determine which image is visible based on scroll position
|
||||
images.forEach((image, index) => {
|
||||
const imageTop = image.offsetTop; // Distance from top of the container
|
||||
const imageBottom = imageTop + image.offsetHeight;
|
||||
|
||||
// Check if the image is in the visible area
|
||||
if (containerScrollTop + 80 >= imageTop && containerScrollTop < imageBottom) {
|
||||
visibleImageIndex = index;
|
||||
}
|
||||
});
|
||||
|
||||
// Update the current image index
|
||||
setCurrentImage(visibleImageIndex + 1);
|
||||
};
|
||||
|
||||
const throttledHandleScroll = throttle(handleScroll, 100); // Throttle for performance
|
||||
ref.current.addEventListener("scroll", throttledHandleScroll);
|
||||
|
||||
// Initial check for visible image
|
||||
handleScroll();
|
||||
|
||||
return () => {
|
||||
if (ref.current) {
|
||||
ref.current.removeEventListener("scroll", throttledHandleScroll);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AppLayout auth={ auth } header={
|
||||
<>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink asChild>
|
||||
<Link href={ route('comics.chapters', [comic.comic.path_word]) }>
|
||||
{ comic.comic.name }
|
||||
</Link>
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>{ chapter.chapter.name }</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</>
|
||||
} toolbar={ <Toolbar /> }>
|
||||
<Head>
|
||||
<title>{ chapter.chapter.name } - { comic.comic.name }</title>
|
||||
</Head>
|
||||
<div className="p-3 pt-1 pb-1 flex flex-wrap justify-center" id="mvp" ref={ ref }
|
||||
style={ { overflowAnchor: "none", height: "calc(100dvh - 90px)", overflowY: "scroll" } }>
|
||||
{ chapter.sorted.map((img, j) => <ImageForComic key={ j } innerKey={ j } { ...img } />) }
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user