diff --git a/package.json b/package.json index 2782154..57ee669 100644 --- a/package.json +++ b/package.json @@ -248,6 +248,7 @@ "yarn-deduplicate": "^3.1.0" }, "dependencies": { + "@koa/cors": "^3.1.0", "@material-ui/core": "^4.11.4", "@material-ui/icons": "^4.11.2", "classnames": "^2.3.1", diff --git a/src/App.global.css b/src/App.global.css index 1f0c0ce..ecdca4f 100644 --- a/src/App.global.css +++ b/src/App.global.css @@ -7,7 +7,6 @@ body { color: #000; height: 100vh; font-family: sans-serif; - overflow-y: hidden; display: flex; justify-content: center; align-items: center; @@ -18,6 +17,7 @@ body { #root { width: 100%; height: 100%; + overflow: auto; } button { diff --git a/src/localserver.js b/src/localserver.js index 6e7fa39..30686c5 100644 --- a/src/localserver.js +++ b/src/localserver.js @@ -3,6 +3,7 @@ import Koa from 'koa'; import { app } from 'electron'; import Router from 'koa-router'; import fsPromisese from 'fs.promises'; +import cors from '@koa/cors'; import fs from 'fs'; import path from 'path'; import { v4 as uuidv4 } from 'uuid'; @@ -269,6 +270,7 @@ export default async function hostServer() { .get('/comic/:id', getComic) .get('/comic', getComicList) + app.use(cors()); app.use(bodyParser()); app.use(router.routes()); app.use(router.allowedMethods()); diff --git a/src/main.dev.ts b/src/main.dev.ts index 840320a..d5b1a44 100644 --- a/src/main.dev.ts +++ b/src/main.dev.ts @@ -115,7 +115,7 @@ const createWindow = async () => { // 初始化本地Server const server = await hostServer(); // 初始化IPC - initIpc(app, mainWindow, server); + initIpc(app, mainWindow); }; /** diff --git a/src/package.json b/src/package.json index 1b50e10..9ba240e 100644 --- a/src/package.json +++ b/src/package.json @@ -1,7 +1,7 @@ { "name": "electron-react-boilerplate", "productName": "electron-webtoon", - "version": "2.3.0", + "version": "2.3.1", "description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development", "main": "./main.prod.js", "author": { diff --git a/src/page/comic/index.css b/src/page/comic/index.css index 0fe860e..014b9fb 100644 --- a/src/page/comic/index.css +++ b/src/page/comic/index.css @@ -1,11 +1,12 @@ .container { padding-top: 50px; + box-sizing: border-box; width: 100%; height: 100%; } .navbar { - position: absolute; + position: fixed; top: 20px; left: 20px; } @@ -19,26 +20,27 @@ top: 0; left: 320px; width: calc(100% - 320px); - overflow: auto; box-sizing: border-box; padding: 50px 0; - height: 100%; font-size: 0; background: #fff; + user-select: none; } .imglist img { display: block; max-width: 100%; margin: 0 auto; + pointer-events: none; } .chapter { - position: absolute; + position: fixed; + box-sizing: border-box; left: 0; top: 50px; width: 300px; - height: 100%; + height: calc(100% - 100px); overflow: auto; } diff --git a/src/page/comic/index.jsx b/src/page/comic/index.jsx index 9d4a54b..7c88db8 100644 --- a/src/page/comic/index.jsx +++ b/src/page/comic/index.jsx @@ -57,7 +57,6 @@ function sortImgList(imgList) { function ImgList({ imgList }) { - const containerRef = useRef(null); function renderList(list) { return list.map((item, index) => { if (item.name) { @@ -73,10 +72,27 @@ function ImgList({ imgList }) { }); } + const autoScrollRef = useRef(false); + + const onMouseUp = useCallback(() => { + autoScrollRef.current = false; + }, []); + + const onMouseDown = useCallback(() => { + function scroll() { + document.scrollingElement.scrollTop += 5; + if (autoScrollRef.current) { + requestAnimationFrame(scroll); + } + } + autoScrollRef.current = true; + requestAnimationFrame(scroll); + }, []); + useEffect(() => { - containerRef.current.scrollTop = 0; + document.scrollingElement.scrollTop = 0; }, [imgList]); - return