headerActions.ts 766 B
Newer Older
Andrei Eres's avatar
Andrei Eres committed
import { action, atom } from 'nanostores'
Andrei Eres's avatar
Andrei Eres committed
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 headerActionsStore = atom<Action[]>([])
Andrei Eres's avatar
Andrei Eres committed

Andrei Eres's avatar
Andrei Eres committed
export const addHeaderAction = action(
  headerActionsStore,
  'add_header_action',
  (store, v: Action) => {
    store.set([...store.get(), v])
  }
)
Andrei Eres's avatar
Andrei Eres committed

Andrei Eres's avatar
Andrei Eres committed
export const resetHeaderActions = action(
  headerActionsStore,
  'reset_header_actions',
  (store) => {
    store.set([])
  }
)