Open room on notification click.

This commit is contained in:
Danila Fedorin 2018-12-13 14:06:15 -08:00
parent 46352c429a
commit 2c7b72fba6
5 changed files with 14 additions and 6 deletions

View File

@ -59,6 +59,7 @@ update msg model = case msg of
ChangeLoginPassword p -> ({ model | loginPassword = p }, Cmd.none) ChangeLoginPassword p -> ({ model | loginPassword = p }, Cmd.none)
AttemptLogin -> (model, Scylla.Http.login model.apiUrl model.loginUsername model.loginPassword) -- TODO AttemptLogin -> (model, Scylla.Http.login model.apiUrl model.loginUsername model.loginPassword) -- TODO
TryUrl urlRequest -> updateTryUrl model urlRequest TryUrl urlRequest -> updateTryUrl model urlRequest
OpenRoom s -> (model, Nav.pushUrl model.key <| roomUrl s)
ChangeRoute r -> ({ model | route = r }, Cmd.none) ChangeRoute r -> ({ model | route = r }, Cmd.none)
ReceiveLoginResponse r -> updateLoginResponse model r ReceiveLoginResponse r -> updateLoginResponse model r
ReceiveFirstSyncResponse r -> updateSyncResponse model r False ReceiveFirstSyncResponse r -> updateSyncResponse model r False
@ -129,7 +130,7 @@ updateSyncResponse model r notify =
_ -> (model, syncCmd) _ -> (model, syncCmd)
subscriptions : Model -> Sub Msg subscriptions : Model -> Sub Msg
subscriptions m = Sub.none subscriptions m = onNotificationClickPort OpenRoom
onUrlRequest : Browser.UrlRequest -> Msg onUrlRequest : Browser.UrlRequest -> Msg
onUrlRequest = TryUrl onUrlRequest = TryUrl

View File

@ -5,6 +5,7 @@ import Scylla.Login exposing (LoginResponse, Username, Password)
import Scylla.UserData exposing (UserData) import Scylla.UserData exposing (UserData)
import Scylla.Route exposing (Route) import Scylla.Route exposing (Route)
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Url.Builder
import Dict exposing (Dict) import Dict exposing (Dict)
import Browser import Browser
import Http import Http
@ -30,6 +31,7 @@ type Msg =
| ChangeLoginPassword Password -- During login screen: the password | ChangeLoginPassword Password -- During login screen: the password
| AttemptLogin -- During login screen, login button presed | AttemptLogin -- During login screen, login button presed
| TryUrl Browser.UrlRequest -- User attempts to change URL | TryUrl Browser.UrlRequest -- User attempts to change URL
| OpenRoom String -- We try open a room
| ChangeRoute Route -- URL changes | ChangeRoute Route -- URL changes
| ChangeRoomText String String -- Change to a room's input text | ChangeRoomText String String -- Change to a room's input text
| SendRoomText String -- Sends a message typed into a given room's input | SendRoomText String -- Sends a message typed into a given room's input
@ -41,3 +43,9 @@ type Msg =
displayName : Model -> Username -> String displayName : Model -> Username -> String
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData
roomUrl : String -> String
roomUrl s = Url.Builder.absolute [ "room", s ] []
loginUrl : String
loginUrl = Url.Builder.absolute [ "login" ] []

View File

@ -8,4 +8,4 @@ type alias Notification =
} }
port sendNotificationPort : Notification -> Cmd msg port sendNotificationPort : Notification -> Cmd msg
port onNotificationClickPort : (Json.Decode.Value -> msg) -> Sub msg port onNotificationClickPort : (String -> msg) -> Sub msg

View File

@ -69,7 +69,7 @@ roomListElementView s jr =
let let
name = Maybe.withDefault "<No Name>" <| roomName jr name = Maybe.withDefault "<No Name>" <| roomName jr
in in
a [ href <| Url.Builder.absolute [ "room", s ] [] ] [ text name ] a [ href <| roomUrl s ] [ text name ]
loginView : Model -> Html Msg loginView : Model -> Html Msg
loginView m = div [ class "login-wrapper" ] loginView m = div [ class "login-wrapper" ]

View File

@ -9,9 +9,8 @@ function setupNotificationPorts(app) {
} }
var n = new Notification(data.name, options) var n = new Notification(data.name, options)
n.onclick = function() { n.onclick = function() {
app.ports.onNotificationClickPort.send({ app.ports.onNotificationClickPort.send(data.room);
"room" : data.room n.close();
});
} }
}) })
} }