Update part1 and part2
This commit is contained in:
@@ -31,7 +31,7 @@ type Page
|
||||
= Blank
|
||||
| NotFound
|
||||
| Errored PageLoadError
|
||||
| Home Home.Model
|
||||
| Home
|
||||
| Settings Settings.Model
|
||||
| Login Login.Model
|
||||
| Register Register.Model
|
||||
@@ -116,10 +116,9 @@ viewPage session isLoading page =
|
||||
|> frame Page.Other
|
||||
|> Html.map SettingsMsg
|
||||
|
||||
Home subModel ->
|
||||
Home.view session subModel
|
||||
Home ->
|
||||
Home.page
|
||||
|> frame Page.Home
|
||||
|> Html.map HomeMsg
|
||||
|
||||
Login subModel ->
|
||||
Login.view session subModel
|
||||
@@ -199,7 +198,7 @@ pageSubscriptions page =
|
||||
Settings _ ->
|
||||
Sub.none
|
||||
|
||||
Home _ ->
|
||||
Home ->
|
||||
Sub.none
|
||||
|
||||
Login _ ->
|
||||
@@ -224,11 +223,9 @@ pageSubscriptions page =
|
||||
|
||||
type Msg
|
||||
= SetRoute (Maybe Route)
|
||||
| HomeLoaded (Result PageLoadError Home.Model)
|
||||
| ArticleLoaded (Result PageLoadError Article.Model)
|
||||
| ProfileLoaded Username (Result PageLoadError Profile.Model)
|
||||
| EditArticleLoaded Slug (Result PageLoadError Editor.Model)
|
||||
| HomeMsg Home.Msg
|
||||
| SettingsMsg Settings.Msg
|
||||
| SetUser (Maybe User)
|
||||
| LoginMsg Login.Msg
|
||||
@@ -278,7 +275,7 @@ setRoute maybeRoute model =
|
||||
errored Page.Settings "You must be signed in to access your settings."
|
||||
|
||||
Just Route.Home ->
|
||||
transition HomeLoaded (Home.init model.session)
|
||||
( { model | pageState = Loaded Home }, Cmd.none )
|
||||
|
||||
Just Route.Root ->
|
||||
( model, Route.modifyUrl Route.Home )
|
||||
@@ -342,12 +339,6 @@ updatePage page msg model =
|
||||
( SetRoute route, _ ) ->
|
||||
setRoute route model
|
||||
|
||||
( HomeLoaded (Ok subModel), _ ) ->
|
||||
( { model | pageState = Loaded (Home subModel) }, Cmd.none )
|
||||
|
||||
( HomeLoaded (Err error), _ ) ->
|
||||
( { model | pageState = Loaded (Errored error) }, Cmd.none )
|
||||
|
||||
( ProfileLoaded username (Ok subModel), _ ) ->
|
||||
( { model | pageState = Loaded (Profile username subModel) }, Cmd.none )
|
||||
|
||||
@@ -430,9 +421,6 @@ updatePage page msg model =
|
||||
, Cmd.map RegisterMsg cmd
|
||||
)
|
||||
|
||||
( HomeMsg subMsg, Home subModel ) ->
|
||||
toPage Home HomeMsg (Home.update session) subMsg subModel
|
||||
|
||||
( ProfileMsg subMsg, Profile username subModel ) ->
|
||||
toPage (Profile username) ProfileMsg (Profile.update model.session) subMsg subModel
|
||||
|
||||
|
||||
@@ -1,130 +1,40 @@
|
||||
module Page.Home exposing (Model, Msg, init, update, view)
|
||||
module Page.Home exposing (page)
|
||||
|
||||
{-| The homepage. You can get here via either the / or /#/ routes.
|
||||
-}
|
||||
|
||||
import Data.Article as Article exposing (Tag)
|
||||
import Data.Session exposing (Session)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (attribute, class, classList, href, id, placeholder)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import Page.Errored exposing (PageLoadError, pageLoadError)
|
||||
import Request.Article
|
||||
import SelectList exposing (SelectList)
|
||||
import Task exposing (Task)
|
||||
import Views.Article.Feed as Feed exposing (FeedSource, globalFeed, tagFeed, yourFeed)
|
||||
import Views.Page as Page
|
||||
|
||||
|
||||
-- MODEL --
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ tags : List Tag
|
||||
, feed : Feed.Model
|
||||
}
|
||||
|
||||
|
||||
init : Session -> Task PageLoadError Model
|
||||
init session =
|
||||
let
|
||||
feedSources =
|
||||
if session.user == Nothing then
|
||||
SelectList.singleton globalFeed
|
||||
else
|
||||
SelectList.fromLists [] yourFeed [ globalFeed ]
|
||||
|
||||
loadTags =
|
||||
Request.Article.tags
|
||||
|> Http.toTask
|
||||
|
||||
loadSources =
|
||||
Feed.init session feedSources
|
||||
|
||||
handleLoadError _ =
|
||||
pageLoadError Page.Home "Homepage is currently unavailable."
|
||||
in
|
||||
Task.map2 Model loadTags loadSources
|
||||
|> Task.mapError handleLoadError
|
||||
|
||||
|
||||
|
||||
-- VIEW --
|
||||
|
||||
|
||||
view : Session -> Model -> Html Msg
|
||||
view session model =
|
||||
page =
|
||||
div [ class "home-page" ]
|
||||
[ viewBanner
|
||||
[ p [] [ text "TODO: Replace this <p> with the banner" ]
|
||||
, div [ class "container page" ]
|
||||
[ div [ class "row" ]
|
||||
[ div [ class "col-md-9" ] (viewFeed model.feed)
|
||||
, div [ class "col-md-3" ]
|
||||
[ div [ class "sidebar" ]
|
||||
[ p [] [ text "Popular Tags" ]
|
||||
, viewTags model.tags
|
||||
]
|
||||
]
|
||||
[ div [ class "col-md-9" ] [ viewFeed ]
|
||||
, div [ class "col-md-3" ] []
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
viewBanner : Html msg
|
||||
viewBanner =
|
||||
{- TODO Add a logo and tagline to this banner, so its structure becomes:
|
||||
|
||||
<div class="banner">
|
||||
<div class="container">
|
||||
<h1 class="logo-font">conduit</h1>
|
||||
<p>A place to share your knowledge.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
HINT 1: the <div class="row"> above is an element with 2 child nodes.
|
||||
|
||||
HINT 2: the <div class="feed-toggle"> below is an element with text.
|
||||
-}
|
||||
div [ class "banner" ]
|
||||
[ div [ class "container" ]
|
||||
[ h1 [ class "logo-font" ] [ text "conduit" ]
|
||||
, p [] [ text "A place to share your knowledge." ]
|
||||
]
|
||||
[]
|
||||
]
|
||||
|
||||
|
||||
viewFeed : Feed.Model -> List (Html Msg)
|
||||
viewFeed feed =
|
||||
div [ class "feed-toggle" ]
|
||||
[ Feed.viewFeedSources feed |> Html.map FeedMsg ]
|
||||
:: (Feed.viewArticles feed |> List.map (Html.map FeedMsg))
|
||||
|
||||
|
||||
viewTags : List Tag -> Html Msg
|
||||
viewTags tags =
|
||||
div [ class "tag-list" ] (List.map viewTag tags)
|
||||
|
||||
|
||||
viewTag : Tag -> Html Msg
|
||||
viewTag tagName =
|
||||
a
|
||||
[ class "tag-pill tag-default"
|
||||
, href "javascript:void(0)"
|
||||
, onClick (SelectTag tagName)
|
||||
]
|
||||
[ text (Article.tagToString tagName) ]
|
||||
|
||||
|
||||
|
||||
-- UPDATE --
|
||||
|
||||
|
||||
type Msg
|
||||
= FeedMsg Feed.Msg
|
||||
| SelectTag Tag
|
||||
|
||||
|
||||
update : Session -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update session msg model =
|
||||
case msg of
|
||||
FeedMsg subMsg ->
|
||||
let
|
||||
( newFeed, subCmd ) =
|
||||
Feed.update session subMsg model.feed
|
||||
in
|
||||
( { model | feed = newFeed }, Cmd.map FeedMsg subCmd )
|
||||
|
||||
SelectTag tagName ->
|
||||
let
|
||||
subCmd =
|
||||
Feed.selectTag (Maybe.map .token session.user) tagName
|
||||
in
|
||||
( model, Cmd.map FeedMsg subCmd )
|
||||
viewFeed =
|
||||
div [ class "feed-toggle" ] [ text "(We’ll display some articles here later.)" ]
|
||||
|
||||
@@ -7,22 +7,12 @@ import Data.Article exposing (Article)
|
||||
import Data.UserPhoto as UserPhoto exposing (UserPhoto)
|
||||
import Date.Format
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (attribute, class, classList, href, id, placeholder, src)
|
||||
import Html.Attributes exposing (attribute, class, classList, href, id, src)
|
||||
import Route exposing (Route)
|
||||
import Views.Article.Favorite as Favorite
|
||||
import Views.Author
|
||||
|
||||
|
||||
-- VIEWS --
|
||||
|
||||
|
||||
{-| Some pages want to view just the timestamp, not the whole article.
|
||||
-}
|
||||
viewTimestamp : Article a -> Html msg
|
||||
viewTimestamp article =
|
||||
span [ class "date" ] [ text (formattedTimestamp article) ]
|
||||
|
||||
|
||||
view : (Article a -> msg) -> Article a -> Html msg
|
||||
view toggleFavorite article =
|
||||
let
|
||||
@@ -35,7 +25,7 @@ view toggleFavorite article =
|
||||
[ img [ UserPhoto.src author.image ] [] ]
|
||||
, div [ class "info" ]
|
||||
[ Views.Author.view author.username
|
||||
, span [ class "date" ] [ text (formattedTimestamp article) ]
|
||||
, viewTimestamp article
|
||||
]
|
||||
, Favorite.button
|
||||
toggleFavorite
|
||||
@@ -51,8 +41,9 @@ view toggleFavorite article =
|
||||
]
|
||||
|
||||
|
||||
|
||||
-- INTERNAL --
|
||||
viewTimestamp : Article a -> Html msg
|
||||
viewTimestamp article =
|
||||
span [ class "date" ] [ text (formattedTimestamp article) ]
|
||||
|
||||
|
||||
formattedTimestamp : Article a -> String
|
||||
|
||||
Reference in New Issue
Block a user