Compare commits
No commits in common. "fbc4fb75e85f397c96d668165a5fd20a3fbba44f" and "ab2f73af70bc1b1b0c2f26613f90694c83c69ea3" have entirely different histories.
fbc4fb75e8
...
ab2f73af70
3 changed files with 12 additions and 29 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -14,8 +14,6 @@ app/**
|
||||||
settings.json
|
settings.json
|
||||||
comic_config.json
|
comic_config.json
|
||||||
**/comic_config.json
|
**/comic_config.json
|
||||||
compiled/
|
|
||||||
deploy-scripts/
|
|
||||||
|
|
||||||
.pnpm-store/**
|
.pnpm-store/**
|
||||||
.env
|
.env
|
|
@ -4,8 +4,7 @@ import { Input } from "@/components/ui/input";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||||
import { useGalleryDoc } from "@/hook/useGalleryDoc.ts";
|
import { useGalleryDoc } from "@/hook/useGalleryDoc.ts";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { EnterFullScreenIcon, ExitFullScreenIcon, ExitIcon } from "@radix-ui/react-icons";
|
import { EnterFullScreenIcon, ExitIcon } from "@radix-ui/react-icons";
|
||||||
import { useEventListener } from "usehooks-ts";
|
|
||||||
import type { Document } from "dbtype/api";
|
import type { Document } from "dbtype/api";
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
|
@ -93,30 +92,12 @@ function clip(val: number, min: number, max: number): number {
|
||||||
return Math.max(min, Math.min(max, val));
|
return Math.max(min, Math.min(max, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
function useFullScreen() {
|
|
||||||
const ref = useRef<HTMLElement>(document.documentElement);
|
|
||||||
const [isFullScreen, setIsFullScreen] = useState(false);
|
|
||||||
|
|
||||||
const toggleFullScreen = useCallback(() => {
|
|
||||||
if (isFullScreen) {
|
|
||||||
document.exitFullscreen();
|
|
||||||
} else {
|
|
||||||
document.documentElement.requestFullscreen();
|
|
||||||
}
|
|
||||||
}, [isFullScreen]);
|
|
||||||
|
|
||||||
useEventListener("fullscreenchange", () => {
|
|
||||||
setIsFullScreen(!!document.fullscreenElement);
|
|
||||||
}, ref);
|
|
||||||
return { isFullScreen, toggleFullScreen };
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ComicPage({
|
export default function ComicPage({
|
||||||
params
|
params
|
||||||
}: ComicPageProps) {
|
}: ComicPageProps) {
|
||||||
const { data, error, isLoading } = useGalleryDoc(params.id);
|
const { data, error, isLoading } = useGalleryDoc(params.id);
|
||||||
const [curPage, setCurPage] = useState(0);
|
const [curPage, setCurPage] = useState(0);
|
||||||
const { isFullScreen, toggleFullScreen } = useFullScreen();
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
// TODO: Add a loading spinner
|
// TODO: Add a loading spinner
|
||||||
return <div className="p-4">
|
return <div className="p-4">
|
||||||
|
@ -141,8 +122,11 @@ export default function ComicPage({
|
||||||
return (
|
return (
|
||||||
<PageNavItem items={<>
|
<PageNavItem items={<>
|
||||||
<NavItem to={`/doc/${params.id}`} name="Back" icon={<ExitIcon />}/>
|
<NavItem to={`/doc/${params.id}`} name="Back" icon={<ExitIcon />}/>
|
||||||
<NavItemButton name={isFullScreen ? "Exit Fullscreen" : "Enter Fullscreen"} icon={isFullScreen ? <ExitFullScreenIcon/> : <EnterFullScreenIcon/>} onClick={()=>{
|
<NavItemButton name="fullscreen" icon={<EnterFullScreenIcon/>} onClick={()=>{
|
||||||
toggleFullScreen();
|
const elem = document.documentElement;
|
||||||
|
if (elem.requestFullscreen) {
|
||||||
|
elem.requestFullscreen();
|
||||||
|
}
|
||||||
}} />
|
}} />
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
|
@ -153,14 +137,15 @@ export default function ComicPage({
|
||||||
setCurPage(clip(Number.parseInt(e.target.value) - 1,
|
setCurPage(clip(Number.parseInt(e.target.value) - 1,
|
||||||
0,
|
0,
|
||||||
(data.additional.page as number) - 1))} />
|
(data.additional.page as number) - 1))} />
|
||||||
|
<div className="flex">
|
||||||
|
</div>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
</>}>
|
</>}>
|
||||||
<ComicViewer
|
<ComicViewer
|
||||||
curPage={curPage}
|
curPage={curPage}
|
||||||
onChangePage={setCurPage}
|
onChangePage={setCurPage}
|
||||||
doc={data}
|
doc={data} totalPage={data.additional.page as number} />
|
||||||
totalPage={data.additional.page as number} />
|
|
||||||
</PageNavItem>
|
</PageNavItem>
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "build/app.js",
|
"main": "build/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "swc src --out-dir compile",
|
"compile": "swc src --out-dir dist",
|
||||||
"dev": "nodemon -r @swc-node/register --enable-source-maps --exec node app.ts",
|
"dev": "nodemon -r @swc-node/register --enable-source-maps --exec node app.ts",
|
||||||
"start": "node compile/app.js"
|
"start": "node dist/app.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|
Loading…
Add table
Reference in a new issue