elm-pages 3.0.12 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -26
- package/codegen/elm-pages-codegen.cjs +13695 -11461
- package/generator/src/build.js +15 -5
- package/generator/src/cli.js +3 -5
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/dev-server.js +3 -0
- package/generator/src/render.js +681 -50
- package/generator/src/request-cache.js +13 -6
- package/generator/src/spinnies/index.js +200 -0
- package/generator/src/spinnies/utils.js +123 -0
- package/generator/src/validate-stream.js +25 -0
- package/package.json +4 -2
- package/src/BackendTask/Custom.elm +38 -0
- package/src/BackendTask/Do.elm +233 -0
- package/src/BackendTask/File.elm +24 -9
- package/src/BackendTask/Glob.elm +208 -25
- package/src/BackendTask/Http.elm +32 -21
- package/src/BackendTask/Internal/Glob.elm +16 -4
- package/src/BackendTask/Stream.elm +1179 -0
- package/src/BackendTask.elm +214 -7
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform.elm +11 -2
- package/src/Pages/Script/Spinner.elm +505 -0
- package/src/Pages/Script.elm +199 -2
- package/src/Pages/StaticHttp/Request.elm +7 -0
- package/src/RequestsAndPending.elm +1 -1
- package/src/Scaffold/Form.elm +2 -3
- package/src/TerminalText.elm +8 -0
- package/src/Vendored/Result/Extra.elm +75 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +0 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -28657
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +0 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +0 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -30511
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
- package/generator/review/elm-stuff/tests-0.19.1/js/package.json +0 -1
- package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
- package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
- package/src/Result/Extra.elm +0 -26
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
module Pages.Script.Spinner exposing
|
|
2
|
+
( Steps(..), steps, withStep
|
|
3
|
+
, withStepWithOptions
|
|
4
|
+
, runSteps
|
|
5
|
+
, Options, options
|
|
6
|
+
, CompletionIcon(..)
|
|
7
|
+
, withOnCompletion
|
|
8
|
+
, runTask, runTaskWithOptions
|
|
9
|
+
, showStep, runSpinnerWithTask, Spinner
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
{-|
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Running Steps
|
|
16
|
+
|
|
17
|
+
The easiest way to use spinners is to define a series of [`Steps`](#Steps) and then run them with [`runSteps`](#runSteps).
|
|
18
|
+
|
|
19
|
+
Steps are a sequential series of `BackendTask`s that are run one after the other. If a step fails (has a [`FatalError`](FatalError)),
|
|
20
|
+
its spinner will show a failure, and the remaining steps will not be run and will be displayed as cancelled (the step name in gray).
|
|
21
|
+
|
|
22
|
+
module StepsDemo exposing (run)
|
|
23
|
+
|
|
24
|
+
import BackendTask exposing (BackendTask)
|
|
25
|
+
import Pages.Script as Script exposing (Script)
|
|
26
|
+
import Pages.Script.Spinner as Spinner
|
|
27
|
+
|
|
28
|
+
run : Script
|
|
29
|
+
run =
|
|
30
|
+
Script.withoutCliOptions
|
|
31
|
+
(Spinner.steps
|
|
32
|
+
|> Spinner.withStep "Compile Main.elm" (\() -> Script.exec "elm" [ "make", "src/Main.elm", "--output=/dev/null" ])
|
|
33
|
+
|> Spinner.withStep "Verify formatting" (\() -> Script.exec "elm-format" [ "--validate", "src/" ])
|
|
34
|
+
|> Spinner.withStep "elm-review" (\() -> Script.exec "elm-review" [])
|
|
35
|
+
|> Spinner.runSteps
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@docs Steps, steps, withStep
|
|
39
|
+
|
|
40
|
+
@docs withStepWithOptions
|
|
41
|
+
|
|
42
|
+
@docs runSteps
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Configuring Steps
|
|
46
|
+
|
|
47
|
+
@docs Options, options
|
|
48
|
+
|
|
49
|
+
@docs CompletionIcon
|
|
50
|
+
|
|
51
|
+
@docs withOnCompletion
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Running with BackendTask
|
|
55
|
+
|
|
56
|
+
@docs runTask, runTaskWithOptions
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Low-Level
|
|
60
|
+
|
|
61
|
+
@docs showStep, runSpinnerWithTask, Spinner
|
|
62
|
+
|
|
63
|
+
-}
|
|
64
|
+
|
|
65
|
+
import BackendTask exposing (BackendTask)
|
|
66
|
+
import BackendTask.Http
|
|
67
|
+
import BackendTask.Internal.Request
|
|
68
|
+
import FatalError exposing (FatalError)
|
|
69
|
+
import Json.Decode as Decode
|
|
70
|
+
import Json.Encode as Encode
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
{-| An icon used to indicate the completion status of a step. Set by using [`withOnCompletion`](#withOnCompletion).
|
|
74
|
+
-}
|
|
75
|
+
type CompletionIcon
|
|
76
|
+
= Succeed
|
|
77
|
+
| Fail
|
|
78
|
+
| Warn
|
|
79
|
+
| Info
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
{-| Configuration that can be used with [`runTaskWithOptions`](#runTaskWithOptions) and [`withStepWithOptions`](#withStepWithOptions).
|
|
83
|
+
-}
|
|
84
|
+
type Options error value
|
|
85
|
+
= Options
|
|
86
|
+
{ text : String
|
|
87
|
+
, animation : Maybe String
|
|
88
|
+
, immediateStart : Bool
|
|
89
|
+
, onCompletion : Result error value -> ( CompletionIcon, Maybe String )
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
{-| Set the completion icon and text based on the result of the task.
|
|
94
|
+
|
|
95
|
+
import Pages.Script.Spinner as Spinner
|
|
96
|
+
|
|
97
|
+
example =
|
|
98
|
+
Spinner.options "Fetching data"
|
|
99
|
+
|> Spinner.withOnCompletion
|
|
100
|
+
(\result ->
|
|
101
|
+
case result of
|
|
102
|
+
Ok _ ->
|
|
103
|
+
( Spinner.Succeed, "Fetched data!" )
|
|
104
|
+
|
|
105
|
+
Err _ ->
|
|
106
|
+
( Spinner.Fail
|
|
107
|
+
, Just "Could not fetch data."
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
-}
|
|
112
|
+
withOnCompletion : (Result error value -> ( CompletionIcon, Maybe String )) -> Options error value -> Options error value
|
|
113
|
+
withOnCompletion function (Options options_) =
|
|
114
|
+
Options { options_ | onCompletion = function }
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
{-| -}
|
|
118
|
+
type Spinner error value
|
|
119
|
+
= Spinner String (Options error value)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
{-| The default options for a spinner. The spinner `text` is a required argument and will be displayed as the step name.
|
|
123
|
+
|
|
124
|
+
import Pages.Script.Spinner as Spinner
|
|
125
|
+
|
|
126
|
+
example =
|
|
127
|
+
Spinner.options "Compile Main.elm"
|
|
128
|
+
|
|
129
|
+
-}
|
|
130
|
+
options : String -> Options error value
|
|
131
|
+
options text =
|
|
132
|
+
Options
|
|
133
|
+
{ text = text
|
|
134
|
+
, animation = Nothing
|
|
135
|
+
, immediateStart = False
|
|
136
|
+
, onCompletion =
|
|
137
|
+
\result ->
|
|
138
|
+
case result of
|
|
139
|
+
Ok _ ->
|
|
140
|
+
( Succeed, Nothing )
|
|
141
|
+
|
|
142
|
+
Err _ ->
|
|
143
|
+
( Fail, Nothing )
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
--{-| -}
|
|
149
|
+
--withNamedAnimation : String -> Options error value -> Options error value
|
|
150
|
+
--withNamedAnimation animationName (Options options_) =
|
|
151
|
+
-- Options { options_ | animation = Just animationName }
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
{-| `showStep` gives you a `Spinner` reference which you can use to start the spinner later with `runSpinnerWithTask`.
|
|
155
|
+
|
|
156
|
+
Most use cases can be achieved more easily using more high-level helpers, like [`runTask`](#runTask) or [`steps`](#steps).
|
|
157
|
+
`showStep` can be useful if you have more dynamic steps that you want to reveal over time.
|
|
158
|
+
|
|
159
|
+
module ShowStepDemo exposing (run)
|
|
160
|
+
|
|
161
|
+
import BackendTask exposing (BackendTask)
|
|
162
|
+
import Pages.Script as Script exposing (Script, doThen, sleep)
|
|
163
|
+
import Pages.Script.Spinner as Spinner
|
|
164
|
+
|
|
165
|
+
run : Script
|
|
166
|
+
run =
|
|
167
|
+
Script.withoutCliOptions
|
|
168
|
+
(BackendTask.succeed
|
|
169
|
+
(\spinner1 spinner2 spinner3 ->
|
|
170
|
+
sleep 3000
|
|
171
|
+
|> Spinner.runSpinnerWithTask spinner1
|
|
172
|
+
|> doThen
|
|
173
|
+
(sleep 3000
|
|
174
|
+
|> Spinner.runSpinnerWithTask spinner2
|
|
175
|
+
|> doThen
|
|
176
|
+
(sleep 3000
|
|
177
|
+
|> Spinner.runSpinnerWithTask spinner3
|
|
178
|
+
)
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
|> BackendTask.andMap
|
|
182
|
+
(Spinner.options "Step 1" |> Spinner.showStep)
|
|
183
|
+
|> BackendTask.andMap
|
|
184
|
+
(Spinner.options "Step 2" |> Spinner.showStep)
|
|
185
|
+
|> BackendTask.andMap
|
|
186
|
+
(Spinner.options "Step 3" |> Spinner.showStep)
|
|
187
|
+
|> BackendTask.andThen identity
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
-}
|
|
191
|
+
showStep : Options error value -> BackendTask error (Spinner error value)
|
|
192
|
+
showStep (Options options_) =
|
|
193
|
+
BackendTask.Internal.Request.request
|
|
194
|
+
{ name = "start-spinner"
|
|
195
|
+
, body =
|
|
196
|
+
BackendTask.Http.jsonBody
|
|
197
|
+
([ ( "text", Encode.string options_.text ) |> Just
|
|
198
|
+
, ( "immediateStart", Encode.bool options_.immediateStart ) |> Just
|
|
199
|
+
, options_.animation |> Maybe.map (\animation -> ( "spinner", Encode.string animation ))
|
|
200
|
+
]
|
|
201
|
+
|> List.filterMap identity
|
|
202
|
+
|> Encode.object
|
|
203
|
+
)
|
|
204
|
+
, expect =
|
|
205
|
+
BackendTask.Http.expectJson
|
|
206
|
+
(Decode.map
|
|
207
|
+
(\s -> Spinner s (Options options_))
|
|
208
|
+
Decode.string
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
--{-| -}
|
|
215
|
+
--withImmediateStart : Options error value -> Options error value
|
|
216
|
+
--withImmediateStart (Options options_) =
|
|
217
|
+
-- Options { options_ | immediateStart = True }
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
{-| -}
|
|
221
|
+
runTaskWithOptions : Options error value -> BackendTask error value -> BackendTask error value
|
|
222
|
+
runTaskWithOptions (Options options_) backendTask =
|
|
223
|
+
Options options_
|
|
224
|
+
--|> withImmediateStart
|
|
225
|
+
|> showStep
|
|
226
|
+
|> BackendTask.andThen
|
|
227
|
+
(\(Spinner spinnerId _) ->
|
|
228
|
+
backendTask
|
|
229
|
+
|> BackendTask.onError
|
|
230
|
+
(\error ->
|
|
231
|
+
let
|
|
232
|
+
( completionIcon, completionText ) =
|
|
233
|
+
options_.onCompletion (Err error)
|
|
234
|
+
in
|
|
235
|
+
BackendTask.Internal.Request.request
|
|
236
|
+
{ name = "stop-spinner"
|
|
237
|
+
, body =
|
|
238
|
+
BackendTask.Http.jsonBody
|
|
239
|
+
(Encode.object
|
|
240
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
241
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
242
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
243
|
+
]
|
|
244
|
+
)
|
|
245
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
|
246
|
+
}
|
|
247
|
+
|> BackendTask.andThen (\() -> BackendTask.fail error)
|
|
248
|
+
)
|
|
249
|
+
|> BackendTask.andThen
|
|
250
|
+
(\value ->
|
|
251
|
+
let
|
|
252
|
+
( completionIcon, completionText ) =
|
|
253
|
+
options_.onCompletion (Ok value)
|
|
254
|
+
in
|
|
255
|
+
BackendTask.Internal.Request.request
|
|
256
|
+
{ name = "stop-spinner"
|
|
257
|
+
, body =
|
|
258
|
+
BackendTask.Http.jsonBody
|
|
259
|
+
(Encode.object
|
|
260
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
261
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
262
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
263
|
+
]
|
|
264
|
+
)
|
|
265
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed value)
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
{-| Run a `BackendTask` with a spinner. The spinner will show a success icon if the task succeeds, and a failure icon if the task fails.
|
|
272
|
+
|
|
273
|
+
It's often easier to use [`steps`](#steps) when possible.
|
|
274
|
+
|
|
275
|
+
module SequentialSteps exposing (run)
|
|
276
|
+
|
|
277
|
+
import Pages.Script as Script exposing (Script, doThen, sleep)
|
|
278
|
+
import Pages.Script.Spinner as Spinner
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
run : Script
|
|
282
|
+
run =
|
|
283
|
+
Script.withoutCliOptions
|
|
284
|
+
(sleep 3000
|
|
285
|
+
|> Spinner.runTask "Step 1..."
|
|
286
|
+
|> doThen
|
|
287
|
+
(sleep 3000
|
|
288
|
+
|> Spinner.runTask "Step 2..."
|
|
289
|
+
|> doThen
|
|
290
|
+
(sleep 3000
|
|
291
|
+
|> Spinner.runTask "Step 3..."
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
-}
|
|
297
|
+
runTask : String -> BackendTask error value -> BackendTask error value
|
|
298
|
+
runTask text backendTask =
|
|
299
|
+
spinner text
|
|
300
|
+
(\result ->
|
|
301
|
+
case result of
|
|
302
|
+
Ok _ ->
|
|
303
|
+
( Succeed, Nothing )
|
|
304
|
+
|
|
305
|
+
Err _ ->
|
|
306
|
+
( Fail, Nothing )
|
|
307
|
+
)
|
|
308
|
+
backendTask
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
{-| After calling `showStep` to get a reference to a `Spinner`, use `runSpinnerWithTask` to run a `BackendTask` and show a failure or success
|
|
312
|
+
completion status once it is done.
|
|
313
|
+
-}
|
|
314
|
+
runSpinnerWithTask : Spinner error value -> BackendTask error value -> BackendTask error value
|
|
315
|
+
runSpinnerWithTask (Spinner spinnerId (Options options_)) backendTask =
|
|
316
|
+
BackendTask.Internal.Request.request
|
|
317
|
+
{ name = "start-spinner"
|
|
318
|
+
, body =
|
|
319
|
+
BackendTask.Http.jsonBody
|
|
320
|
+
(Encode.object
|
|
321
|
+
[ ( "text", Encode.string options_.text )
|
|
322
|
+
, ( "spinnerId", Encode.string spinnerId )
|
|
323
|
+
, ( "immediateStart", Encode.bool options_.immediateStart )
|
|
324
|
+
, ( "spinner", Encode.string "line" )
|
|
325
|
+
]
|
|
326
|
+
)
|
|
327
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
|
328
|
+
}
|
|
329
|
+
|> BackendTask.andThen (\() -> backendTask)
|
|
330
|
+
|> BackendTask.andThen
|
|
331
|
+
(\value ->
|
|
332
|
+
let
|
|
333
|
+
( completionIcon, completionText ) =
|
|
334
|
+
options_.onCompletion (Ok value)
|
|
335
|
+
in
|
|
336
|
+
BackendTask.Internal.Request.request
|
|
337
|
+
{ name = "stop-spinner"
|
|
338
|
+
, body =
|
|
339
|
+
BackendTask.Http.jsonBody
|
|
340
|
+
(Encode.object
|
|
341
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
342
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
343
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
344
|
+
]
|
|
345
|
+
)
|
|
346
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed value)
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
|> BackendTask.onError
|
|
350
|
+
(\error ->
|
|
351
|
+
let
|
|
352
|
+
( completionIcon, completionText ) =
|
|
353
|
+
options_.onCompletion (Err error)
|
|
354
|
+
in
|
|
355
|
+
BackendTask.Internal.Request.request
|
|
356
|
+
{ name = "stop-spinner"
|
|
357
|
+
, body =
|
|
358
|
+
BackendTask.Http.jsonBody
|
|
359
|
+
(Encode.object
|
|
360
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
361
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
362
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
363
|
+
]
|
|
364
|
+
)
|
|
365
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
|
366
|
+
}
|
|
367
|
+
|> BackendTask.andThen (\() -> BackendTask.fail error)
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
{-| -}
|
|
372
|
+
spinner : String -> (Result error value -> ( CompletionIcon, Maybe String )) -> BackendTask error value -> BackendTask error value
|
|
373
|
+
spinner text onCompletion task =
|
|
374
|
+
BackendTask.Internal.Request.request
|
|
375
|
+
{ name = "start-spinner"
|
|
376
|
+
, body =
|
|
377
|
+
BackendTask.Http.jsonBody
|
|
378
|
+
(Encode.object
|
|
379
|
+
[ ( "text", Encode.string text )
|
|
380
|
+
, ( "immediateStart", Encode.bool True )
|
|
381
|
+
, ( "spinner", Encode.string "line" )
|
|
382
|
+
|
|
383
|
+
-- TODO more ora options here
|
|
384
|
+
]
|
|
385
|
+
)
|
|
386
|
+
, expect =
|
|
387
|
+
BackendTask.Http.expectJson Decode.string
|
|
388
|
+
}
|
|
389
|
+
|> BackendTask.andThen
|
|
390
|
+
(\spinnerId ->
|
|
391
|
+
task
|
|
392
|
+
|> BackendTask.onError
|
|
393
|
+
(\error ->
|
|
394
|
+
let
|
|
395
|
+
( completionIcon, completionText ) =
|
|
396
|
+
onCompletion (Err error)
|
|
397
|
+
in
|
|
398
|
+
BackendTask.Internal.Request.request
|
|
399
|
+
{ name = "stop-spinner"
|
|
400
|
+
, body =
|
|
401
|
+
BackendTask.Http.jsonBody
|
|
402
|
+
(Encode.object
|
|
403
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
404
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
405
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
406
|
+
]
|
|
407
|
+
)
|
|
408
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
|
409
|
+
}
|
|
410
|
+
|> BackendTask.andThen (\() -> BackendTask.fail error)
|
|
411
|
+
)
|
|
412
|
+
|> BackendTask.andThen
|
|
413
|
+
(\value ->
|
|
414
|
+
let
|
|
415
|
+
( completionIcon, completionText ) =
|
|
416
|
+
onCompletion (Ok value)
|
|
417
|
+
in
|
|
418
|
+
BackendTask.Internal.Request.request
|
|
419
|
+
{ name = "stop-spinner"
|
|
420
|
+
, body =
|
|
421
|
+
BackendTask.Http.jsonBody
|
|
422
|
+
(Encode.object
|
|
423
|
+
[ ( "spinnerId", Encode.string spinnerId )
|
|
424
|
+
, ( "completionFn", encodeCompletionIcon completionIcon |> Encode.string )
|
|
425
|
+
, ( "completionText", completionText |> Maybe.map Encode.string |> Maybe.withDefault Encode.null )
|
|
426
|
+
]
|
|
427
|
+
)
|
|
428
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed value)
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
encodeCompletionIcon : CompletionIcon -> String
|
|
435
|
+
encodeCompletionIcon completionIcon =
|
|
436
|
+
case completionIcon of
|
|
437
|
+
Succeed ->
|
|
438
|
+
"succeed"
|
|
439
|
+
|
|
440
|
+
Fail ->
|
|
441
|
+
"fail"
|
|
442
|
+
|
|
443
|
+
Warn ->
|
|
444
|
+
"warn"
|
|
445
|
+
|
|
446
|
+
Info ->
|
|
447
|
+
"info"
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
{-| The definition of a series of `BackendTask`s to run, with a spinner for each step.
|
|
451
|
+
-}
|
|
452
|
+
type Steps error value
|
|
453
|
+
= Steps (BackendTask error value)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
{-| Initialize an empty series of `Steps`.
|
|
457
|
+
-}
|
|
458
|
+
steps : Steps FatalError ()
|
|
459
|
+
steps =
|
|
460
|
+
Steps (BackendTask.succeed ())
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
{-| Add a `Step`. See [`withStepWithOptions`](#withStepWithOptions) to configure the step's spinner.
|
|
464
|
+
-}
|
|
465
|
+
withStep : String -> (oldValue -> BackendTask FatalError newValue) -> Steps FatalError oldValue -> Steps FatalError newValue
|
|
466
|
+
withStep text backendTask steps_ =
|
|
467
|
+
case steps_ of
|
|
468
|
+
Steps previousSteps ->
|
|
469
|
+
Steps
|
|
470
|
+
(BackendTask.map2
|
|
471
|
+
(\pipelineValue newSpinner ->
|
|
472
|
+
runSpinnerWithTask
|
|
473
|
+
newSpinner
|
|
474
|
+
(backendTask pipelineValue)
|
|
475
|
+
)
|
|
476
|
+
previousSteps
|
|
477
|
+
(options text |> showStep)
|
|
478
|
+
|> BackendTask.andThen identity
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
{-| Add a step with custom [`Options`](#Options).
|
|
483
|
+
-}
|
|
484
|
+
withStepWithOptions : Options FatalError newValue -> (oldValue -> BackendTask FatalError newValue) -> Steps FatalError oldValue -> Steps FatalError newValue
|
|
485
|
+
withStepWithOptions options_ backendTask steps_ =
|
|
486
|
+
case steps_ of
|
|
487
|
+
Steps previousSteps ->
|
|
488
|
+
Steps
|
|
489
|
+
(BackendTask.map2
|
|
490
|
+
(\pipelineValue newSpinner ->
|
|
491
|
+
runSpinnerWithTask
|
|
492
|
+
newSpinner
|
|
493
|
+
(backendTask pipelineValue)
|
|
494
|
+
)
|
|
495
|
+
previousSteps
|
|
496
|
+
(showStep options_)
|
|
497
|
+
|> BackendTask.andThen identity
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
{-| Perform the `Steps` in sequence.
|
|
502
|
+
-}
|
|
503
|
+
runSteps : Steps FatalError value -> BackendTask FatalError value
|
|
504
|
+
runSteps (Steps steps_) =
|
|
505
|
+
steps_
|