headerActions.ts 692 B
Newer Older
Andrei Eres's avatar
Andrei Eres committed
import { createStore, update } from 'nanostores'
import { goHome, goToImport } from '../utils/routing'

type Action = {
  label: string
  onAction: () => void
}

export const importHeaderAction: Action = {
  label: 'Import',
  onAction: goToImport,
}

export const cancelAndGoHomeHeaderAction: Action = {
Andrei Eres's avatar
Andrei Eres committed
  label: 'Cancel',
  onAction: goHome,
}

export const doneAndGoHomeHeaderAction: Action = {
  label: 'Done',
  onAction: goHome,
}

Andrei Eres's avatar
Andrei Eres committed
export const headerActions = createStore<Action[]>(() => {
  headerActions.set([])
})

export const addHeaderAction = (v: Action) => {
  update(headerActions, (list) => [...list, v])
}

export const resetHeaderActions = () => {
  headerActions.set([])
}