Make UI responsive

Switch to a vertical layout for phones
This commit is contained in:
Correl Roush 2020-05-16 18:52:45 -04:00
parent e789b43885
commit a49612b3ba
3 changed files with 48 additions and 16 deletions

View file

@ -28,7 +28,9 @@ var app = Elm.Main.init({
node: document.getElementById("elm-main"), node: document.getElementById("elm-main"),
flags: { flags: {
player: player_id, player: player_id,
room: room_id room: room_id,
width: window.innerWidth,
height: window.innerHeight
} }
}) })

View file

@ -1,6 +1,7 @@
module Main exposing (main) module Main exposing (main)
import Browser exposing (Document) import Browser exposing (Document)
import Browser.Events as Events
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Html import Html
import PlanningPokerEntry as Entry import PlanningPokerEntry as Entry
@ -13,6 +14,8 @@ import Url.Parser as Parser exposing ((</>), Parser, s, string)
type alias Flags = type alias Flags =
{ player : String { player : String
, room : String , room : String
, height : Int
, width : Int
} }
@ -21,6 +24,7 @@ type alias Model =
, key : Nav.Key , key : Nav.Key
, player : String , player : String
, room : String , room : String
, dimensions : { width : Int, height : Int }
} }
@ -40,15 +44,17 @@ type Msg
| ClickedLink Browser.UrlRequest | ClickedLink Browser.UrlRequest
| EntryMsg Entry.Msg | EntryMsg Entry.Msg
| RoomMsg Room.Msg | RoomMsg Room.Msg
| WindowResized Int Int
init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg ) init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
init { player, room } url key = init { player, room, width, height } url key =
updateUrl url updateUrl url
{ page = NotFound { page = NotFound
, key = key , key = key
, player = player , player = player
, room = room , room = room
, dimensions = { width = width, height = height }
} }
@ -67,6 +73,15 @@ update msg model =
( RoomMsg roomMsg, RoomPage roomModel ) -> ( RoomMsg roomMsg, RoomPage roomModel ) ->
toRoom model (Room.update model.key roomMsg roomModel) toRoom model (Room.update model.key roomMsg roomModel)
( WindowResized width height, _ ) ->
let
newDimensions =
{ width = width, height = height }
in
( { model | dimensions = newDimensions }
, Cmd.none
)
_ -> _ ->
( model, Cmd.none ) ( model, Cmd.none )
@ -136,7 +151,7 @@ view model =
mapDocument EntryMsg <| Entry.view entryModel mapDocument EntryMsg <| Entry.view entryModel
RoomPage roomModel -> RoomPage roomModel ->
mapDocument RoomMsg <| Room.view roomModel mapDocument RoomMsg <| Room.view model.dimensions roomModel
NotFound -> NotFound ->
NotFound.view NotFound.view
@ -158,4 +173,5 @@ subscriptions : Model -> Sub Msg
subscriptions _ = subscriptions _ =
Sub.batch Sub.batch
[ Sub.map RoomMsg Room.subscriptions [ Sub.map RoomMsg Room.subscriptions
, Events.onResize WindowResized
] ]

View file

@ -189,9 +189,13 @@ update key msg model =
) )
view : Model -> Document Msg view : { height : Int, width : Int } -> Model -> Document Msg
view model = view dimensions model =
let let
device =
classifyDevice dimensions
|> Debug.log "device"
playerName = playerName =
Dict.get model.player model.room.players Dict.get model.player model.room.players
|> Maybe.map .name |> Maybe.map .name
@ -203,7 +207,7 @@ view model =
{ title = model.room.name { title = model.room.name
, body = , body =
[ navBar { title = model.room.name, playerName = playerName } [ navBar { title = model.room.name, playerName = playerName }
, viewRoom model , viewRoom device model
] ]
} }
@ -217,24 +221,34 @@ view model =
} }
viewRoom : Model -> Element Msg viewRoom : Device -> Model -> Element Msg
viewRoom model = viewRoom device model =
let let
myVote = myVote =
Dict.get model.player model.room.players Dict.get model.player model.room.players
|> Maybe.andThen .vote |> Maybe.andThen .vote
in in
column [ width fill, spacing 20 ] case device.class of
[ row Phone ->
[ width fill ] column [ width fill, spacing 20 ]
[ el [ width (fillPortion 3), alignTop ] <|
viewCards myVote
, column [ width (fillPortion 1), alignTop, spacing 50 ] <|
[ viewPlayers (Dict.values model.room.players) model.showVotes [ viewPlayers (Dict.values model.room.players) model.showVotes
, el [ width (fillPortion 3), alignTop ] <|
viewCards myVote
, moderatorTools model , moderatorTools model
] ]
]
] _ ->
column [ width fill, spacing 20 ]
[ row
[ width fill ]
[ el [ width (fillPortion 3), alignTop ] <|
viewCards myVote
, column [ width (fillPortion 1), alignTop, spacing 50 ] <|
[ viewPlayers (Dict.values model.room.players) model.showVotes
, moderatorTools model
]
]
]
navBar : { title : String, playerName : String } -> Element Msg navBar : { title : String, playerName : String } -> Element Msg