2022-02-24 15:41:24 +01:00
|
|
|
import { writable } from "svelte/store"
|
|
|
|
|
|
|
|
export function createBannerStore() {
|
2022-09-13 12:52:31 +02:00
|
|
|
const DEFAULT_CONFIG = {
|
|
|
|
messages: [],
|
|
|
|
}
|
2022-02-24 15:41:24 +01:00
|
|
|
|
|
|
|
const banner = writable(DEFAULT_CONFIG)
|
|
|
|
|
|
|
|
const show = async (
|
|
|
|
// eslint-disable-next-line
|
|
|
|
config = { message, type, extraButtonText, extraButtonAction, onChange }
|
|
|
|
) => {
|
|
|
|
banner.update(store => {
|
|
|
|
return {
|
|
|
|
...store,
|
|
|
|
...config,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const showStatus = async () => {
|
|
|
|
const config = {
|
|
|
|
message: "Some systems are experiencing issues",
|
|
|
|
type: "negative",
|
|
|
|
extraButtonText: "View Status",
|
|
|
|
extraButtonAction: () => window.open("https://status.budibase.com/"),
|
|
|
|
}
|
|
|
|
|
|
|
|
await show(config)
|
|
|
|
}
|
|
|
|
|
2022-09-13 12:52:31 +02:00
|
|
|
const queue = async entries => {
|
|
|
|
banner.update(store => {
|
|
|
|
const sorted = [...store.messages, ...entries].sort(
|
|
|
|
(a, b) => a.priority > b.priority
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
...store,
|
|
|
|
messages: sorted,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-24 15:41:24 +01:00
|
|
|
return {
|
|
|
|
subscribe: banner.subscribe,
|
|
|
|
showStatus,
|
2022-09-13 12:52:31 +02:00
|
|
|
show,
|
|
|
|
queue,
|
2022-02-24 15:41:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const banner = createBannerStore()
|