feat: preserve media dialog state in browser history (#743)

zio/stable
Ivan Demchuk 2023-01-05 18:51:50 +02:00 committed by GitHub
parent c68c7ad507
commit 7e794aa641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -57,14 +57,33 @@ if (isPreviewHelpOpen.value) {
}) })
} }
function restoreMediaPreviewFromState() {
mediaPreviewList.value = JSON.parse(history.state?.mediaPreviewList ?? '[]')
mediaPreviewIndex.value = history.state?.mediaPreviewIndex ?? 0
isMediaPreviewOpen.value = history.state?.mediaPreview ?? false
}
if (process.client) {
window.addEventListener('popstate', restoreMediaPreviewFromState)
restoreMediaPreviewFromState()
}
export function openMediaPreview(attachments: Attachment[], index = 0) { export function openMediaPreview(attachments: Attachment[], index = 0) {
mediaPreviewList.value = attachments mediaPreviewList.value = attachments
mediaPreviewIndex.value = index mediaPreviewIndex.value = index
isMediaPreviewOpen.value = true isMediaPreviewOpen.value = true
history.pushState({
...history.state,
mediaPreview: true,
mediaPreviewList: JSON.stringify(attachments),
mediaPreviewIndex: index,
}, '')
} }
export function closeMediaPreview() { export function closeMediaPreview() {
isMediaPreviewOpen.value = false history.back()
} }
export function openEditHistoryDialog(edit: StatusEdit) { export function openEditHistoryDialog(edit: StatusEdit) {