use derive_where::derive_where;
use topcoat::{context::Cx, view::*};
use super::{Column, ColumnBase, ColumnWidth};
use crate::Lens;
#[derive_where(Clone, Debug)]
pub struct FileColumn<M> {
lens: Lens<M, String>,
base: ColumnBase,
}
impl<M> FileColumn<M>
where
M: toasty::schema::Model,
{
pub fn new(lens: Lens<M, String>) -> Self {
Self {
base: ColumnBase::new(lens.path(), ColumnWidth::Grow),
lens,
}
}
base_builders!();
}
impl<M> Column<M> for FileColumn<M>
where
M: toasty::schema::Model + Send + Sync + 'static,
{
base_column_methods!(binding);
fn text(&self, _cx: &Cx, row: &M) -> String {
self.lens.read(row).clone()
}
fn cell<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a> {
let path = self.lens.read(row);
if path.trim().is_empty() {
return crate::schema::value_cell(cx, path);
}
crate::schema::stored_upload(cx, path)
}
}