mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-11 06:31:38 +03:00
48 lines
1.2 KiB
Elm
48 lines
1.2 KiB
Elm
module Update exposing (Msg(..), subscriptions, update)
|
|
|
|
import Browser exposing (UrlRequest(..))
|
|
import Browser.Navigation
|
|
import Model exposing (..)
|
|
import NriModules as NriModules
|
|
import Routes
|
|
import Url exposing (Url)
|
|
|
|
|
|
type Msg
|
|
= UpdateModuleStates NriModules.Msg
|
|
| OnUrlRequest Browser.UrlRequest
|
|
| OnUrlChange Url
|
|
| NoOp
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
update action model =
|
|
case action of
|
|
UpdateModuleStates msg ->
|
|
let
|
|
( moduleStates, cmd ) =
|
|
NriModules.update msg model.moduleStates
|
|
in
|
|
( { model | moduleStates = moduleStates }
|
|
, Cmd.map UpdateModuleStates cmd
|
|
)
|
|
|
|
OnUrlRequest request ->
|
|
case request of
|
|
Internal loc ->
|
|
( model, Browser.Navigation.pushUrl model.navigationKey (Url.toString loc) )
|
|
|
|
External loc ->
|
|
( model, Browser.Navigation.load loc )
|
|
|
|
OnUrlChange route ->
|
|
( { model | route = Routes.fromLocation route }, Cmd.none )
|
|
|
|
NoOp ->
|
|
( model, Cmd.none )
|
|
|
|
|
|
subscriptions : Model -> Sub Msg
|
|
subscriptions model =
|
|
Sub.map UpdateModuleStates (NriModules.subscriptions model.moduleStates)
|