Fix viewport params for pages. (#3079)

This commit is contained in:
Mitja Bezenšek 2024-03-07 15:50:25 +01:00 committed by GitHub
parent 40aeebab46
commit 40c20e5585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,6 +50,17 @@ export function useUrlState(onChangeUrl: (params: UrlStateParams) => void) {
const url = new URL(location.href)
// We need to check the page first so that any changes to the camera will be applied to the correct page.
if (url.searchParams.has(PARAMS.page) || url.searchParams.has(PARAMS.p)) {
const newPageId =
url.searchParams.get(PARAMS.page) ?? 'page:' + url.searchParams.get(PARAMS.p)
if (newPageId) {
if (editor.store.has(newPageId as TLPageId)) {
editor.setCurrentPage(newPageId as TLPageId)
}
}
}
if (url.searchParams.has(PARAMS.viewport) || url.searchParams.has(PARAMS.v)) {
const newViewportRaw = url.searchParams.get(PARAMS.viewport) ?? url.searchParams.get(PARAMS.v)
if (newViewportRaw) {
@ -70,15 +81,6 @@ export function useUrlState(onChangeUrl: (params: UrlStateParams) => void) {
}
}
}
if (url.searchParams.has(PARAMS.page) || url.searchParams.has(PARAMS.p)) {
const newPageId =
url.searchParams.get(PARAMS.page) ?? 'page:' + url.searchParams.get(PARAMS.p)
if (newPageId) {
if (editor.store.has(newPageId as TLPageId)) {
editor.setCurrentPage(newPageId as TLPageId)
}
}
}
const handleChange = debounce((params: UrlStateParams | null) => {
if (params) onChangeUrlRef.current(params)