Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162module UI.Routing.State exposing (linkClicked, openUrlOnNewPage, resetUrl, transition, urlChanged)
import Browser exposing (UrlRequest)import Browser.Navigation as Navimport List.Extra as Listimport Monocle.Lens as Lensimport Return exposing (return)import Sourcesimport Sources.Services.Dropboximport Sources.Services.Googleimport UI.Common.State as Commonimport UI.Page as Page exposing (Page)import UI.Ports as Portsimport UI.Sources.Formimport UI.Sources.Pageimport UI.Sources.State as Sourcesimport UI.Sources.Types as Sourcesimport UI.Types as UI exposing (Manager)import Url exposing (Url)
-- 🔱
linkClicked : UrlRequest -> ManagerlinkClicked urlRequest model = case urlRequest of Browser.Internal urlWithFragment -> let url = if urlWithFragment.fragment == Just "/" then { urlWithFragment | fragment = Nothing }
else urlWithFragment in if url.path /= model.url.path then return model (Nav.load url.path)
else return model (Nav.pushUrl model.navKey <| Url.toString url)
Browser.External href -> return model (Nav.load href)
openUrlOnNewPage : String -> ManageropenUrlOnNewPage url model = url |> Ports.openUrlOnNewPage |> return model
urlChanged : Url -> ManagerurlChanged url model = let rewrittenUrl = Page.rewriteUrl { url | query = Nothing } in case ( url.query, Page.fromUrl rewrittenUrl ) of ( Nothing, Just page ) -> transition page { model | page = page, url = url }
( Just _, Just page ) -> return model (resetUrl model.navKey url page)
_ -> return model (resetUrl model.navKey url Page.Index)
-- TRANSITIONING
transition : Page -> Managertransition page model = case page of ----------------------------------------- -- Sources.NewThroughRedirect ----------------------------------------- Page.Sources (UI.Sources.Page.NewThroughRedirect service args) -> let ( form, defaultContext ) = ( model.sourceForm , UI.Sources.Form.defaultContext ) in { defaultContext | data = case service of Sources.Dropbox -> Sources.Services.Dropbox.authorizationSourceData args
Sources.Google -> Sources.Services.Google.authorizationSourceData args
_ -> defaultContext.data , service = service } |> (\c -> { form | context = c, step = Sources.By }) |> (\f -> { model | sourceForm = f }) |> Return.singleton
----------------------------------------- -- Sources.Edit ----------------------------------------- Page.Sources (UI.Sources.Page.Edit sourceId) -> loadSourceForForm sourceId model
----------------------------------------- -- Sources.Rename ----------------------------------------- Page.Sources (UI.Sources.Page.Rename sourceId) -> loadSourceForForm sourceId model
----------------------------------------- -- 📭 ----------------------------------------- _ -> Return.singleton model
-- 🚀
resetUrl : Nav.Key -> Url -> Page.Page -> Cmd UI.MsgresetUrl key url page = Nav.replaceUrl key (url.path ++ Page.toString page)
-- ㊙️
loadSourceForForm : String -> ManagerloadSourceForForm sourceId model = let isLoading = model.isLoading
maybeSource = List.find (.id >> (==) sourceId) model.sources in case ( isLoading, maybeSource ) of ( False, Just source ) -> model |> Lens.modify Sources.formLens (\m -> { m | context = source }) |> Return.singleton
( False, Nothing ) -> Return.singleton model
( True, _ ) -> -- Redirect away from edit-source page Common.changeUrlUsingPage (Page.Sources UI.Sources.Page.Index) model