Skip to content

Commit 6179efd

Browse files
thewrzcodex
andcommitted
fix(ui): address sound sorting review findings
Keep grid rows aligned when cached indices no longer resolve and consolidate config loading through the explicit-path implementation. Co-Authored-By: Codex <noreply@openai.com>
1 parent 767723a commit 6179efd

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

src/state/config/persistence.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,7 @@ impl AppConfig {
1717

1818
/// Loads config from disk, creating defaults if the file is missing.
1919
pub fn load() -> Result<Self, ConfigError> {
20-
let path = Self::config_path()?;
21-
22-
if !path.exists() {
23-
let config = Self::default();
24-
config.save()?;
25-
return Ok(config);
26-
}
27-
28-
let contents = read_config(&path)?;
29-
serde_json::from_str(&contents).map_err(|source| ConfigError::Deserialize {
30-
path: path.display().to_string(),
31-
source,
32-
})
20+
Self::load_from(&Self::config_path()?)
3321
}
3422

3523
/// Persists config to disk, creating parent directories as needed.

src/ui/sound_grid.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn view_grid_columns<'a>(
101101
})
102102
.collect();
103103

104-
tiles.extend((0..missing_tile_slots(chunk.len(), columns)).map(|_| {
104+
tiles.extend((0..missing_tile_slots(tiles.len(), columns)).map(|_| {
105105
Space::new()
106106
.width(Length::Fill)
107107
.height(tile_layout::tile_slot_height())
@@ -302,6 +302,18 @@ pub fn context_menu_overlay<'a>(
302302
mod tests {
303303
use super::*;
304304

305+
fn test_sound() -> SoundEntry {
306+
SoundEntry {
307+
id: "sound".into(),
308+
name: "Sound".into(),
309+
path: "/sounds/sound.wav".into(),
310+
format: crate::state::AudioFormat::Wav,
311+
duration_ms: None,
312+
modified_ms: None,
313+
category: "Test".into(),
314+
}
315+
}
316+
305317
#[test]
306318
fn incomplete_rows_reserve_all_missing_tile_slots() {
307319
// Iced view rendering is intentionally not unit-tested here; this pins
@@ -312,4 +324,30 @@ mod tests {
312324
assert_eq!(missing_tile_slots(5, 5), 0);
313325
assert_eq!(missing_tile_slots(6, 5), 0);
314326
}
327+
328+
#[test]
329+
fn unresolved_indices_are_replaced_with_filler_slots() {
330+
let sounds = [test_sound()];
331+
let visible_indices = [0, 99];
332+
let slots = SlotMap::default();
333+
let triggers = std::array::from_fn(|_| None);
334+
let sound_meta = SoundMetaStore::default();
335+
let element = view_grid_columns(
336+
&sounds,
337+
&visible_indices,
338+
None,
339+
GridCtx {
340+
slots: &slots,
341+
triggers: &triggers,
342+
shortcuts_active: false,
343+
columns: 2,
344+
sound_meta: &sound_meta,
345+
},
346+
2,
347+
);
348+
let tree = iced_core::widget::Tree::new(element.as_widget());
349+
350+
assert_eq!(tree.children.len(), 1);
351+
assert_eq!(tree.children[0].children.len(), 2);
352+
}
315353
}

0 commit comments

Comments
 (0)