Major early updates

This commit is contained in:
Connor Johnstone
2026-03-18 10:56:19 -04:00
parent 50a0ddcdbc
commit 55607df07b
20 changed files with 2665 additions and 1 deletions

View File

@@ -0,0 +1,86 @@
use yew::prelude::*;
use crate::api;
use crate::types::AppConfig;
#[function_component(SettingsPage)]
pub fn settings_page() -> Html {
let config = use_state(|| None::<AppConfig>);
let error = use_state(|| None::<String>);
let message = use_state(|| None::<String>);
{
let config = config.clone();
let error = error.clone();
use_effect_with((), move |_| {
wasm_bindgen_futures::spawn_local(async move {
match api::get_config().await {
Ok(c) => config.set(Some(c)),
Err(e) => error.set(Some(e.0)),
}
});
});
}
let trigger = |action: &'static str| {
let message = message.clone();
let error = error.clone();
Callback::from(move |_: MouseEvent| {
let message = message.clone();
let error = error.clone();
wasm_bindgen_futures::spawn_local(async move {
let result = match action {
"index" => api::trigger_index().await,
"tag" => api::trigger_tag().await,
"organize" => api::trigger_organize().await,
_ => return,
};
match result {
Ok(t) => message.set(Some(format!("{action} started (task: {})", t.task_id))),
Err(e) => error.set(Some(e.0)),
}
});
})
};
html! {
<div>
<div class="page-header">
<h2>{ "Settings" }</h2>
</div>
if let Some(ref msg) = *message {
<div class="card" style="border-color: var(--success);">{ msg }</div>
}
if let Some(ref err) = *error {
<div class="card error">{ err }</div>
}
<div class="card">
<h3>{ "Actions" }</h3>
<div class="actions mt-1">
<button class="btn btn-primary" onclick={trigger("index")}>{ "Re-index Library" }</button>
<button class="btn btn-primary" onclick={trigger("tag")}>{ "Auto-tag Tracks" }</button>
<button class="btn btn-primary" onclick={trigger("organize")}>{ "Organize Files" }</button>
</div>
</div>
{ match &*config {
None => html! { <p class="loading">{ "Loading configuration..." }</p> },
Some(c) => html! {
<div class="card mt-2">
<h3>{ "Configuration" }</h3>
<table>
<tbody>
<tr><td class="text-muted">{ "Library Path" }</td><td>{ &c.library_path }</td></tr>
<tr><td class="text-muted">{ "Database URL" }</td><td class="text-sm">{ &c.database_url }</td></tr>
<tr><td class="text-muted">{ "Download Path" }</td><td>{ &c.download_path }</td></tr>
<tr><td class="text-muted">{ "Organization Format" }</td><td><code>{ &c.organization_format }</code></td></tr>
</tbody>
</table>
</div>
},
}}
</div>
}
}