Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSeage committed Nov 11, 2023
1 parent ec85cc4 commit 1a2fc0a
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions website/app/[locale]/(root)/play/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,22 @@ export default function Play(props: any) {
} else {
params.set(name, value);
}

return params.toString();
},
[],
);

useEffect(() => {
const urlSearchParams = new URLSearchParams(location.search)
const queryLayout = urlSearchParams.get('layout')
const queryPreview = urlSearchParams.get('preview')
setLayout(urlSearchParams.get('layout') || '')
setPreview(urlSearchParams.get('preview') || '')
const queryTab = urlSearchParams.get('tab')
if (queryLayout) {
setLayout(queryLayout)
}
if (queryPreview) {
setPreview(queryPreview)
}
if ([...shareItem.files.map(({ title }) => title)].includes(queryTab || '')) {
setCurrentTabTitle(queryTab)
} else {
setCurrentTabTitle(shareItem.files[0].title)
}
}, [createQueryString, pathname, router, searchParams, shareItem.files])
}, [pathname, router, searchParams, shareItem.files])

/**
* 避免切換到更大視口時仍停留在僅小視口支援的 Preview 或 Generated CSS 瀏覽模式
Expand All @@ -194,13 +187,13 @@ export default function Play(props: any) {
if (new URLSearchParams(location.search).get('layout') !== layout) {
router.push(pathname + '?' + createQueryString('layout', layout))
}
}, [createQueryString, layout, pathname, router, searchParams, shareId])
}, [layout, searchParams])

useEffect(() => {
if (new URLSearchParams(location.search).get('preview') !== preview) {
router.push(pathname + '?' + createQueryString('preview', preview))
}
}, [createQueryString, pathname, preview, router, searchParams, shareId])
}, [preview, searchParams])

/**
* 需避免即時編輯 HTML, Config 或切換 Theme 時更新 previewHTML,否則 Preview 將重載並造成視覺閃爍
Expand Down

0 comments on commit 1a2fc0a

Please sign in to comment.