Skip to content

Commit 0ce3282

Browse files
committed
shuffle testimonials on startup
1 parent 97e2544 commit 0ce3282

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

elm.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"elm/html": "1.0.0",
1313
"elm/http": "2.0.0",
1414
"elm/json": "1.1.3",
15-
"elm/time": "1.0.0"
15+
"elm/random": "1.0.0",
16+
"elm/time": "1.0.0",
17+
"elm-community/random-extra": "3.2.0"
1618
},
1719
"indirect": {
1820
"elm/bytes": "1.0.8",

src/Testimonials.elm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Html.Events as Events
66
import HtmlHelpers exposing (hideOnBreakpoint)
77
import Http
88
import Json.Decode
9+
import Random
10+
import Random.List exposing (shuffle)
911
import Set
1012
import Task
1113
import Time
@@ -71,7 +73,7 @@ type Msg
7173
= Right
7274
| Left
7375
| GotTestimonials (Result Http.Error (List Testimonial))
74-
| SetRandomizedIndex Time.Posix
76+
| GotShuffledTetsemonials (List Testimonial)
7577

7678

7779
update : Msg -> Model -> ( Model, Cmd Msg )
@@ -83,11 +85,11 @@ update msg model =
8385
( Success testimonials index, Left ) ->
8486
( Success testimonials (changeOrRollover testimonials (index - 1)), Cmd.none )
8587

86-
( Success testimonials _, SetRandomizedIndex time ) ->
87-
( Success testimonials (changeOrRollover testimonials (time |> Time.posixToMillis)), Cmd.none )
88+
( Loading, GotShuffledTetsemonials testimonials ) ->
89+
( Success testimonials 0, Cmd.none )
8890

8991
( _, GotTestimonials (Ok testimonials) ) ->
90-
( Success testimonials 0, Cmd.none )
92+
( Loading, Random.generate GotShuffledTetsemonials (shuffle testimonials) )
9193

9294
( _, GotTestimonials (Err _) ) ->
9395
( Failure, Cmd.none )

0 commit comments

Comments
 (0)