1module Alfred exposing (..)
2
3import List.Extra as List
4import Material.Icons.Types exposing (Coloring)
5import Svg exposing (Svg)
6
7
8
9-- 🌳
10
11
12type alias Alfred msg =
13 { action : Action msg
14 , focus : Int
15 , index : List (Group msg)
16 , indexFlattened : List (Item msg)
17 , message : String
18 , operation : Operation
19 , results : List (Group msg)
20 , searchTerm : Maybe String
21 }
22
23
24type alias Action msg =
25 { result : Maybe (Item msg), searchTerm : Maybe String } -> List msg
26
27
28type alias Group msg =
29 { name : Maybe String, items : List (Item msg) }
30
31
32type alias Item msg =
33 { icon : Maybe (Coloring -> Svg msg)
34 , title : String
35 , value : ItemValue msg
36 }
37
38
39type ItemValue msg
40 = Command msg
41 | StringValue String
42
43
44type Operation
45 = Query
46 | QueryOrMutation
47 | Mutation
48
49
50
51-- 🛳
52
53
54create :
55 { action : Action msg
56 , index : List (Group msg)
57 , message : String
58 , operation : Operation
59 }
60 -> Alfred msg
61create { action, index, message, operation } =
62 { action = action
63 , focus = 0
64 , index = index
65 , indexFlattened = List.concatMap .items index
66 , message = message
67 , operation = operation
68 , results = index
69 , searchTerm = Nothing
70 }
71
72
73
74-- 🛠
75
76
77command : ItemValue msg -> Maybe msg
78command val =
79 case val of
80 Command cmd ->
81 Just cmd
82
83 StringValue _ ->
84 Nothing
85
86
87stringValue : ItemValue msg -> Maybe String
88stringValue val =
89 case val of
90 Command _ ->
91 Nothing
92
93 StringValue string ->
94 Just string
95
96
97
98-- 🛠
99
100
101getAt : Int -> Alfred msg -> Maybe (Item msg)
102getAt index alfred =
103 alfred.results
104 |> List.concatMap .items
105 |> List.getAt index
106
107
108length : Alfred msg -> Int
109length { indexFlattened } =
110 List.length indexFlattened