budibase/packages/bbui/src/Stores/banner.js

54 lines
1.1 KiB
JavaScript
Raw Normal View History

import { writable } from "svelte/store"
export function createBannerStore() {
2022-09-13 12:52:31 +02:00
const DEFAULT_CONFIG = {
messages: [],
}
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,
}
})
}
return {
subscribe: banner.subscribe,
showStatus,
2022-09-13 12:52:31 +02:00
show,
queue,
}
}
export const banner = createBannerStore()