file manager
git clone https://git.lucas.co/cce-files.git
src/pages/preview.rs (1.7K)
1 use std::path::PathBuf;
2
3 use crate::preview_pane::PreviewPane;
4
5 // ── Data ────────────────────────────────────────────────────────────
6
7 #[derive(Debug, Clone)]
8 pub enum PreviewMessage {
9 SetPath { path: PathBuf },
10 Clear,
11 PreviewLoaded { path: PathBuf, data: crate::services::fs::PreviewData },
12 }
13
14 // ── Update ──────────────────────────────────────────────────────────
15
16 pub fn update(state: &mut PreviewPane, msg: PreviewMessage) {
17 match msg {
18 PreviewMessage::Clear => {
19 // Free the texture BEFORE the wholesale replace — a plain
20 // Default::default() swap would leak the uploaded id.
21 state.set_image(None);
22 *state = PreviewPane::default();
23 }
24 PreviewMessage::SetPath { path: _ } => {
25 // Deprecated direct SetPath, as we now load previews via the FsService.
26 }
27 PreviewMessage::PreviewLoaded { path, data } => {
28 state.path_display = path.to_string_lossy().to_string();
29 state.path = Some(path);
30 state.name = data.name;
31 state.is_dir = data.is_dir;
32 state.size = data.size;
33 state.permissions = data.permissions;
34 state.modified = data.modified;
35 state.file_type = data.file_type;
36 state.target = data.target;
37 state.content_preview = data.content_preview;
38 state.set_image(data.image_preview.map(|img| (img.pixels, img.width, img.height)));
39 state.reset_scroll();
40 }
41 }
42 }