mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Use router instead of window.location to better handle the local cache
This commit is contained in:
parent
d56f4f9234
commit
788b44c7c9
3 changed files with 15 additions and 10 deletions
|
|
@ -10,6 +10,8 @@ export type OmnivoreLogoBaseProps = {
|
|||
}
|
||||
|
||||
export function OmnivoreLogoBase(props: OmnivoreLogoBaseProps): JSX.Element {
|
||||
const router = useRouter()
|
||||
|
||||
return (
|
||||
<Box
|
||||
style={{
|
||||
|
|
@ -20,14 +22,14 @@ export function OmnivoreLogoBase(props: OmnivoreLogoBaseProps): JSX.Element {
|
|||
onClick={(event) => {
|
||||
const navReturn = window.localStorage.getItem('nav-return')
|
||||
if (navReturn) {
|
||||
window.location.assign(navReturn)
|
||||
router.push(navReturn)
|
||||
return
|
||||
}
|
||||
const query = window.sessionStorage.getItem('q')
|
||||
if (query) {
|
||||
window.location.assign(`${DEFAULT_HOME_PATH}?${query}`)
|
||||
router.push(`${DEFAULT_HOME_PATH}?${query}`)
|
||||
} else {
|
||||
window.location.replace(DEFAULT_HOME_PATH)
|
||||
router.push(DEFAULT_HOME_PATH)
|
||||
}
|
||||
}}
|
||||
tabIndex={-1}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {
|
|||
useMergeHighlight,
|
||||
useUpdateHighlight,
|
||||
} from '../../../lib/networking/highlights/useItemHighlights'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export type PdfArticleContainerProps = {
|
||||
viewer: UserBasicData
|
||||
|
|
@ -38,12 +39,12 @@ export type PdfArticleContainerProps = {
|
|||
export default function PdfArticleContainer(
|
||||
props: PdfArticleContainerProps
|
||||
): JSX.Element {
|
||||
const router = useRouter()
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
const [notebookKey, setNotebookKey] = useState<string>(uuidv4())
|
||||
const [noteTarget, setNoteTarget] = useState<Highlight | undefined>(undefined)
|
||||
const [noteTargetPageIndex, setNoteTargetPageIndex] = useState<
|
||||
number | undefined
|
||||
>(undefined)
|
||||
const [noteTargetPageIndex, setNoteTargetPageIndex] =
|
||||
useState<number | undefined>(undefined)
|
||||
const highlightsRef = useRef<Highlight[]>([])
|
||||
const createHighlight = useCreateHighlight()
|
||||
const deleteHighlight = useDeleteHighlight()
|
||||
|
|
@ -481,14 +482,14 @@ export default function PdfArticleContainer(
|
|||
case 'u':
|
||||
const navReturn = window.localStorage.getItem('nav-return')
|
||||
if (navReturn) {
|
||||
window.location.assign(navReturn)
|
||||
router.push(navReturn)
|
||||
return
|
||||
}
|
||||
const query = window.sessionStorage.getItem('q')
|
||||
if (query) {
|
||||
window.location.assign(`${DEFAULT_HOME_PATH}?${query}`)
|
||||
router.push(`${DEFAULT_HOME_PATH}?${query}`)
|
||||
} else {
|
||||
window.location.replace(DEFAULT_HOME_PATH)
|
||||
router.push(DEFAULT_HOME_PATH)
|
||||
}
|
||||
break
|
||||
case 'e':
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ import { useCallback } from 'react'
|
|||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { useAddItem } from '../networking/library_items/useLibraryItems'
|
||||
import { showErrorToast, showSuccessToastWithAction } from '../toastHelpers'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export const useHandleAddUrl = () => {
|
||||
const router = useRouter()
|
||||
const addItem = useAddItem()
|
||||
return useCallback(async (url: string, timezone: string, locale: string) => {
|
||||
const itemId = uuidv4()
|
||||
|
|
@ -16,7 +18,7 @@ export const useHandleAddUrl = () => {
|
|||
console.log('result: ', result)
|
||||
if (result) {
|
||||
showSuccessToastWithAction('Item saving', 'Read now', async () => {
|
||||
window.location.href = `/article?url=${encodeURIComponent(url)}`
|
||||
router.push(`/article?url=${encodeURIComponent(url)}`)
|
||||
return Promise.resolve()
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue