//! File previews: browser-native media (image/PDF/video/audio), full page. //! Text files open in the editor instead. use api_types::FileKind; use leptos::prelude::*; use crate::api; /// What kind of preview a file gets. #[derive(Clone, Copy, PartialEq, Eq)] pub enum PreviewKind { Image, Pdf, Video, Audio, } /// Which viewer opens this entry, from the server's sniffed [`FileKind`]. /// `None` = nothing we can preview here: text goes to the editor, archives /// and binaries get the "no preview" view. pub fn preview_kind(kind: FileKind) -> Option { match kind { FileKind::Image => Some(PreviewKind::Image), FileKind::Pdf => Some(PreviewKind::Pdf), FileKind::Video => Some(PreviewKind::Video), FileKind::Audio => Some(PreviewKind::Audio), FileKind::Dir | FileKind::Archive | FileKind::Binary | FileKind::Text => None, } } /// A file the user wants to preview. #[derive(Clone)] pub struct PreviewTarget { pub root_id: i64, /// Path relative to the root (e.g. "docs/a.txt"). pub path: String, /// Display name (used for the title + language detection). pub name: String, } /// The full-page media preview (closing lives in the top bar). #[component] pub fn Preview(target: PreviewTarget, kind: PreviewKind) -> impl IntoView { let t = target; let url = api::preview_url(t.root_id, &t.path); view! {
{move || match kind { PreviewKind::Image => { view! { t.name.clone()/ } .into_view() .into_any() } PreviewKind::Pdf => { view! {