mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
42 lines
931 B
Swift
42 lines
931 B
Swift
//
|
|
// AlbumListReducer.swift
|
|
// Persephone
|
|
//
|
|
// Created by Daniel Barber on 2019/4/21.
|
|
// Copyright © 2019 Dan Barber. All rights reserved.
|
|
//
|
|
|
|
import ReSwift
|
|
|
|
func albumListReducer(action: Action, state: AlbumListState?) -> AlbumListState {
|
|
var state = state ?? AlbumListState()
|
|
|
|
switch action {
|
|
case let action as UpdateAlbumListAction:
|
|
state.albums = action.albums.map { Album(mpdAlbum: $0) }
|
|
|
|
case let action as UpdateCoverArtAction:
|
|
state.albums[action.albumIndex].coverArt = .loaded(action.coverArt)
|
|
|
|
case is ResetAlbumListCoverArtAction:
|
|
state.albums = AppDelegate.store.state.albumListState.albums.map {
|
|
var album = $0
|
|
switch album.coverArt {
|
|
case .loaded(let coverArt):
|
|
if coverArt == nil {
|
|
album.coverArt = .notLoaded
|
|
}
|
|
default:
|
|
album.coverArt = .notLoaded
|
|
}
|
|
return album
|
|
}
|
|
|
|
default:
|
|
break
|
|
|
|
}
|
|
|
|
return state
|
|
}
|