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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123module UI.Tracks.State exposing (..)
import Alienimport Base64import Common exposing (..)import ContextMenuimport Coordinates exposing (Coordinates)import Debouncer.Basic as Debouncerimport Dictimport Html.Events.Extra.Mouse as Mouseimport InfiniteListimport Json.Decode as Jsonimport Json.Encodeimport Keyboardimport List.Ext as Listimport List.Extra as Listimport Maybe.Extra as Maybeimport Notificationsimport Playlists exposing (Playlist)import Queueimport Return exposing (andThen, return)import Return.Ext as Returnimport Sourcesimport Task.Extra as Taskimport Tracks exposing (..)import Tracks.Collection as Collectionimport Tracks.Encoding as Encodingimport Tracks.Favourites as Favouritesimport UI.Common.State as Common exposing (showNotification)import UI.DnD as DnDimport UI.Pageimport UI.Ports as Portsimport UI.Queue.State as Queueimport UI.Themeimport UI.Tracks.ContextMenu as Tracksimport UI.Tracks.Covers as Coversimport UI.Tracks.Types as Tracks exposing (..)import UI.Types exposing (Manager, Model, Msg(..))import UI.User.State.Export as Userimport User.Layer exposing (HypaethralData)
-- 📣
update : Tracks.Msg -> Managerupdate msg = case msg of Download a b -> download a b
DownloadFinished -> downloadFinished
Harvest -> harvest
MarkAsSelected a b -> markAsSelected a b
ScrollToNowPlaying -> scrollToNowPlaying
SyncTags a -> syncTags a
ToggleCachedOnly -> toggleCachedOnly
ToggleCoverSelectionReducesPool -> toggleCoverSelectionReducesPool
ToggleFavouritesOnly -> toggleFavouritesOnly
ToggleHideDuplicates -> toggleHideDuplicates
----------------------------------------- -- Cache ----------------------------------------- ClearCache -> clearCache
RemoveFromCache a -> removeFromCache a
StoreInCache a -> storeInCache a
StoredInCache a b -> storedInCache a b
--------- -- Covers --------- GotCachedCover a -> gotCachedCover a
InsertCoverCache a -> insertCoverCache a
----------------------------------------- -- Collection ----------------------------------------- Add a -> add a
AddFavourites a -> addFavourites a
Reload a -> reload a
RemoveByPaths a -> removeByPaths a
RemoveBySourceId a -> removeBySourceId a
RemoveFavourites a -> removeFavourites a
SortBy a -> sortBy a
ToggleFavourite a -> toggleFavourite a
----------------------------------------- -- Groups ----------------------------------------- DisableGrouping -> disableGrouping
GroupBy a -> groupBy a
----------------------------------------- -- Menus ----------------------------------------- ShowCoverMenu a b -> showCoverMenu a b
ShowCoverMenuWithSmallDelay a b -> showCoverMenuWithDelay a b
ShowTracksMenu a b c -> showTracksMenu a b c
ShowTracksMenuWithSmallDelay a b c -> showTracksMenuWithDelay a b c
ShowViewMenu a b -> showViewMenu a b
----------------------------------------- -- Scenes ----------------------------------------- ChangeScene a -> changeScene a
DeselectCover -> deselectCover
InfiniteListMsg a -> infiniteListMsg a
SelectCover a -> selectCover a
----------------------------------------- -- Search ----------------------------------------- ClearSearch -> clearSearch
Search -> search
SetSearchResults a -> setSearchResults a
SetSearchTerm a -> setSearchTerm a
-- 🔱
add : Json.Value -> Manageradd encodedTracks model = reviseCollection (encodedTracks |> Json.decodeValue (Json.list Encoding.trackDecoder) |> Result.withDefault [] |> Collection.add ) model
addFavourites : List IdentifiedTrack -> ManageraddFavourites = manageFavourites AddToFavourites
afterInitialLoad : ManagerafterInitialLoad model = Common.toggleLoadingScreen Off model
changeScene : Scene -> ManagerchangeScene scene model = (case scene of Covers -> Ports.loadAlbumCovers { list = True, coverView = True }
List -> Cmd.none ) |> return { model | scene = scene, selectedCover = Nothing } |> andThen (if model.coverSelectionReducesPool then Queue.reset
else Return.singleton ) |> andThen Common.forceTracksRerender |> andThen User.saveEnclosedUserData
clearCache : ManagerclearCache model = model.cachedTracks |> Json.Encode.list Json.Encode.string |> Alien.broadcast Alien.RemoveTracksFromCache |> Ports.toBrain |> return { model | cachedTracks = [] } |> andThen harvest |> andThen User.saveEnclosedUserData |> andThen ("Tracks cache was cleared" |> Notifications.casual |> Common.showNotification )
clearSearch : ManagerclearSearch model = { model | searchResults = Nothing, searchTerm = Nothing } |> reviseCollection Collection.harvest |> andThen User.saveEnclosedUserData
deselectCover : ManagerdeselectCover model = (if model.coverSelectionReducesPool then Queue.reset
else Return.singleton ) { model | selectedCover = Nothing }
download : { prefixTrackNumber : Bool, zipName : String } -> List Track -> Managerdownload { prefixTrackNumber, zipName } tracks model = let notification = Notifications.stickyCasual "Downloading tracks ..."
downloading = Just { notificationId = Notifications.id notification } in [ ( "prefixTrackNumber", Json.Encode.bool prefixTrackNumber ) , ( "trackIds" , tracks |> List.map .id |> Json.Encode.list Json.Encode.string ) , ( "zipName", Json.Encode.string zipName ) ] |> Json.Encode.object |> Alien.broadcast Alien.DownloadTracks |> Ports.toBrain |> return { model | downloading = downloading } |> andThen (Common.showNotification notification)
downloadFinished : ManagerdownloadFinished model = case model.downloading of Just { notificationId } -> Common.dismissNotification { id = notificationId } { model | downloading = Nothing }
Nothing -> Return.singleton model
disableGrouping : ManagerdisableGrouping model = { model | grouping = Nothing } |> reviseCollection Collection.arrange |> andThen User.saveEnclosedUserData
failedToStoreInCache : List String -> ManagerfailedToStoreInCache trackIds m = showNotification (Notifications.error "Failed to store track in cache") { m | cachingTracksInProgress = List.without trackIds m.cachingTracksInProgress }
finishedStoringInCache : List String -> ManagerfinishedStoringInCache trackIds model = { model | cachedTracks = model.cachedTracks ++ trackIds , cachingTracksInProgress = List.without trackIds model.cachingTracksInProgress } |> (\m -> -- When a context menu of a track is open, -- it should be "rerendered" in case -- the track is no longer being downloaded. case m.contextMenu of Just contextMenu -> let isTrackContextMenu = ContextMenu.anyItem (.label >> (==) "Downloading ...") contextMenu
coordinates = ContextMenu.coordinates contextMenu in if isTrackContextMenu then showTracksMenu Nothing { alt = False } coordinates m
else Return.singleton m
Nothing -> Return.singleton m ) |> andThen harvest |> andThen User.saveEnclosedUserData
generateCovers : ManagergenerateCovers model = model.tracks |> Covers.generate model.sortBy |> (\c -> { model | covers = c }) |> Return.singleton
gotCachedCover : Json.Value -> ManagergotCachedCover json model = let cachedCovers = Maybe.withDefault Dict.empty model.cachedCovers
decodedValue = Json.decodeValue (Json.map3 (\i k u -> ( i, k, u )) (Json.field "imageType" Json.string) (Json.field "key" Json.string) (Json.field "url" Json.string) ) json in decodedValue |> Result.map (\( _, key, url ) -> Dict.insert key url cachedCovers) |> Result.map (\dict -> { model | cachedCovers = Just dict }) |> Result.withDefault model |> (\m -> case ( m.nowPlaying, decodedValue ) of ( Just nowPlaying, Ok val ) -> let ( imageType, key, url ) = val
( _, track ) = nowPlaying.item.identifiedTrack
hasntLoadedYet = nowPlaying.coverLoaded == False
( keyA, keyB ) = ( Base64.encode (Tracks.coverKey False track) , Base64.encode (Tracks.coverKey True track) )
keyMatches = keyA == key || keyB == key in if hasntLoadedYet && keyMatches then ( m, Ports.setMediaSessionArtwork { blobUrl = url, imageType = imageType } )
else Return.singleton m
_ -> Return.singleton m )
groupBy : Tracks.Grouping -> ManagergroupBy grouping model = { model | grouping = Just grouping } |> reviseCollection Collection.arrange |> andThen User.saveEnclosedUserData
harvest : Managerharvest = reviseCollection Collection.harvest
harvestCovers : ManagerharvestCovers model = model.covers |> Covers.harvest model.selectedCover model.sortBy model.tracks |> (\( c, s ) -> { model | covers = c, selectedCover = s }) |> Return.communicate (Ports.loadAlbumCovers { list = True, coverView = True })
infiniteListMsg : InfiniteList.Model -> ManagerinfiniteListMsg infiniteList model = return { model | infiniteList = infiniteList } (Ports.loadAlbumCovers { list = True, coverView = False })
insertCoverCache : Json.Value -> ManagerinsertCoverCache json model = json |> Json.decodeValue (Json.dict Json.string) |> Result.map (\dict -> { model | cachedCovers = Just dict }) |> Result.withDefault model |> Return.singleton
manageFavourites : FavouritesManagementAction -> List IdentifiedTrack -> ManagermanageFavourites action tracks model = let newFavourites = (case action of AddToFavourites -> Favourites.completeFavouritesList
RemoveFromFavourites -> Favourites.removeFromFavouritesList ) tracks model.favourites
effect collection = collection |> Collection.map (case action of AddToFavourites -> Favourites.completeTracksList tracks
RemoveFromFavourites -> Favourites.removeFromTracksList tracks ) |> (if model.favouritesOnly then Collection.harvest
else identity )
selectedCover = Maybe.map (\cover -> cover.tracks |> (case action of AddToFavourites -> Favourites.completeTracksList tracks
RemoveFromFavourites -> Favourites.removeFromTracksList tracks ) |> (\a -> { cover | tracks = a }) ) model.selectedCover in { model | favourites = newFavourites, selectedCover = selectedCover } |> reviseCollection effect |> andThen User.saveFavourites |> (if model.scene == Covers then andThen generateCovers >> andThen harvestCovers
else identity )
markAsSelected : Int -> { shiftKey : Bool } -> ManagermarkAsSelected indexInList { shiftKey } model = let selection = if shiftKey then model.selectedTrackIndexes |> List.head |> Maybe.map (\n -> if n > indexInList then List.range indexInList n
else List.range n indexInList ) |> Maybe.withDefault [ indexInList ]
else [ indexInList ] in Return.singleton { model | selectedTrackIndexes = selection }
reload : Json.Value -> Managerreload encodedTracks model = reviseCollection (encodedTracks |> Json.decodeValue (Json.list Encoding.trackDecoder) |> Result.withDefault model.tracks.untouched |> Collection.replace ) model
removeByPaths : Json.Value -> ManagerremoveByPaths encodedParams model = let decoder = Json.map2 Tuple.pair (Json.field "filePaths" <| Json.list Json.string) (Json.field "sourceId" Json.string)
( paths, sourceId ) = encodedParams |> Json.decodeValue decoder |> Result.withDefault ( [], missingId )
{ kept, removed } = Tracks.removeByPaths { sourceId = sourceId, paths = paths } model.tracks.untouched
newCollection = { emptyCollection | untouched = kept } in { model | tracks = newCollection } |> reviseCollection Collection.identify |> andThen (removeFromCache removed)
removeBySourceId : String -> ManagerremoveBySourceId sourceId model = let { kept, removed } = Tracks.removeBySourceId sourceId model.tracks.untouched
newCollection = { emptyCollection | untouched = kept } in sourceId |> Json.Encode.string |> Alien.broadcast Alien.RemoveTracksBySourceId |> Ports.toBrain |> return { model | tracks = newCollection } |> andThen (reviseCollection Collection.identify) |> andThen (removeFromCache removed)
removeFavourites : List IdentifiedTrack -> ManagerremoveFavourites = manageFavourites RemoveFromFavourites
removeFromCache : List Track -> ManagerremoveFromCache tracks model = let trackIds = List.map .id tracks in trackIds |> Json.Encode.list Json.Encode.string |> Alien.broadcast Alien.RemoveTracksFromCache |> Ports.toBrain |> return { model | cachedTracks = List.without trackIds model.cachedTracks } |> andThen harvest |> andThen User.saveEnclosedUserData
reviseCollection : (Parcel -> Parcel) -> ManagerreviseCollection collector model = resolveParcel (model |> makeParcel |> collector ) model
search : Managersearch model = case ( model.searchTerm, model.searchResults ) of ( Just term, _ ) -> term |> String.trim |> Json.Encode.string |> Ports.giveBrain Alien.SearchTracks |> return model
( Nothing, Just _ ) -> reviseCollection Collection.harvest { model | searchResults = Nothing }
( Nothing, Nothing ) -> Return.singleton model
selectCover : Cover -> ManagerselectCover cover model = { model | selectedCover = Just cover } |> (if model.coverSelectionReducesPool then Queue.reset
else Return.singleton ) |> Return.command (Ports.loadAlbumCovers { list = False, coverView = True })
setSearchResults : Json.Value -> ManagersetSearchResults json model = case model.searchTerm of Just _ -> json |> Json.decodeValue (Json.list Json.string) |> Result.withDefault [] |> (\results -> { model | searchResults = Just results }) |> reviseCollection Collection.harvest |> andThen afterInitialLoad
Nothing -> Return.singleton model
setSearchTerm : String -> ManagersetSearchTerm term model = (case String.trim term of "" -> { model | searchTerm = Nothing }
_ -> { model | searchTerm = Just term } ) |> Return.communicate (Search |> TracksMsg |> Debouncer.provideInput |> SearchDebounce |> Task.do ) |> Return.andThen User.saveEnclosedUserData
showCoverMenu : Cover -> Coordinates -> ManagershowCoverMenu cover coordinates model = let menuDependencies = { cached = model.cachedTracks , cachingInProgress = model.cachingTracksInProgress , currentTime = model.currentTime , selectedPlaylist = model.selectedPlaylist , lastModifiedPlaylistName = model.lastModifiedPlaylist , showAlternativeMenu = False , sources = model.sources } in coordinates |> Tracks.trackMenu menuDependencies cover.tracks |> Common.showContextMenuWithModel model
showCoverMenuWithDelay : Cover -> Coordinates -> ManagershowCoverMenuWithDelay a b model = Tracks.ShowCoverMenu a b |> TracksMsg |> Task.doDelayed 250 |> return model
showTracksMenu : Maybe Int -> { alt : Bool } -> Coordinates -> ManagershowTracksMenu maybeTrackIndex { alt } coordinates model = let selection = case maybeTrackIndex of Just trackIndex -> if List.isEmpty model.selectedTrackIndexes then [ trackIndex ]
else if List.member trackIndex model.selectedTrackIndexes == False then [ trackIndex ]
else model.selectedTrackIndexes
Nothing -> model.selectedTrackIndexes
menuDependencies = { cached = model.cachedTracks , cachingInProgress = model.cachingTracksInProgress , currentTime = model.currentTime , selectedPlaylist = model.selectedPlaylist , lastModifiedPlaylistName = model.lastModifiedPlaylist , showAlternativeMenu = alt , sources = model.sources }
tracks = List.pickIndexes selection model.tracks.harvested in coordinates |> Tracks.trackMenu menuDependencies tracks |> Common.showContextMenuWithModel { model | dnd = DnD.initialModel , selectedTrackIndexes = selection }
showTracksMenuWithDelay : Maybe Int -> { alt : Bool } -> Coordinates -> ManagershowTracksMenuWithDelay a b c model = Tracks.ShowTracksMenu a b c |> TracksMsg |> Task.doDelayed 250 |> return model
showViewMenu : Maybe Grouping -> Mouse.Event -> ManagershowViewMenu maybeGrouping mouseEvent model = mouseEvent.clientPos |> Coordinates.fromTuple |> Tracks.viewMenu model.cachedTracksOnly maybeGrouping |> Common.showContextMenuWithModel model
scrollToNowPlaying : ManagerscrollToNowPlaying model = model.nowPlaying |> Maybe.map (.item >> .identifiedTrack >> Tuple.second >> .id) |> Maybe.andThen (\id -> List.find (Tuple.second >> .id >> (==) id) model.tracks.harvested ) |> Maybe.map (\( identifiers, track ) -> case model.scene of Covers -> if List.member Keyboard.Shift model.pressedKeys then return { model | selectedCover = Nothing } (UI.Theme.scrollToNowPlaying Covers ( identifiers, track ) model)
else model.covers.harvested |> List.find (\cover -> List.member track.id cover.trackIds) |> Maybe.unwrap model (\cover -> { model | selectedCover = Just cover }) |> Return.communicate (Ports.loadAlbumCovers { list = True, coverView = True })
List -> return { model | selectedCover = Nothing } (UI.Theme.scrollToNowPlaying List ( identifiers, track ) model) ) |> Maybe.map (UI.Page.Index |> Common.changeUrlUsingPage |> andThen ) |> Maybe.withDefault (Return.singleton model)
sortBy : SortBy -> ManagersortBy property model = let sortDir = if model.sortBy /= property then Asc
else if model.sortDirection == Asc then Desc
else Asc in { model | sortBy = property, sortDirection = sortDir } |> reviseCollection Collection.arrange |> andThen User.saveEnclosedUserData
storeInCache : List Track -> ManagerstoreInCache tracks model = let trackIds = List.map .id tracks
notification = case tracks of [ t ] -> ("__" ++ t.tags.title ++ "__ will be stored in the cache") |> Notifications.casual
list -> list |> List.length |> String.fromInt |> (\s -> "__" ++ s ++ " tracks__ will be stored in the cache") |> Notifications.casual in tracks |> Json.Encode.list (\track -> Json.Encode.object [ ( "trackId" , Json.Encode.string track.id ) , ( "url" , track |> Queue.makeTrackUrl model.currentTime model.sources |> Json.Encode.string ) ] ) |> Alien.broadcast Alien.StoreTracksInCache |> Ports.toBrain |> return { model | cachingTracksInProgress = model.cachingTracksInProgress ++ trackIds } |> andThen (Common.showNotification notification)
storedInCache : Json.Value -> Maybe String -> ManagerstoredInCache json maybeError = case ( maybeError , Json.decodeValue (Json.list Json.string) json ) of ( Nothing, Ok list ) -> finishedStoringInCache list
( Nothing, Err err ) -> err |> Json.errorToString |> Notifications.error |> Common.showNotification
( Just _, Ok trackIds ) -> failedToStoreInCache trackIds
( Just err, Err _ ) -> err |> Notifications.error |> Common.showNotification
syncTags : List Track -> ManagersyncTags tracks = tracks |> Json.Encode.list (\track -> Json.Encode.object [ ( "path", Json.Encode.string track.path ) , ( "sourceId", Json.Encode.string track.sourceId ) , ( "trackId", Json.Encode.string track.id ) ] ) |> Alien.broadcast Alien.SyncTrackTags |> Ports.toBrain |> Return.communicate
toggleCachedOnly : ManagertoggleCachedOnly model = { model | cachedTracksOnly = not model.cachedTracksOnly } |> reviseCollection Collection.harvest |> andThen User.saveEnclosedUserData |> andThen Common.forceTracksRerender
toggleCoverSelectionReducesPool : ManagertoggleCoverSelectionReducesPool model = { model | coverSelectionReducesPool = not model.coverSelectionReducesPool } |> Queue.reset |> andThen User.saveSettings
toggleFavourite : Int -> ManagertoggleFavourite index model = case List.getAt index model.tracks.harvested of Just ( i, t ) -> let newFavourites = Favourites.toggleInFavouritesList ( i, t ) model.favourites
effect collection = collection |> Collection.map (Favourites.toggleInTracksList t) |> (if model.favouritesOnly then Collection.harvest
else identity )
selectedCover = Maybe.map (\cover -> cover.tracks |> Favourites.toggleInTracksList t |> (\a -> { cover | tracks = a }) ) model.selectedCover in { model | favourites = newFavourites, selectedCover = selectedCover } |> reviseCollection effect |> andThen User.saveFavourites |> (if model.scene == Covers then andThen generateCovers >> andThen harvestCovers
else identity )
Nothing -> Return.singleton model
toggleFavouritesOnly : ManagertoggleFavouritesOnly model = { model | favouritesOnly = not model.favouritesOnly } |> reviseCollection Collection.harvest |> andThen User.saveEnclosedUserData
toggleHideDuplicates : ManagertoggleHideDuplicates model = { model | hideDuplicates = not model.hideDuplicates } |> reviseCollection Collection.arrange |> andThen User.saveSettings
-- 📣 ░░ PARCEL
makeParcel : Model -> ParcelmakeParcel model = ( { cached = model.cachedTracks , cachedOnly = model.cachedTracksOnly , enabledSourceIds = Sources.enabledSourceIds model.sources , favourites = model.favourites , favouritesOnly = model.favouritesOnly , grouping = model.grouping , hideDuplicates = model.hideDuplicates , searchResults = model.searchResults , selectedPlaylist = model.selectedPlaylist , sortBy = model.sortBy , sortDirection = model.sortDirection } , model.tracks )
resolveParcel : Parcel -> ManagerresolveParcel ( deps, newCollection ) model = let scrollObj = Json.Encode.object [ ( "scrollTop", Json.Encode.int 0 ) ]
scrollEvent = Json.Encode.object [ ( "target", scrollObj ) ]
newScrollContext = scrollContext model
collectionChanged = Collection.tracksChanged model.tracks.untouched newCollection.untouched
arrangementChanged = if collectionChanged then True
else Collection.identifiedTracksChanged model.tracks.arranged newCollection.arranged
harvestChanged = if arrangementChanged then True
else Collection.identifiedTracksChanged model.tracks.harvested newCollection.harvested
scrollContextChanged = newScrollContext /= model.tracks.scrollContext
modelWithNewCollection = (if model.scene == List && scrollContextChanged then \m -> { m | infiniteList = InfiniteList.updateScroll scrollEvent m.infiniteList }
else identity ) { model | tracks = { newCollection | scrollContext = newScrollContext } , selectedTrackIndexes = if collectionChanged || harvestChanged then []
else model.selectedTrackIndexes } in (if collectionChanged then whenCollectionChanges
else if arrangementChanged then whenArrangementChanges
else if harvestChanged then whenHarvestChanges
else identity ) ( modelWithNewCollection ----------------------------------------- -- Command ----------------------------------------- , if scrollContextChanged then UI.Theme.scrollTracksToTop model.scene
else Cmd.none )
whenHarvestChanges = andThen harvestCovers >> andThen Queue.reset
whenArrangementChanges = andThen generateCovers >> whenHarvestChanges
whenCollectionChanges = andThen search >> andThen Common.generateDirectoryPlaylists >> whenArrangementChanges
scrollContext : Model -> StringscrollContext model = String.concat [ Maybe.withDefault "" <| model.searchTerm , Maybe.withDefault "" <| Maybe.map .name model.selectedPlaylist ]
-- 📣 ░░ USER DATA
importHypaethral : HypaethralData -> Maybe Playlist -> ManagerimportHypaethral data selectedPlaylist model = { model | favourites = data.favourites , selectedPlaylist = selectedPlaylist , tracks = { emptyCollection | untouched = data.tracks } } |> reviseCollection Collection.identify |> andThen search |> (case model.searchTerm of Just _ -> identity
Nothing -> andThen afterInitialLoad )
-- ㊙️
type FavouritesManagementAction = AddToFavourites | RemoveFromFavourites