Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix hotkey bug in image reader #205

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions apps/desktop/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ tasks:
mergeDeps: 'replace'
mergeInputs: 'replace'

# # TODO: need to have more targets.
# build:
# # tauri build --target universal-apple-darwin
# command: 'pnpm tauri build'
# local: true
# deps:
# - '~:build-webapp'

# build-webapp:
# command: 'pnpm vite build'
nuke:
command: 'pnpm exec rimraf -rf node_modules'
local: true
3 changes: 3 additions & 0 deletions apps/web/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ tasks:
build:
command: 'vite build'
local: true

nuke:
command: 'rimraf -rf node_modules'
3 changes: 3 additions & 0 deletions docs/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ tasks:
options:
shell: true
runFromWorkspaceRoot: false

nuke:
command: 'rimraf -rf node_modules'
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"build:web": "pnpm web build && pnpm build:server",
"build:desktop": "pnpm desktop build",
"moon": "moon --color --log trace",
"prettify": "prettier --config prettier.config.js --ignore-path .prettierignore --write ."
"prettify": "prettier --config prettier.config.js --ignore-path .prettierignore --write .",
"nuke": "cargo clean && cargo codegen && moon run :nuke && pnpm i"
},
"devDependencies": {
"@babel/core": "^7.23.2",
Expand All @@ -46,6 +47,7 @@
"prettier": "^3.0.3",
"prettier-eslint": "^16.1.1",
"prettier-plugin-tailwindcss": "^0.5.6",
"rimraf": "^5.0.5",
"trash-cli": "^5.0.0",
"tsconfig-moon": "^1.3.0",
"typescript": "^5.2.2"
Expand Down
3 changes: 3 additions & 0 deletions packages/components/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ tasks:
storybook:
command: 'start-storybook -p 6006'
local: true

nuke:
command: 'rimraf -rf node_modules'
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export type PagedReaderProps = {
}

/**
* A component that renders a reader for image-based media. Images are displayed one at a time,
* A reader component for image-based media. Images are displayed one at a time,
* however preloading is done to reduce wait times for consecutive pages.
*
* Note: This component lacks animations between pages. The `AnimatedPagedReader` component
* has animations, as the name suggests lol.
* will have animations between pages, but is currently a WIP
*/
export default function PagedReader({
currentPage,
Expand All @@ -36,13 +36,14 @@ export default function PagedReader({

const [toolbarVisible, { toggle: toggleToolbar, off: hideToolbar }] = useBoolean(false)

const pageCount = media.pages
/**
* This effect is responsible for preloading the next 2 pages relative to the current page. This is done to
* try and prevent wait times for the next page to load.
*/
useEffect(
() => {
const pageArray = Array.from({ length: media.pages })
const pageArray = Array.from({ length: pageCount })

const start = currentPage >= 1 ? currentPage - 1 : 0

Expand All @@ -53,7 +54,7 @@ export default function PagedReader({
},

// eslint-disable-next-line react-hooks/exhaustive-deps
[currentPage, media.pages],
[currentPage, pageCount],
)

/**
Expand Down Expand Up @@ -82,10 +83,10 @@ export default function PagedReader({
* A simple function that does a little bit of validation before calling the onPageChange callback.
* This is done to prevent the user from going to a page that doesn't exist.
*
* @param newPage The new page to navigate to
* @param newPage The new page to navigate to (1-indexed)
*/
function handlePageChange(newPage: number) {
if (newPage < media.pages && newPage > 0) {
if (newPage <= media.pages && newPage > 0) {
onPageChange(newPage)
}
}
Expand Down Expand Up @@ -126,7 +127,8 @@ export default function PagedReader({
visible={toolbarVisible}
onPageChange={handlePageChange}
/>
<SideBarControl position="left" onClick={() => onPageChange(currentPage - 1)} />
<SideBarControl position="left" onClick={() => handlePageChange(currentPage - 1)} />
{/* TODO: better error handling for the loaded image */}
<img
className="z-30 max-h-full w-full select-none md:w-auto"
src={getPageUrl(currentPage)}
Expand All @@ -136,7 +138,7 @@ export default function PagedReader({
}}
onClick={toggleToolbar}
/>
<SideBarControl position="right" onClick={() => onPageChange(currentPage + 1)} />
<SideBarControl position="right" onClick={() => handlePageChange(currentPage + 1)} />
</div>
)
}
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading