Skip to content

Commit

Permalink
Move 'Article' to the page stack
Browse files Browse the repository at this point in the history
  • Loading branch information
cdevienne committed Apr 1, 2022
1 parent 43659d4 commit 1aaf988
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 92 deletions.
50 changes: 20 additions & 30 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Viewer exposing (Viewer)
type Model
= Redirect Session
| NotFound Session
| Article Article.Model
| Editor (Maybe Slug) Editor.Model
| Stack Session StackModel

Expand All @@ -54,23 +53,27 @@ type alias StackModel =


type alias StackCurrentModel =
Register.Model
Article.Model


type alias StackPreviousModel =
Spa.PageStack.Model
Never
Login.Model
Register.Model
(Spa.PageStack.Model
Never
Profile.Model
Login.Model
(Spa.PageStack.Model
Never
Settings.Model
Profile.Model
(Spa.PageStack.Model
Never
Home.Model
(Spa.PageStack.Model Never () ())
Settings.Model
(Spa.PageStack.Model
Never
Home.Model
(Spa.PageStack.Model Never () ())
)
)
)
)
Expand All @@ -81,20 +84,24 @@ type alias StackMsg =


type alias StackCurrentMsg =
Register.Msg
Article.Msg


type alias StackPreviousMsg =
Spa.PageStack.Msg
Route
Login.Msg
Register.Msg
(Spa.PageStack.Msg
Route
Profile.Msg
Login.Msg
(Spa.PageStack.Msg
Route
Settings.Msg
(Spa.PageStack.Msg Route Home.Msg (Spa.PageStack.Msg Route () ()))
Profile.Msg
(Spa.PageStack.Msg
Route
Settings.Msg
(Spa.PageStack.Msg Route Home.Msg (Spa.PageStack.Msg Route () ()))
)
)
)

Expand All @@ -111,6 +118,7 @@ stack =
|> Spa.PageStack.add ( View.map, View.map ) Route.matchProfile (Profile.page >> Ok)
|> Spa.PageStack.add ( View.map, View.map ) Route.matchLogin (Login.page >> Ok)
|> Spa.PageStack.add ( View.map, View.map ) Route.matchRegister (Register.page >> Ok)
|> Spa.PageStack.add ( View.map, View.map ) Route.matchArticle (Article.page >> Ok)



Expand Down Expand Up @@ -149,9 +157,6 @@ view model =
NotFound _ ->
Page.view viewer Page.Other NotFound.view

Article article ->
viewPage Page.Other GotArticleMsg (Article.view article)

Editor Nothing editor ->
viewPage Page.NewArticle GotEditorMsg (Editor.view editor)

Expand All @@ -173,7 +178,6 @@ view model =
type Msg
= ChangedUrl Url
| ClickedLink Browser.UrlRequest
| GotArticleMsg Article.Msg
| GotEditorMsg Editor.Msg
| GotSession Session
| StackMsg StackMsg
Expand All @@ -190,9 +194,6 @@ toSession page =
NotFound session ->
session

Article article ->
Article.toSession article

Editor _ editor ->
Editor.toSession editor

Expand Down Expand Up @@ -224,10 +225,6 @@ changeRouteTo maybeRoute model =
Editor.initEdit session slug
|> updateWith (Editor (Just slug)) GotEditorMsg model

Just (Route.Article slug) ->
Article.init session slug
|> updateWith Article GotArticleMsg model

Just route ->
let
( newStack, effect ) =
Expand Down Expand Up @@ -272,10 +269,6 @@ update msg model =
( ChangedUrl url, _ ) ->
changeRouteTo (Route.fromUrl url) model

( GotArticleMsg subMsg, Article article ) ->
Article.update subMsg article
|> updateWith Article GotArticleMsg model

( GotEditorMsg subMsg, Editor slug editor ) ->
Editor.update subMsg editor
|> updateWith (Editor slug) GotEditorMsg model
Expand Down Expand Up @@ -322,9 +315,6 @@ subscriptions model =
Redirect _ ->
Session.changes GotSession (Session.navKey (toSession model))

Article article ->
Sub.map GotArticleMsg (Article.subscriptions article)

Editor _ editor ->
Sub.map GotEditorMsg (Editor.subscriptions editor)

Expand Down
Loading

0 comments on commit 1aaf988

Please sign in to comment.