Start to use nav return in most places to return to the previous library section

This commit is contained in:
Jackson Harper
2024-06-21 10:56:20 +08:00
parent f91c4cd5b5
commit f33e5323c6
12 changed files with 23 additions and 19 deletions

View File

@ -40,7 +40,7 @@ export function HomeContainer(): JSX.Element {
}, [viewerData])
useEffect(() => {
window.sessionStorage.setItem('nav-return', router.asPath)
window.localStorage.setItem('nav-return', router.asPath)
}, [router.asPath])
return (

View File

@ -95,7 +95,7 @@ export function LibraryGridCard(props: LinkedItemCardProps): JSX.Element {
props.setIsChecked(props.item.id, !props.isChecked)
return
}
window.sessionStorage.setItem('nav-return', router.asPath)
window.localStorage.setItem('nav-return', router.asPath)
if (event.metaKey || event.ctrlKey) {
window.open(
`/${props.viewer.profile.username}/${props.item.slug}`,

View File

@ -100,7 +100,7 @@ export function LibraryListCard(props: LinkedItemCardProps): JSX.Element {
props.setIsChecked(props.item.id, !props.isChecked)
return
}
window.sessionStorage.setItem('nav-return', router.asPath)
window.localStorage.setItem('nav-return', router.asPath)
if (event.metaKey || event.ctrlKey) {
window.open(
`/${props.viewer.profile.username}/${props.item.slug}`,

View File

@ -32,7 +32,7 @@ const ReturnButton = (): JSX.Element => {
},
}}
>
<Link href="/home">
<Link href="/l/home">
<HStack
css={{
pl: '20px',

View File

@ -35,9 +35,8 @@ export default function PdfArticleContainer(
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 annotationOmnivoreId = (annotation: Annotation): string | undefined => {
@ -449,16 +448,16 @@ export default function PdfArticleContainer(
document.dispatchEvent(new Event('openOriginalArticle'))
break
case 'u':
const navReturn = window.sessionStorage.getItem('nav-return')
const navReturn = window.localStorage.getItem('nav-return')
if (navReturn) {
window.location.assign(navReturn)
return
}
const query = window.sessionStorage.getItem('q')
if (query) {
window.location.assign(`/home?${query}`)
window.location.assign(`/l/home?${query}`)
} else {
window.location.replace(`/home`)
window.location.replace(`/l/home`)
}
break
case 'e':

View File

@ -89,7 +89,7 @@ export default function Home(): JSX.Element {
// return
// }
// }
const navReturn = window.sessionStorage.getItem('nav-return')
const navReturn = window.localStorage.getItem('nav-return')
if (navReturn) {
router.push(navReturn)
return
@ -303,7 +303,7 @@ export default function Home(): JSX.Element {
name: 'Return to library',
shortcut: ['u'],
perform: () => {
const navReturn = window.sessionStorage.getItem('nav-return')
const navReturn = window.localStorage.getItem('nav-return')
if (navReturn) {
router.push(navReturn)
return

View File

@ -43,12 +43,12 @@ const generateActions = (router: NextRouter) => {
shortcut: ['g', 'h'],
keywords: 'go home',
perform: () => {
const navReturn = window.sessionStorage.getItem('nav-return')
const navReturn = window.localStorage.getItem('nav-return')
if (navReturn) {
router.push(navReturn)
return
}
router?.push('/home')
router?.push('/l/home')
},
},
{

View File

@ -29,7 +29,7 @@ const requestHandler = (req: NextApiRequest, res: NextApiResponse): void => {
})
} else {
res.writeHead(302, {
Location: '/home',
Location: '/l/home',
})
}

View File

@ -9,7 +9,12 @@ export default function LandingPage(): JSX.Element {
const { viewerData, isLoading } = useGetViewerQuery()
if (!isLoading && router.isReady && viewerData?.me) {
router.push('/home')
const navReturn = window.localStorage.getItem('nav-return')
if (navReturn) {
router.push(navReturn)
} else {
router.push('/l/home')
}
return <></>
} else if (isLoading || !router.isReady) {
return (

View File

@ -202,7 +202,7 @@ export default function BulkPerformer(): JSX.Element {
<VStack css={{ width: '100%' }} alignment="center">
<Button
onClick={(e) => {
window.location.href = '/home'
window.location.href = '/l/home'
e.preventDefault()
}}
style="ctaDarkYellow"

View File

@ -240,7 +240,7 @@ export default function ImportUploader(): JSX.Element {
{uploadState == 'completed' && (
<Button
onClick={(e) => {
window.location.href = '/home'
window.location.href = '/l/home'
e.preventDefault()
}}
style="ctaDarkYellow"

View File

@ -190,7 +190,7 @@ export default function ImportUploader(): JSX.Element {
<VStack css={{ width: '100%' }} alignment="center">
<Button
onClick={(e) => {
window.location.href = '/home'
window.location.href = '/l/home'
e.preventDefault()
}}
style="ctaDarkYellow"