forked from Zynh0722/nyazoom
fix remaining text
parent
e58b966319
commit
2acdcc6d2f
|
@ -53,6 +53,15 @@ async fn link_delete(
|
|||
Ok(Html("".to_string()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_remaining_text(downloads_remaining: u8) -> String {
|
||||
let plural = if downloads_remaining > 1 { "s" } else { "" };
|
||||
format!(
|
||||
"You have {} download{} remaining!",
|
||||
downloads_remaining, plural
|
||||
)
|
||||
}
|
||||
|
||||
async fn remaining(
|
||||
State(state): State<AppState>,
|
||||
axum::extract::Path(id): axum::extract::Path<String>,
|
||||
|
@ -60,12 +69,7 @@ async fn remaining(
|
|||
let records = state.records.lock().await;
|
||||
if let Some(record) = records.get(&id) {
|
||||
let downloads_remaining = record.downloads_remaining();
|
||||
let plural = if downloads_remaining > 1 { "s" } else { "" };
|
||||
let out = format!(
|
||||
"You have {} download{} remaining!",
|
||||
downloads_remaining, plural
|
||||
);
|
||||
Html(out)
|
||||
Html(get_remaining_text(downloads_remaining))
|
||||
} else {
|
||||
Html("?".to_string())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use leptos::{component, view, IntoView};
|
||||
|
||||
use crate::link::get_remaining_text;
|
||||
use crate::state::UploadRecord;
|
||||
use crate::HtmxPage;
|
||||
|
||||
|
@ -19,7 +20,6 @@ pub fn DownloadLinkPage(id: String, record: UploadRecord) -> impl IntoView {
|
|||
#[component]
|
||||
pub fn LinkView(id: String, record: UploadRecord) -> impl IntoView {
|
||||
let downloads_remaining = record.max_downloads - record.downloads;
|
||||
let plural = if downloads_remaining > 1 { "s" } else { "" };
|
||||
view! {
|
||||
<div class="column-container">
|
||||
<div class="link-wrapper">
|
||||
|
@ -33,11 +33,7 @@ pub fn LinkView(id: String, record: UploadRecord) -> impl IntoView {
|
|||
hx-get="/link/{id}/remaining"
|
||||
hx-trigger="click from:#link delay:0.2s, every 10s"
|
||||
>
|
||||
You have
|
||||
{record.downloads_remaining()}
|
||||
download
|
||||
{plural}
|
||||
remaining!
|
||||
{get_remaining_text(downloads_remaining)}
|
||||
</div>
|
||||
<button class="return-button" onclick="clipboard()">
|
||||
Copy to Clipboard
|
||||
|
|
Loading…
Reference in New Issue