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