blob: 491468c884a94a2d864d156825b6a7ef913c98af (
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
|
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
|