Skip to content

Commit 018d33f

Browse files
committed
Add sound settings tab
1 parent 15bdb15 commit 018d33f

File tree

9 files changed

+131
-11
lines changed

9 files changed

+131
-11
lines changed

public/images/commune.jpg

195 KB
Loading

public/images/img.png

18.5 MB
Loading

public/images/weird.jpeg

1.99 MB
Loading

public/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
.writeText(command.value)
4545
.finally(() => app.ports.events.send({name: 'Copied', value: ""}))
4646
break;
47+
case 'ChangeVolume':
48+
// window.localStorage.setItem("preferences", JSON.stringify({volume: parseInt(command.value)}));
49+
alarm.volume = parseInt(command.value) / 100.0;
50+
break;
4751
}
4852
});
4953
alarm.addEventListener("ended", () => {

src/elm/Js/Commands.elm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Command
1212
| SetAlarm Sound.Library.Sound
1313
| StopAlarm
1414
| CopyInPasteBin String
15+
| ChangeVolume Int
1516

1617

1718
type alias OutCommand =
@@ -35,3 +36,6 @@ send command =
3536

3637
StopAlarm ->
3738
OutCommand "StopAlarm" Json.Encode.null
39+
40+
ChangeVolume volume ->
41+
OutCommand "ChangeVolume" <| Json.Encode.string <| String.fromInt volume

src/elm/Lib/Icons/Ion.elm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import Lib.Icons.Rgba exposing (RGBA)
99
import Svg exposing (Svg)
1010

1111

12+
volumeLow : Svg msg
13+
volumeLow =
14+
display Ionicon.volumeLow
15+
16+
volumeHigh : Svg msg
17+
volumeHigh =
18+
display Ionicon.volumeHigh
19+
1220
github : Svg msg
1321
github =
1422
display Ionicon.Social.github

src/elm/Main.elm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Random
2525
import Shared
2626
import SharedEvents
2727
import Sound.Library
28+
import Sound.Settings
2829
import Svg exposing (Svg, svg)
2930
import Svg.Attributes as Svg
3031
import Task
@@ -78,6 +79,7 @@ type alias Model =
7879
, shared : Shared.State
7980
, mobbersSettings : Mobbers.Settings.Model
8081
, clockSettings : Clock.Settings.Model
82+
, soundSettings : Sound.Settings.Model
8183
, alarm : AlarmState
8284
, now : Time.Posix
8385
, toasts : Toasts
@@ -92,6 +94,7 @@ init _ url key =
9294
, shared = Shared.init
9395
, mobbersSettings = Mobbers.Settings.init
9496
, clockSettings = Clock.Settings.init
97+
, soundSettings = Sound.Settings.init 50
9598
, alarm = Standby
9699
, now = Time.millisToPosix 0
97100
, toasts = []
@@ -121,6 +124,7 @@ type Msg
121124
| GotClockSettingsMsg Clock.Settings.Msg
122125
| GotShareTabMsg Mob.Tabs.Share.Msg
123126
| GotMobbersSettingsMsg Mobbers.Settings.Msg
127+
| GotSoundSettingsMsg Sound.Settings.Msg
124128
| GotToastMsg Lib.Toaster.Msg
125129
| SwitchTab Tab
126130
| Batch (List Msg)
@@ -180,7 +184,7 @@ update msg model =
180184
)
181185

182186
Start ->
183-
( model, Random.generate StartWithAlarm <| Sound.Library.pick Sound.Library.ClassicWeird )
187+
( model, Random.generate StartWithAlarm <| Sound.Library.pick model.soundSettings.profile )
184188

185189
StartWithAlarm sound ->
186190
( model
@@ -243,6 +247,13 @@ update msg model =
243247
(\a -> { model | clockSettings = a })
244248
(Cmd.map GotClockSettingsMsg)
245249

250+
GotSoundSettingsMsg subMsg->
251+
Sound.Settings.update subMsg model.soundSettings
252+
|> Tuple.mapBoth
253+
(\a -> { model | soundSettings = a })
254+
(Cmd.map GotSoundSettingsMsg)
255+
256+
246257

247258

248259
-- SUBSCRIPTIONS
@@ -340,7 +351,8 @@ view model =
340351
|> Html.map GotMobbersSettingsMsg
341352

342353
Sound ->
343-
div [] []
354+
Sound.Settings.view model.soundSettings
355+
|> Html.map GotSoundSettingsMsg
344356

345357
Share ->
346358
Mob.Tabs.Share.view "Awesome" model.url

src/elm/Sound/Settings.elm

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module Sound.Settings exposing (..)
2+
3+
import Html exposing (Html, button, div, i, img, input, label, p, text)
4+
import Html.Attributes exposing (alt, class, classList, for, id, src, step, type_, value)
5+
import Html.Events exposing (onClick, onInput)
6+
import Js.Commands
7+
import Json.Encode
8+
import Lib.Icons.Ion
9+
import Sound.Library as SoundLibrary
10+
11+
type alias CommandPort = (Json.Encode.Value -> Cmd Msg)
12+
type alias StorePort = (Json.Encode.Value -> Cmd Msg)
13+
14+
type alias Model =
15+
{ profile : SoundLibrary.Profile
16+
, volume : Int
17+
}
18+
19+
20+
init : Int -> Model
21+
init volume =
22+
{ profile = SoundLibrary.ClassicWeird
23+
, volume = volume
24+
}
25+
26+
27+
type Msg
28+
= VolumeChanged String
29+
| SelectedSoundProfile SoundLibrary.Profile
30+
31+
32+
update : Msg -> Model -> ( Model, Cmd Msg )
33+
update msg model =
34+
case msg of
35+
VolumeChanged rawVolume ->
36+
let
37+
volume = String.toInt rawVolume|> Maybe.withDefault model.volume
38+
in
39+
( { model | volume = volume }
40+
, Js.Commands.send <| Js.Commands.ChangeVolume volume
41+
)
42+
43+
SelectedSoundProfile profile ->
44+
( { model | profile = profile }
45+
, Cmd.none
46+
)
47+
48+
49+
view : Model -> Html Msg
50+
view model =
51+
div [ id "sound", class "tab" ]
52+
[ div
53+
[ id "volume-field", class "form-field" ]
54+
[ label [ for "volume" ] [ text "Volume" ]
55+
, Lib.Icons.Ion.volumeLow
56+
, input
57+
[ id "volume"
58+
, type_ "range"
59+
, onInput VolumeChanged
60+
, step "10"
61+
, value <| String.fromInt model.volume
62+
]
63+
[]
64+
, Lib.Icons.Ion.volumeHigh
65+
]
66+
, div
67+
[ id "sounds-field", class "form-field" ]
68+
[ label [] [ text "Profiles" ]
69+
, div
70+
[ id "sound-cards" ]
71+
[ button
72+
[ classList [ ( "active", model.profile == SoundLibrary.ClassicWeird ) ]
73+
, onClick <| SelectedSoundProfile SoundLibrary.ClassicWeird
74+
]
75+
[ img [ src "/images/weird.jpeg", alt "Man wearing a watermelon as a hat" ] []
76+
, p [] [ text "Classic Weird" ]
77+
]
78+
, button
79+
[ classList [ ( "active", model.profile == SoundLibrary.Riot ) ]
80+
, onClick <| SelectedSoundProfile SoundLibrary.Riot
81+
]
82+
[ img [ src "/images/commune.jpg", alt "Comic book drawing of the paris commune revolution" ] []
83+
, p [] [ text "Revolution" ]
84+
]
85+
]
86+
]
87+
]

src/sass/tabs/_timer.scss

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,31 @@ input[type="range"] {
3232
#sound-cards {
3333
display: flex;
3434
align-items: start;
35+
padding: $margin-space 0;
3536

3637
button {
3738
flex: 1 0;
3839
width: 130px;
3940
background: none;
4041
text-align: center;
41-
padding: 20px;
42+
padding: 0;
4243
color: black;
4344
vertical-align: top;
45+
display: block;
46+
margin-left: $margin-space;
4447

45-
i {
46-
font-size: 2em;
47-
padding: 30px;
48-
background: $dark-button-color;
49-
color: white;
48+
&:first-child {
49+
margin-left: 0;
5050
}
5151

52-
&.active {
53-
i {
54-
background: $light-button-color;
52+
img {
53+
width: 100%;
54+
opacity: .6;
55+
}
56+
57+
&.active, &:hover {
58+
img {
59+
opacity: 1;
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)