Skip to content

Commit 77d1bda

Browse files
committed
feat(timeline): save panes split
1 parent 265b6d7 commit 77d1bda

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/app-frontend/src/features/layout/SplitPane.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { ref, computed } from '@vue/composition-api'
2+
import { ref, computed, watch } from '@vue/composition-api'
33
import { useOrientation } from './orientation'
44
55
export default {
@@ -23,13 +23,41 @@ export default {
2323
type: String,
2424
default: 'center',
2525
validator: value => ['before', 'center', 'after'].includes(value)
26+
},
27+
28+
saveId: {
29+
type: String,
30+
default: null
2631
}
2732
},
2833
2934
setup (props) {
3035
const { orientation } = useOrientation()
3136
3237
const split = ref(props.defaultSplit)
38+
39+
if (props.saveId) {
40+
const storageKey = `split-pane-${props.saveId}`
41+
42+
const savedValue = localStorage.getItem(storageKey)
43+
if (savedValue != null) {
44+
let parsedValue
45+
try {
46+
parsedValue = JSON.parse(savedValue)
47+
} catch (e) {
48+
console.error(e)
49+
}
50+
51+
if (typeof parsedValue === 'number') {
52+
split.value = parsedValue
53+
}
54+
}
55+
56+
watch(split, value => {
57+
localStorage.setItem(storageKey, JSON.stringify(value))
58+
})
59+
}
60+
3361
const boundSplit = computed(() => {
3462
if (split.value < props.min) {
3563
return props.min

packages/app-frontend/src/features/timeline/Timeline.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default {
6969
<template>
7070
<div>
7171
<SplitPane
72+
save-id="timeline-left-main"
7273
:default-split="25"
7374
dragger-offset="before"
7475
>
@@ -96,6 +97,7 @@ export default {
9697

9798
<template #right>
9899
<SplitPane
100+
save-id="timeline-right"
99101
:default-split="70"
100102
:max="85"
101103
dragger-offset="after"

0 commit comments

Comments
 (0)