11module Sound.Settings exposing (..)
22
3- import Html exposing (Html , button , div , i , img , input , label , p , text )
3+ import Html exposing (Html , button , div , img , input , label , p , text )
44import Html.Attributes exposing (alt , class , classList , for , id , src , step , type_ , value )
55import Html.Events exposing (onClick , onInput )
66import Js.Commands
77import Json.Encode
88import Lib.Icons.Ion
9+ import SharedEvents
910import Sound.Library as SoundLibrary
1011
11- type alias CommandPort = ( Json . Encode . Value -> Cmd Msg )
12- type alias StorePort = ( Json . Encode . Value -> Cmd Msg )
12+
13+ type alias CommandPort =
14+ Json . Encode . Value -> Cmd Msg
15+
16+
17+ type alias StorePort =
18+ Json . Encode . Value -> Cmd Msg
19+
1320
1421type alias Model =
15- { profile : SoundLibrary . Profile
16- , volume : Int
17- }
22+ { volume : Int }
1823
1924
2025init : Int -> Model
2126init volume =
22- { profile = SoundLibrary . ClassicWeird
23- , volume = volume
24- }
27+ { volume = volume }
2528
2629
2730type Msg
2831 = VolumeChanged String
29- | SelectedSoundProfile SoundLibrary . Profile
32+ | ShareEvent SharedEvents . Event
3033
3134
3235update : Msg -> Model -> ( Model , Cmd Msg )
3336update msg model =
3437 case msg of
3538 VolumeChanged rawVolume ->
3639 let
37- volume = String . toInt rawVolume|> Maybe . withDefault model. volume
40+ volume =
41+ String . toInt rawVolume |> Maybe . withDefault model. volume
3842 in
3943 ( { model | volume = volume }
4044 , Js . Commands . send <| Js . Commands . ChangeVolume volume
4145 )
4246
43- SelectedSoundProfile profile ->
44- ( { model | profile = profile }
45- , Cmd . none
47+ ShareEvent event ->
48+ ( model
49+ , event
50+ |> SharedEvents . toJson
51+ |> SharedEvents . sendEvent
4652 )
4753
4854
49- view : Model -> Html Msg
50- view model =
55+ view : Model -> SoundLibrary . Profile -> Html Msg
56+ view model profile =
5157 div [ id " sound" , class " tab" ]
5258 [ div
5359 [ id " volume-field" , class " form-field" ]
@@ -69,15 +75,23 @@ view model =
6975 , div
7076 [ id " sound-cards" ]
7177 [ button
72- [ classList [ ( " active" , model. profile == SoundLibrary . ClassicWeird ) ]
73- , onClick <| SelectedSoundProfile SoundLibrary . ClassicWeird
78+ [ classList [ ( " active" , profile == SoundLibrary . ClassicWeird ) ]
79+ , onClick
80+ ( SoundLibrary . ClassicWeird
81+ |> SharedEvents . SelectedMusicProfile
82+ |> ShareEvent
83+ )
7484 ]
7585 [ img [ src " /images/weird.jpeg" , alt " Man wearing a watermelon as a hat" ] []
7686 , p [] [ text " Classic Weird" ]
7787 ]
7888 , button
79- [ classList [ ( " active" , model. profile == SoundLibrary . Riot ) ]
80- , onClick <| SelectedSoundProfile SoundLibrary . Riot
89+ [ classList [ ( " active" , profile == SoundLibrary . Riot ) ]
90+ , onClick
91+ ( SoundLibrary . Riot
92+ |> SharedEvents . SelectedMusicProfile
93+ |> ShareEvent
94+ )
8195 ]
8296 [ img [ src " /images/commune.jpg" , alt " Comic book drawing of the paris commune revolution" ] []
8397 , p [] [ text " Revolution" ]
0 commit comments