Render the name and the uploaded date for each file in the gallery

This commit is contained in:
Savanni D'Gerinel 2023-10-25 10:20:14 -04:00
parent e96b8087e2
commit ee348c29cb
2 changed files with 25 additions and 12 deletions

View File

@ -1,6 +1,6 @@
use crate::html::*; use crate::html::*;
use build_html::{self, Container, ContainerType, Html, HtmlContainer}; use build_html::{self, Container, ContainerType, Html, HtmlContainer};
use file_service::{FileHandle, FileId, ReadFileError}; use file_service::{FileHandle, FileInfo, ReadFileError};
pub fn auth(_message: Option<String>) -> build_html::HtmlPage { pub fn auth(_message: Option<String>) -> build_html::HtmlPage {
build_html::HtmlPage::new() build_html::HtmlPage::new()
@ -49,14 +49,7 @@ pub fn gallery(handles: Vec<Result<FileHandle, ReadFileError>>) -> build_html::H
let mut gallery = Container::new(ContainerType::Div).with_attributes([("class", "gallery")]); let mut gallery = Container::new(ContainerType::Div).with_attributes([("class", "gallery")]);
for handle in handles { for handle in handles {
let container = match handle { let container = match handle {
Ok(ref handle) => thumbnail(&handle.id).with_html( Ok(ref handle) => thumbnail(&handle.info),
Form::new()
.with_path(&format!("/{}", *handle.id))
.with_method("post")
.with_html(Input::new("hidden", "_method").with_value("delete"))
.with_html(Button::new("Delete")),
),
Err(err) => Container::new(ContainerType::Div) Err(err) => Container::new(ContainerType::Div)
.with_attributes(vec![("class", "file")]) .with_attributes(vec![("class", "file")])
.with_paragraph(format!("{:?}", err)), .with_paragraph(format!("{:?}", err)),
@ -88,15 +81,31 @@ pub fn upload_form() -> Form {
) )
} }
pub fn thumbnail(id: &FileId) -> Container { pub fn thumbnail(info: &FileInfo) -> Container {
Container::new(ContainerType::Div) Container::new(ContainerType::Div)
.with_attributes(vec![("class", "card thumbnail")]) .with_attributes(vec![("class", "card thumbnail")])
.with_html( .with_html(
Container::new(ContainerType::Div).with_link( Container::new(ContainerType::Div).with_link(
format!("/{}", **id), format!("/{}", *info.id),
Image::new(&format!("{}/tn", **id)) Image::new(&format!("{}/tn", *info.id))
.with_attributes([("class", "thumbnail__image")]) .with_attributes([("class", "thumbnail__image")])
.to_html_string(), .to_html_string(),
), ),
) )
.with_html(
Container::new(ContainerType::Div)
.with_html(
UnorderedList::new()
.with_attributes(vec![("class", "thumbnail__metadata")])
.with_html(info.name.clone())
.with_html(format!("{}", info.created.format("%Y-%m-%d"))),
)
.with_html(
Form::new()
.with_path(&format!("/{}", *info.id))
.with_method("post")
.with_html(Input::new("hidden", "_method").with_value("delete"))
.with_html(Button::new("Delete")),
),
)
} }

View File

@ -77,6 +77,10 @@ body {
border: none; border: none;
} }
.thumbnail__metadata {
list-style: none;
}
/* /*
[type="submit"] { [type="submit"] {
border-radius: 1em; border-radius: 1em;