2022-10-27 09:08:35 +02:00
|
|
|
import { writable, derived } from "svelte/store"
|
|
|
|
|
|
|
|
export const createSidePanelStore = () => {
|
|
|
|
const initialState = {
|
|
|
|
contentId: null,
|
|
|
|
}
|
|
|
|
const store = writable(initialState)
|
|
|
|
const derivedStore = derived(store, $store => {
|
|
|
|
return {
|
|
|
|
...$store,
|
|
|
|
open: $store.contentId != null,
|
|
|
|
}
|
|
|
|
})
|
2022-12-06 10:55:42 +01:00
|
|
|
let timeout
|
2022-10-27 09:08:35 +02:00
|
|
|
|
|
|
|
const open = id => {
|
2022-12-06 10:55:42 +01:00
|
|
|
clearTimeout(timeout)
|
2022-10-27 09:08:35 +02:00
|
|
|
store.update(state => {
|
|
|
|
state.contentId = id
|
|
|
|
return state
|
|
|
|
})
|
|
|
|
}
|
2022-12-06 10:55:42 +01:00
|
|
|
|
|
|
|
// Delay closing by 50ms to avoid toggling visibility when cycling though
|
|
|
|
// records
|
2022-10-27 09:08:35 +02:00
|
|
|
const close = () => {
|
2022-12-06 10:55:42 +01:00
|
|
|
timeout = setTimeout(() => {
|
|
|
|
store.update(state => {
|
|
|
|
state.contentId = null
|
|
|
|
return state
|
|
|
|
})
|
|
|
|
}, 50)
|
2022-10-27 09:08:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: derivedStore.subscribe,
|
|
|
|
actions: {
|
|
|
|
open,
|
|
|
|
close,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const sidePanelStore = createSidePanelStore()
|