Sort playlists by last video date
This commit is contained in:
		
							parent
							
								
									67e633d887
								
							
						
					
					
						commit
						5b902ec915
					
				| @ -50,7 +50,32 @@ decodePlaylist = | |||||||
| 
 | 
 | ||||||
| decodePlaylists : Decode.Decoder (List Playlist) | decodePlaylists : Decode.Decoder (List Playlist) | ||||||
| decodePlaylists = | decodePlaylists = | ||||||
|     Decode.map (List.sortBy .url >> List.reverse) (Decode.list decodePlaylist) |     Decode.map (sortPlaylists >> List.reverse) (Decode.list decodePlaylist) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | mostRecentVideo : List Video -> Maybe Time.Posix | ||||||
|  | mostRecentVideo videos = | ||||||
|  |     case ( videos, List.map .date videos ) of | ||||||
|  |         ( _, (Just t) :: _ ) -> | ||||||
|  |             Just t | ||||||
|  | 
 | ||||||
|  |         ( _ :: t, Nothing :: _ ) -> | ||||||
|  |             mostRecentVideo t | ||||||
|  | 
 | ||||||
|  |         _ -> | ||||||
|  |             Nothing | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | playlistDate : Playlist -> Int | ||||||
|  | playlistDate playlist = | ||||||
|  |     mostRecentVideo playlist.videos | ||||||
|  |         |> Maybe.map Time.posixToMillis | ||||||
|  |         |> Maybe.withDefault 0 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | sortPlaylists : List Playlist -> List Playlist | ||||||
|  | sortPlaylists list = | ||||||
|  |     List.sortBy playlistDate list | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| fetchPlaylists : (Result Http.Error (List Playlist) -> msg) -> Cmd msg | fetchPlaylists : (Result Http.Error (List Playlist) -> msg) -> Cmd msg | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user