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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150module UI.Common.State exposing (..)
import Browser.Navigation as Navimport Common exposing (..)import ContextMenu exposing (ContextMenu)import Debouncer.Basic as Debouncer exposing (Debouncer)import List.Extra as Listimport Maybe.Extra as Maybeimport Monocle.Lens as Lens exposing (Lens)import Notifications exposing (Notification)import Return exposing (return)import UI.Notificationsimport UI.Page as Page exposing (Page)import UI.Playlists.Directoryimport UI.Syncing.Types as Syncingimport UI.Types as UI exposing (Manager, Model, Msg)import User.Layer exposing (Method)
-- 📣
changeUrlUsingPage : Page -> ManagerchangeUrlUsingPage page model = page |> Page.toString |> Nav.pushUrl model.navKey |> return model
debounce : (Model -> Debouncer Msg Msg) -> (Debouncer Msg Msg -> Model -> Model) -> (Debouncer.Msg Msg -> Msg) -> (Msg -> Model -> ( Model, Cmd Msg )) -> Debouncer.Msg Msg -> Managerdebounce getter setter debouncerMsgContainer update debouncerMsg model = let ( subModel, subCmd, emittedMsg ) = Debouncer.update debouncerMsg (getter model)
mappedCmd = Cmd.map debouncerMsgContainer subCmd
updatedModel = setter subModel model in case emittedMsg of Just emitted -> updatedModel |> update emitted |> Return.command mappedCmd
Nothing -> return updatedModel mappedCmd
dismissNotification : { id : Int } -> ManagerdismissNotification options model = options |> UI.Notifications.dismiss model.notifications |> Return.map (\n -> { model | notifications = n })
forceTracksRerender : ManagerforceTracksRerender model = -- -- TODO: -- -- let -- containerId = -- case model.scene of -- Tracks.Covers -> -- UI.Tracks.Scene.Covers.containerId -- Tracks.List -> -- UI.Tracks.Scene.List.containerId -- in -- Browser.Dom.setViewportOf containerId 0 1 -- |> Task.attempt (always UI.Bypass) -- |> return model -- Return.singleton model
generateDirectoryPlaylists : ManagergenerateDirectoryPlaylists model = let nonDirectoryPlaylists = List.filterNot (.autoGenerated >> Maybe.isJust) model.playlists
directoryPlaylists = UI.Playlists.Directory.generate model.sources model.tracks.untouched in [ nonDirectoryPlaylists , directoryPlaylists ] |> List.concat |> (\c -> { model | playlists = c }) |> Return.singleton
showContextMenuWithModel : UI.Model -> ContextMenu Msg -> ( UI.Model, Cmd UI.Msg )showContextMenuWithModel model contextMenu = Return.singleton { model | contextMenu = Just contextMenu }
showNotification : Notification Msg -> ManagershowNotification notification model = model.notifications |> UI.Notifications.show notification |> Return.map (\n -> { model | notifications = n })
showNotificationWithModel : UI.Model -> Notification Msg -> ( UI.Model, Cmd UI.Msg )showNotificationWithModel model notification = showNotification notification model
showSyncingNotification : Method -> ManagershowSyncingNotification method model = let notification = Notifications.stickyCasual "Syncing user data ..."
syncing = Syncing.Syncing { method = method, notificationId = Notifications.id notification } in showNotification notification { model | syncing = syncing }
toggleLoadingScreen : Switch -> ManagertoggleLoadingScreen switch model = case switch of On -> Return.singleton { model | isLoading = True }
Off -> Return.singleton { model | isLoading = False }
-- 🛠
modifySingleton : Lens a b -> (b -> b) -> a -> ( a, Cmd msg )modifySingleton lens modifier = Lens.modify lens modifier >> Return.singleton