forked from Mirrors/elk
feat: preserve media dialog state in browser history (#743)
This commit is contained in:
parent
c68c7ad507
commit
7e794aa641
1 changed files with 20 additions and 1 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue