summaryrefslogtreecommitdiff
path: root/Handler/Common/Types.hs
blob: 9150f16c236137fd92f2b2875d4c45933a7c4a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE FunctionalDependencies #-}

module Handler.Common.Types where

import Import

import Control.Lens

data InventoryState = InventoryState
  { stock :: [WithType (Entity Item)]
  , invFormState :: Maybe (FormState ItemId)
  }

data ReferenceState = ReferenceState
  { reference :: [WithType (Entity Reference)]
  , refFormState :: Maybe (FormState ReferenceId)
  }

class HasFormState a where
  type family UpdateId a :: *
  formState :: a -> Maybe (FormState (UpdateId a))

instance HasFormState InventoryState where
  type UpdateId InventoryState = ItemId
  formState = invFormState

instance HasFormState ReferenceState where
  type UpdateId ReferenceState = ReferenceId
  formState = refFormState
  
data FormState id = InsertForm
                 { fsInsertForm :: Widget
                 , fsInsertEncoding :: Enctype
                 }
               | UpdateForm
                 { fsUpdateId :: id
                 , fsUpdateForm :: Widget
                 , fsUpdateEncoding :: Enctype
                 }
makeLensesWith abbreviatedFields ''FormState