2017-05-29 10:28:01 -04:00
|
|
|
module Update.Route exposing (update)
|
|
|
|
|
|
|
|
import Command
|
2017-11-29 08:06:08 -05:00
|
|
|
import Mastodon.Model exposing (StatusId(..))
|
2017-05-29 10:28:01 -04:00
|
|
|
import Types exposing (..)
|
|
|
|
import Update.AccountInfo
|
|
|
|
import Update.Timeline
|
|
|
|
import UrlParser exposing (..)
|
|
|
|
|
|
|
|
|
|
|
|
type Route
|
2017-11-29 08:06:08 -05:00
|
|
|
= AccountFollowersRoute String
|
|
|
|
| AccountFollowingRoute String
|
|
|
|
| AccountRoute String
|
2021-01-11 23:20:35 -05:00
|
|
|
| AccountRepliesRoute String
|
2017-05-29 10:28:01 -04:00
|
|
|
| AccountSelectorRoute
|
|
|
|
| BlocksRoute
|
|
|
|
| FavoriteTimelineRoute
|
|
|
|
| GlobalTimelineRoute
|
|
|
|
| HashtagRoute String
|
|
|
|
| LocalTimelineRoute
|
|
|
|
| MutesRoute
|
2017-05-30 18:27:30 -04:00
|
|
|
| SearchRoute
|
2017-11-29 08:06:08 -05:00
|
|
|
| ThreadRoute StatusId
|
|
|
|
|
|
|
|
|
|
|
|
statusIdParser : Parser (StatusId -> a) a
|
|
|
|
statusIdParser =
|
|
|
|
custom "id" (Ok << StatusId)
|
2017-05-29 10:28:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
route : Parser (Route -> a) a
|
|
|
|
route =
|
|
|
|
oneOf
|
|
|
|
[ map LocalTimelineRoute top
|
|
|
|
, map GlobalTimelineRoute (s "global" </> top)
|
|
|
|
, map FavoriteTimelineRoute (s "favorites" </> top)
|
|
|
|
, map HashtagRoute (s "hashtag" </> string)
|
2017-11-29 08:06:08 -05:00
|
|
|
, map ThreadRoute (s "thread" </> statusIdParser)
|
2017-05-29 10:28:01 -04:00
|
|
|
, map BlocksRoute (s "blocks" </> top)
|
|
|
|
, map MutesRoute (s "mutes" </> top)
|
2017-11-29 08:06:08 -05:00
|
|
|
, map AccountFollowersRoute (s "account" </> string </> s "followers")
|
|
|
|
, map AccountFollowingRoute (s "account" </> string </> s "following")
|
2021-01-11 23:20:35 -05:00
|
|
|
, map AccountRepliesRoute (s "account" </> string </> s "replies")
|
2017-11-29 08:06:08 -05:00
|
|
|
, map AccountRoute (s "account" </> string)
|
2017-05-29 10:28:01 -04:00
|
|
|
, map AccountSelectorRoute (s "accounts")
|
2017-05-30 18:27:30 -04:00
|
|
|
, map SearchRoute (s "search" </> top)
|
2017-05-29 10:28:01 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
update : Model -> ( Model, Cmd Msg )
|
|
|
|
update ({ accountInfo } as model) =
|
|
|
|
case parseHash route model.location of
|
|
|
|
Just LocalTimelineRoute ->
|
|
|
|
{ model | currentView = LocalTimelineView } ! []
|
|
|
|
|
|
|
|
Just GlobalTimelineRoute ->
|
|
|
|
{ model | currentView = GlobalTimelineView } ! []
|
|
|
|
|
|
|
|
Just FavoriteTimelineRoute ->
|
|
|
|
{ model
|
|
|
|
| currentView = FavoriteTimelineView
|
|
|
|
, favoriteTimeline = Update.Timeline.setLoading True model.favoriteTimeline
|
|
|
|
}
|
|
|
|
! [ Command.loadFavoriteTimeline (List.head model.clients) Nothing ]
|
|
|
|
|
|
|
|
Just BlocksRoute ->
|
|
|
|
{ model
|
|
|
|
| currentView = BlocksView
|
|
|
|
, blocks = Update.Timeline.setLoading True model.blocks
|
|
|
|
}
|
|
|
|
! [ Command.loadBlocks (List.head model.clients) Nothing ]
|
|
|
|
|
|
|
|
Just MutesRoute ->
|
|
|
|
{ model
|
|
|
|
| currentView = MutesView
|
|
|
|
, mutes = Update.Timeline.setLoading True model.mutes
|
|
|
|
}
|
|
|
|
! [ Command.loadMutes (List.head model.clients) Nothing ]
|
|
|
|
|
|
|
|
Just AccountSelectorRoute ->
|
|
|
|
{ model | currentView = AccountSelectorView, server = "" } ! []
|
|
|
|
|
2021-01-11 23:20:35 -05:00
|
|
|
Just (AccountRepliesRoute accountId) ->
|
|
|
|
{ model
|
|
|
|
| currentView = AccountView AccountStatusesRepliesView
|
|
|
|
, accountInfo = Update.AccountInfo.empty
|
|
|
|
}
|
|
|
|
! [ Command.loadAccount (List.head model.clients) accountId
|
|
|
|
, Command.loadAccountTimelineReplies (List.head model.clients) accountId Nothing
|
|
|
|
]
|
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
Just (AccountRoute accountId) ->
|
|
|
|
{ model
|
|
|
|
| currentView = AccountView AccountStatusesView
|
|
|
|
, accountInfo = Update.AccountInfo.empty
|
|
|
|
}
|
|
|
|
! [ Command.loadAccount (List.head model.clients) accountId
|
2021-01-12 01:08:43 -05:00
|
|
|
, Command.loadAccountPins (List.head model.clients) accountId Nothing
|
2017-05-29 10:28:01 -04:00
|
|
|
, Command.loadAccountTimeline (List.head model.clients) accountId Nothing
|
|
|
|
]
|
|
|
|
|
|
|
|
Just (AccountFollowersRoute accountId) ->
|
|
|
|
{ model
|
|
|
|
| currentView = AccountView AccountFollowersView
|
|
|
|
, accountInfo = { accountInfo | followers = Update.Timeline.empty "account-followers" }
|
|
|
|
}
|
|
|
|
! [ Command.loadAccount (List.head model.clients) accountId
|
|
|
|
, Command.loadAccountFollowers (List.head model.clients) accountId Nothing
|
|
|
|
]
|
|
|
|
|
|
|
|
Just (AccountFollowingRoute accountId) ->
|
|
|
|
{ model
|
|
|
|
| currentView = AccountView AccountFollowingView
|
|
|
|
, accountInfo = { accountInfo | following = Update.Timeline.empty "account-following" }
|
|
|
|
}
|
|
|
|
! [ Command.loadAccount (List.head model.clients) accountId
|
|
|
|
, Command.loadAccountFollowing (List.head model.clients) accountId Nothing
|
|
|
|
]
|
|
|
|
|
|
|
|
Just (HashtagRoute hashtag) ->
|
|
|
|
{ model
|
|
|
|
| currentView = HashtagView hashtag
|
|
|
|
, hashtagTimeline = Update.Timeline.setLoading True model.hashtagTimeline
|
|
|
|
}
|
|
|
|
! [ Command.loadHashtagTimeline (List.head model.clients) hashtag Nothing ]
|
|
|
|
|
|
|
|
Just (ThreadRoute id) ->
|
|
|
|
{ model | currentView = ThreadView (Thread Nothing Nothing) }
|
|
|
|
! [ Command.loadThread (List.head model.clients) id ]
|
|
|
|
|
2017-05-30 18:27:30 -04:00
|
|
|
Just SearchRoute ->
|
|
|
|
{ model | currentView = SearchView } ! []
|
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
_ ->
|
|
|
|
{ model | currentView = LocalTimelineView } ! []
|