Links instead of button

This commit is contained in:
Thomas Forgione 2020-10-08 16:18:22 +02:00
parent f22e1c576b
commit 1ba2bbd8ce
4 changed files with 49 additions and 23 deletions

View File

@ -1,5 +1,6 @@
module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, subscriptions, update) module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, subscriptions, update)
import Browser
import Browser.Events as Events import Browser.Events as Events
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Dict exposing (Dict) import Dict exposing (Dict)
@ -38,6 +39,7 @@ type Msg
| PlaylistClicked Twitch.Playlist | PlaylistClicked Twitch.Playlist
| VideoClicked Twitch.Playlist Twitch.Video | VideoClicked Twitch.Playlist Twitch.Video
| UrlReceived Url.Url | UrlReceived Url.Url
| UrlRequested Browser.UrlRequest
| SizeReceived Int Int | SizeReceived Int Int
@ -166,6 +168,14 @@ update msg model =
in in
( Loaded { m | page = page }, Cmd.batch [ cmd, extraCmd ] ) ( Loaded { m | page = page }, Cmd.batch [ cmd, extraCmd ] )
( UrlRequested u, Loaded m ) ->
case u of
Browser.Internal url ->
( model, Nav.pushUrl m.key (Url.toString url) )
Browser.External s ->
( model, Nav.load s )
_ -> _ ->
( model, Cmd.none ) ( model, Cmd.none )

View File

@ -13,5 +13,5 @@ main =
, view = Views.view , view = Views.view
, subscriptions = Core.subscriptions , subscriptions = Core.subscriptions
, onUrlChange = Core.UrlReceived , onUrlChange = Core.UrlReceived
, onUrlRequest = \_ -> Core.Noop , onUrlRequest = Core.UrlRequested
} }

12
src/Ui.elm Normal file
View File

@ -0,0 +1,12 @@
module Ui exposing (link)
import Element exposing (Element)
import Element.Input as Input
link : List (Element.Attribute msg) -> { label : Element msg, url : String } -> Element msg
link attr data =
Input.button attr
{ label = Element.link [ Element.width Element.fill, Element.height Element.fill ] data
, onPress = Nothing
}

View File

@ -16,6 +16,7 @@ import Json.Encode as Encode
import Time import Time
import TimeUtils import TimeUtils
import Twitch import Twitch
import Ui
view : Core.FullModel -> Browser.Document Core.Msg view : Core.FullModel -> Browser.Document Core.Msg
@ -88,14 +89,13 @@ topBar =
homeButton : Element Core.Msg homeButton : Element Core.Msg
homeButton = homeButton =
Input.button Ui.link
[ Element.padding Consts.homePadding [ Element.padding Consts.homePadding
, Element.height Element.fill , Element.height Element.fill
, Element.mouseOver [ Background.color Colors.primaryOver ]
, Font.bold , Font.bold
] ]
{ label = Element.text Consts.name { label = Element.text Consts.name
, onPress = Just Core.HomeClicked , url = "/"
} }
@ -175,9 +175,13 @@ playlistView playlist =
] ]
button = button =
Input.button [ Element.width Element.fill, Element.alignTop ] Input.button [ Element.width Element.fill ]
{ label = display { label =
, onPress = Just (Core.PlaylistClicked playlist) Ui.link [ Element.width Element.fill, Element.alignTop ]
{ label = display
, url = "/#" ++ playlist.url
}
, onPress = Nothing
} }
in in
button button
@ -253,9 +257,9 @@ videoMiniatureView zone playlist video =
] ]
button = button =
Input.button [ Element.width Element.fill, Element.alignTop ] Ui.link [ Element.width Element.fill, Element.alignTop ]
{ label = display { label = display
, onPress = Just (Core.VideoClicked playlist video) , url = "/#" ++ playlist.url ++ video.url
} }
in in
button button
@ -264,19 +268,6 @@ videoMiniatureView zone playlist video =
videoInList : Time.Zone -> Twitch.Playlist -> Twitch.Video -> Twitch.Video -> Element Core.Msg videoInList : Time.Zone -> Twitch.Playlist -> Twitch.Video -> Twitch.Video -> Element Core.Msg
videoInList zone playlist activeVideo video = videoInList zone playlist activeVideo video =
let let
( msg, attr ) =
if video == activeVideo then
( Nothing
, [ Element.width Element.fill
, Background.color Colors.selected
, Border.color Colors.primary
, Border.width 2
]
)
else
( Just (Core.VideoClicked playlist video), [ Element.width Element.fill ] )
label = label =
Element.row [ Element.width Element.fill, Element.spacing 10 ] Element.row [ Element.width Element.fill, Element.spacing 10 ]
[ Element.el [ Element.width (Element.fillPortion 2) ] [ Element.el [ Element.width (Element.fillPortion 2) ]
@ -285,7 +276,20 @@ videoInList zone playlist activeVideo video =
(videoDescription zone video) (videoDescription zone video)
] ]
in in
Input.button attr { label = label, onPress = msg } if video == activeVideo then
Element.el
[ Element.width Element.fill
, Background.color Colors.selected
, Border.color Colors.primary
, Border.width 2
]
label
else
Ui.link [ Element.width Element.fill ]
{ label = label
, url = "/#" ++ playlist.url ++ video.url
}
videoView : Element.Device -> Time.Zone -> Twitch.Playlist -> Twitch.Video -> Element Core.Msg videoView : Element.Device -> Time.Zone -> Twitch.Playlist -> Twitch.Video -> Element Core.Msg