Only expand one album at a time
This commit is contained in:
parent
16214369f5
commit
ee70f6742c
4 changed files with 37 additions and 14 deletions
|
@ -13,6 +13,9 @@ pub type Library {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An ID that can never match any library item
|
||||||
|
pub const invalid_id = -1
|
||||||
|
|
||||||
/// Gets an empty library for use as a default value.
|
/// Gets an empty library for use as a default value.
|
||||||
pub fn empty() {
|
pub fn empty() {
|
||||||
Library(albums: map.new(), artists: map.new(), tracks: map.new())
|
Library(albums: map.new(), artists: map.new(), tracks: map.new())
|
||||||
|
|
10
src/elekf/utils/misc.gleam
Normal file
10
src/elekf/utils/misc.gleam
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//// Miscellaneous utilities that do not fit anywhere else.
|
||||||
|
|
||||||
|
/// Toggle a value with a new value - if the new value is the same as the
|
||||||
|
/// previous, returns the "null" value. Otherwise returns the new value.
|
||||||
|
pub fn toggle(prev: a, new: a, null: a) {
|
||||||
|
case new == prev {
|
||||||
|
True -> null
|
||||||
|
False -> new
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@
|
||||||
import gleam/string
|
import gleam/string
|
||||||
import gleam/list
|
import gleam/list
|
||||||
import gleam/map
|
import gleam/map
|
||||||
import gleam/set
|
|
||||||
import gleam/option
|
import gleam/option
|
||||||
import gleam/dynamic
|
import gleam/dynamic
|
||||||
import gleam/result
|
import gleam/result
|
||||||
|
@ -11,7 +10,7 @@ import lustre
|
||||||
import lustre/effect
|
import lustre/effect
|
||||||
import lustre/attribute
|
import lustre/attribute
|
||||||
import lustre/element
|
import lustre/element
|
||||||
import elekf/utils/set as set_utils
|
import elekf/utils/misc
|
||||||
import elekf/library.{type Library}
|
import elekf/library.{type Library}
|
||||||
import elekf/library/album.{type Album}
|
import elekf/library/album.{type Album}
|
||||||
import elekf/library/album_utils
|
import elekf/library/album_utils
|
||||||
|
@ -23,7 +22,7 @@ import elekf/web/common
|
||||||
const component_name = "albums-view"
|
const component_name = "albums-view"
|
||||||
|
|
||||||
type Model {
|
type Model {
|
||||||
Model(library_view: library_view.Model(Album), expanded_albums: set.Set(Int))
|
Model(library_view: library_view.Model(Album), expanded_album: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Msg {
|
type Msg {
|
||||||
|
@ -62,7 +61,7 @@ fn init() {
|
||||||
library_view.init(library.empty(), data_getter, shuffler)
|
library_view.init(library.empty(), data_getter, shuffler)
|
||||||
|
|
||||||
#(
|
#(
|
||||||
Model(library_view: lib_m, expanded_albums: set.new()),
|
Model(library_view: lib_m, expanded_album: library.invalid_id),
|
||||||
effect.map(lib_e, LibraryViewMsg),
|
effect.map(lib_e, LibraryViewMsg),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,11 @@ fn update(model: Model, msg) {
|
||||||
#(
|
#(
|
||||||
Model(
|
Model(
|
||||||
..model,
|
..model,
|
||||||
expanded_albums: set_utils.toggle(model.expanded_albums, album.0),
|
expanded_album: misc.toggle(
|
||||||
|
model.expanded_album,
|
||||||
|
album.0,
|
||||||
|
library.invalid_id,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
effect.none(),
|
effect.none(),
|
||||||
)
|
)
|
||||||
|
@ -116,6 +119,6 @@ fn view(model: Model, item: LibraryItem(Album)) {
|
||||||
model.library_view.library,
|
model.library_view.library,
|
||||||
model.library_view.settings,
|
model.library_view.settings,
|
||||||
item,
|
item,
|
||||||
set.contains(model.expanded_albums, item.0),
|
item.0 == model.expanded_album,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import gleam/string
|
import gleam/string
|
||||||
import gleam/list
|
import gleam/list
|
||||||
import gleam/map
|
import gleam/map
|
||||||
import gleam/set
|
|
||||||
import gleam/option
|
import gleam/option
|
||||||
import gleam/dynamic
|
import gleam/dynamic
|
||||||
import gleam/result
|
import gleam/result
|
||||||
|
@ -12,7 +11,7 @@ import lustre/element/html.{div, header}
|
||||||
import lustre/element.{text}
|
import lustre/element.{text}
|
||||||
import lustre/attribute
|
import lustre/attribute
|
||||||
import lustre/effect
|
import lustre/effect
|
||||||
import elekf/utils/set as set_utils
|
import elekf/utils/misc
|
||||||
import elekf/library.{type Library}
|
import elekf/library.{type Library}
|
||||||
import elekf/library/album.{type Album}
|
import elekf/library/album.{type Album}
|
||||||
import elekf/library/album_utils
|
import elekf/library/album_utils
|
||||||
|
@ -28,7 +27,7 @@ type Model {
|
||||||
Model(
|
Model(
|
||||||
library_view: library_view.Model(Album),
|
library_view: library_view.Model(Album),
|
||||||
artist: option.Option(LibraryItem(Artist)),
|
artist: option.Option(LibraryItem(Artist)),
|
||||||
expanded_albums: set.Set(Int),
|
expanded_album: Int,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +84,11 @@ fn init() {
|
||||||
)
|
)
|
||||||
|
|
||||||
#(
|
#(
|
||||||
Model(artist: option.None, expanded_albums: set.new(), library_view: lib_m),
|
Model(
|
||||||
|
artist: option.None,
|
||||||
|
expanded_album: library.invalid_id,
|
||||||
|
library_view: lib_m,
|
||||||
|
),
|
||||||
effect.map(lib_e, LibraryViewMsg),
|
effect.map(lib_e, LibraryViewMsg),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -95,7 +98,7 @@ fn update(model: Model, msg) {
|
||||||
ArtistUpdated(option.Some(artist)) -> #(
|
ArtistUpdated(option.Some(artist)) -> #(
|
||||||
Model(
|
Model(
|
||||||
artist: option.Some(artist),
|
artist: option.Some(artist),
|
||||||
expanded_albums: set.new(),
|
expanded_album: library.invalid_id,
|
||||||
library_view: library_view.Model(
|
library_view: library_view.Model(
|
||||||
..model.library_view,
|
..model.library_view,
|
||||||
data: data_getter(model.library_view.library, artist),
|
data: data_getter(model.library_view.library, artist),
|
||||||
|
@ -106,7 +109,7 @@ fn update(model: Model, msg) {
|
||||||
ArtistUpdated(option.None) -> #(
|
ArtistUpdated(option.None) -> #(
|
||||||
Model(
|
Model(
|
||||||
artist: option.None,
|
artist: option.None,
|
||||||
expanded_albums: set.new(),
|
expanded_album: library.invalid_id,
|
||||||
library_view: library_view.Model(..model.library_view, data: []),
|
library_view: library_view.Model(..model.library_view, data: []),
|
||||||
),
|
),
|
||||||
effect.none(),
|
effect.none(),
|
||||||
|
@ -114,7 +117,11 @@ fn update(model: Model, msg) {
|
||||||
LibraryViewMsg(AlbumExpandToggled(album)) -> #(
|
LibraryViewMsg(AlbumExpandToggled(album)) -> #(
|
||||||
Model(
|
Model(
|
||||||
..model,
|
..model,
|
||||||
expanded_albums: set_utils.toggle(model.expanded_albums, album.0),
|
expanded_album: misc.toggle(
|
||||||
|
model.expanded_album,
|
||||||
|
album.0,
|
||||||
|
library.invalid_id,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
effect.none(),
|
effect.none(),
|
||||||
)
|
)
|
||||||
|
@ -186,7 +193,7 @@ fn album_view(model: Model, item: LibraryItem(Album)) {
|
||||||
model.library_view.library,
|
model.library_view.library,
|
||||||
model.library_view.settings,
|
model.library_view.settings,
|
||||||
item,
|
item,
|
||||||
set.contains(model.expanded_albums, item.0),
|
item.0 == model.expanded_album,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue