Skip to content
Open
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
5 changes: 1 addition & 4 deletions apps/reader/src/components/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
hasSelection,
useBackground,
useColorScheme,
useDisablePinchZooming,
useMobile,
useSync,
useTranslation,
Expand Down Expand Up @@ -384,8 +383,6 @@ function BookPane({ tab, onMouseDown }: BookPaneProps) {
}
})

useDisablePinchZooming(iframe)

return (
<div className={clsx('flex h-full flex-col', mobile && 'py-[3vw]')}>
<PhotoSlider
Expand Down Expand Up @@ -500,4 +497,4 @@ const Bar: React.FC<LineProps> = ({ className, ...props }) => {
{...props}
></div>
)
}
}
5 changes: 4 additions & 1 deletion apps/reader/src/components/TextSelectionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const TextSelectionMenuRenderer: React.FC<TextSelectionMenuRendererProps> = ({
setWidth(el.clientWidth)
setHeight(el.clientHeight)
if (!mobile) {
el.focus()
el.focus({ preventScroll: true })
}
}}
className={clsx(
Expand All @@ -188,6 +188,9 @@ const TextSelectionMenuRenderer: React.FC<TextSelectionMenuRendererProps> = ({
copy(text)
}
}}
onMouseDown={(e) => {
e.stopPropagation()
}}
>
{annotate ? (
<div className="mb-3">
Expand Down
5 changes: 4 additions & 1 deletion apps/reader/src/hooks/useDisablePinchZooming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export function useDisablePinchZooming(win?: Window) {
const _win = win ?? window
// Block pinch-zooming on iOS outside of the content area
const handleTouchMove = (event: TouchEvent) => {
event.preventDefault()
// event.preventDefault()
if ((event as any).scale !== 1) {
event.preventDefault()
}
}

_win.document.addEventListener('touchmove', handleTouchMove, {
Expand Down
52 changes: 24 additions & 28 deletions apps/reader/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import {
MdOutlineShare,
} from 'react-icons/md'
import { useSet } from 'react-use'
import { usePrevious } from 'react-use'

import { ReaderGridView, Button, TextField, DropZone } from '../components'
import { BookRecord, CoverRecord, db } from '../db'
import { addFile, fetchBook, handleFiles } from '../file'
import {
useDisablePinchZooming,
useLibrary,
useMobile,
useRemoteBooks,
Expand All @@ -40,8 +38,6 @@ export default function Index() {
const src = new URL(window.location.href).searchParams.get(SOURCE)
const [loading, setLoading] = useState(!!src)

useDisablePinchZooming()

useEffect(() => {
let src = router.query[SOURCE]
if (!src) return
Expand Down Expand Up @@ -102,43 +98,24 @@ const Library: React.FC = () => {

const { data: remoteBooks, mutate: mutateRemoteBooks } = useRemoteBooks()
const { data: remoteFiles, mutate: mutateRemoteFiles } = useRemoteFiles()
const previousRemoteBooks = usePrevious(remoteBooks)
const previousRemoteFiles = usePrevious(remoteFiles)

const [select, toggleSelect] = useBoolean(false)
const [selectedBookIds, { add, has, toggle, reset }] = useSet<string>()

const [loading, setLoading] = useState<string | undefined>()
const [readyToSync, setReadyToSync] = useState(false)
const [syncVersion, setSyncVersion] = useState(0)

const { groups } = useReaderSnapshot()

useEffect(() => {
if (previousRemoteFiles && remoteFiles) {
// to remove effect dependency `books`
db?.books.toArray().then((books) => {
if (books.length === 0) return

const newRemoteBooks = remoteFiles.map((f) =>
books.find((b) => b.name === f.name),
) as BookRecord[]

uploadData(newRemoteBooks)
mutateRemoteBooks(newRemoteBooks, { revalidate: false })
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mutateRemoteBooks, remoteFiles])

useEffect(() => {
if (!previousRemoteBooks && remoteBooks) {
db?.books.bulkPut(remoteBooks).then(() => setReadyToSync(true))
if (remoteBooks) {
db?.books.bulkPut(remoteBooks).then(() => setSyncVersion((v) => v + 1))
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [remoteBooks])

useEffect(() => {
if (!remoteFiles || !readyToSync) return
if (!remoteFiles || !syncVersion) return

db?.books.toArray().then(async (books) => {
for (const remoteFile of remoteFiles) {
Expand All @@ -158,7 +135,7 @@ const Library: React.FC = () => {
setLoading(undefined)
}
})
}, [readyToSync, remoteFiles])
}, [syncVersion, remoteFiles])

useEffect(() => {
if (!select) reset()
Expand Down Expand Up @@ -268,6 +245,16 @@ const Library: React.FC = () => {
setLoading(undefined)

mutateRemoteFiles()
mutateRemoteBooks((remoteBooks) => {
const newRemoteBooks = [
...(remoteBooks || []),
...selectedBooks.filter(
(b) => !remoteBooks?.find((r) => r.id === b.id),
),
]
uploadData(newRemoteBooks)
return newRemoteBooks
})
}
}}
>
Expand Down Expand Up @@ -296,6 +283,15 @@ const Library: React.FC = () => {
},
{ revalidate: false },
)

mutateRemoteBooks((remoteBooks) => {
const newRemoteBooks =
remoteBooks?.filter(
(b) => !selectedBooks.find((s) => s.id === b.id),
) || []
uploadData(newRemoteBooks)
return newRemoteBooks
})
}}
>
{t('delete')}
Expand Down