This repository was archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAppModal.elm
293 lines (228 loc) · 9.5 KB
/
AppModal.elm
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
module UnisonShare.AppModal exposing (..)
import Definition.Reference exposing (Reference)
import Env exposing (Env, OperatingSystem(..))
import Finder
import Finder.SearchOptions as SearchOptions
import FullyQualifiedName as FQN exposing (FQN)
import Html exposing (Html, a, div, h3, p, section, span, strong, text)
import Html.Attributes exposing (class, href, rel, target)
import KeyboardShortcut
import KeyboardShortcut.Key as Key exposing (Key(..))
import UI
import UI.Button as Button
import UI.CopyField as CopyField
import UI.Modal as Modal
-- MODEL
type AppModal
= FinderModal Finder.Model
| KeyboardShortcutsModal
| ReportBugModal
| PublishModal
| DownloadModal FQN
type Model
= NoModal
| Visible AppModal
init : Model
init =
NoModal
-- UPDATE
type Msg
= Close
| FinderMsg Finder.Msg
type OutMsg
= None
| OpenDefinition Reference
update : Env -> Msg -> Model -> ( Model, Cmd Msg, OutMsg )
update env msg model =
case ( model, msg ) of
( Visible (FinderModal fModel), FinderMsg fMsg ) ->
let
( fm, fc, out ) =
Finder.update env fMsg fModel
in
case out of
Finder.Remain ->
( Visible (FinderModal fm), Cmd.map FinderMsg fc, None )
Finder.Exit ->
( close, Cmd.none, None )
Finder.OpenDefinition ref ->
( close, Cmd.none, OpenDefinition ref )
( Visible _, Close ) ->
( close, Cmd.none, None )
_ ->
( model, Cmd.none, None )
-- API
show : AppModal -> ( Model, Cmd Msg )
show modal =
( Visible modal, Cmd.none )
showFinder : Env -> Maybe FQN -> ( Model, Cmd Msg )
showFinder env withinNamespace =
let
options =
SearchOptions.init env.perspective withinNamespace
( fm, fcmd ) =
Finder.init env options
in
( Visible (FinderModal fm), Cmd.map FinderMsg fcmd )
close : Model
close =
NoModal
isOpen : Model -> Bool
isOpen model =
model == NoModal
modalIs : Model -> AppModal -> Bool
modalIs model modal =
case model of
NoModal ->
False
Visible m ->
m == modal
-- VIEW
viewDownloadModal : FQN -> Html Msg
viewDownloadModal fqn =
let
prettyName =
FQN.toString fqn
unqualified =
FQN.unqualifiedName fqn
pullCommand =
"pull git@github.com:unisonweb/share.git:." ++ prettyName ++ " ." ++ unqualified
content =
Modal.Content
(section
[]
[ p [] [ text "Download ", UI.bold prettyName, text " by pulling the namespace from Unison Share into a namespace in your local codebase:" ]
, CopyField.copyField (\_ -> Close) pullCommand |> CopyField.withPrefix ".>" |> CopyField.view
, div [ class "hint" ] [ text "Copy and paste this command into UCM." ]
]
)
in
Modal.modal "download-modal" Close content
|> Modal.withHeader ("Download " ++ prettyName)
|> Modal.view
viewKeyboardShortcutsModal : OperatingSystem -> KeyboardShortcut.Model -> Html Msg
viewKeyboardShortcutsModal os keyboardShortcut =
let
viewRow label instructions =
div
[ class "row" ]
[ label
, div [ class "instructions" ] instructions
]
viewInstructions label shortcuts =
viewRow label [ KeyboardShortcut.viewShortcuts keyboardShortcut shortcuts ]
openFinderInstructions =
case os of
MacOS ->
[ KeyboardShortcut.Chord Meta (K Key.Lower), KeyboardShortcut.Chord Ctrl (K Key.Lower), KeyboardShortcut.single ForwardSlash ]
_ ->
[ KeyboardShortcut.Chord Ctrl (K Key.Lower), KeyboardShortcut.single ForwardSlash ]
toggleSidebarInstructions =
case os of
MacOS ->
[ KeyboardShortcut.Chord Meta (B Key.Lower), KeyboardShortcut.Chord Ctrl (B Key.Lower) ]
_ ->
[ KeyboardShortcut.Chord Ctrl (B Key.Lower), KeyboardShortcut.single (S Key.Lower) ]
content =
Modal.Content
(section
[ class "shortcuts" ]
[ div [ class "shortcut-group" ]
[ h3 [] [ text "General" ]
, viewInstructions (span [] [ text "Keyboard shortcuts", UI.subtle " (this dialog)" ]) [ KeyboardShortcut.single QuestionMark ]
, viewInstructions (text "Open Finder") openFinderInstructions
, viewInstructions (text "Toggle sidebar") toggleSidebarInstructions
, viewInstructions (text "Move focus up") [ KeyboardShortcut.single ArrowUp, KeyboardShortcut.single (K Key.Lower) ]
, viewInstructions (text "Move focus down") [ KeyboardShortcut.single ArrowDown, KeyboardShortcut.single (J Key.Lower) ]
, viewInstructions (text "Close focused definition") [ KeyboardShortcut.single (X Key.Lower) ]
, viewInstructions (text "Expand/Collapse focused definition") [ KeyboardShortcut.single Space ]
]
, div [ class "shortcut-group" ]
[ h3 [] [ text "Finder" ]
, viewInstructions (text "Clear search query") [ KeyboardShortcut.single Escape ]
, viewInstructions (span [] [ text "Close", UI.subtle " (when search query is empty)" ]) [ KeyboardShortcut.single Escape ]
, viewInstructions (text "Move focus up") [ KeyboardShortcut.single ArrowUp ]
, viewInstructions (text "Move focus down") [ KeyboardShortcut.single ArrowDown ]
, viewInstructions (text "Open focused definition") [ KeyboardShortcut.single Enter ]
, viewRow (text "Open definition")
[ KeyboardShortcut.viewBase
[ KeyboardShortcut.viewKey os Semicolon False
, KeyboardShortcut.viewThen
, KeyboardShortcut.viewKeyBase "1-9" False
]
]
]
]
)
in
Modal.modal "help-modal" Close content
|> Modal.withHeader "Keyboard shortcuts"
|> Modal.view
viewPublishModal : Html Msg
viewPublishModal =
let
content =
Modal.Content
(section
[]
[ p [ class "main" ]
[ text "With your Unison codebase on GitHub, open a Pull Request against "
, Button.github "unisonweb/share" |> Button.view
, text " to list (or unlist) your project on Unison Share."
]
, a [ class "help", href "https://www.unisonweb.org/docs/codebase-organization/#day-to-day-development-creating-and-merging-pull-requests", rel "noopener", target "_blank" ] [ text "How do I get my code on GitHub?" ]
]
)
in
Modal.modal "publish-modal" Close content
|> Modal.withHeader "Publish your project on Unison Share"
|> Modal.view
viewReportBugModal : Html Msg
viewReportBugModal =
let
content =
Modal.Content
(div []
[ section []
[ p [] [ text "We try our best, but bugs unfortunately creep through :(" ]
, p [] [ text "We greatly appreciate feedback and bug reports—its very helpful for providing the best developer experience when working with Unison." ]
]
, UI.divider
, section [ class "actions" ]
[ p [] [ text "Visit our GitHub repositories to report bugs and provide feedback" ]
, div [ class "action" ]
[ Button.github "unisonweb/codebase-ui" |> Button.view
, text "for reports on"
, strong [] [ text "Unison Share" ]
, span [ class "subtle" ] [ text "(this UI)" ]
]
, div [ class "action" ]
[ Button.github "unisonweb/unison" |> Button.view
, text "for reports on the"
, strong [] [ text "Unison Language" ]
, span [ class "subtle" ] [ text "(UCM)" ]
]
]
]
)
in
Modal.modal "report-bug-modal" Close content
|> Modal.withHeader "Report a Bug"
|> Modal.view
view : Env -> Model -> Html Msg
view env model =
case model of
NoModal ->
UI.nothing
Visible (FinderModal m) ->
Html.map FinderMsg (Finder.view m)
Visible KeyboardShortcutsModal ->
viewKeyboardShortcutsModal
env.operatingSystem
(KeyboardShortcut.init env.operatingSystem)
Visible PublishModal ->
viewPublishModal
Visible ReportBugModal ->
viewReportBugModal
Visible (DownloadModal fqn) ->
viewDownloadModal fqn