feat(files): page preview for PDF and Office attachments like Teams
- Graph thumbnail of the shared file below the name row, top of the page shown - cards without a thumbnail stay compact Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -28,6 +28,7 @@ const SAVE_BUTTON_SIZE: f32 = 28.;
28
28
const SAVE_BUTTON_RADIUS: f32 = 6.;
29
29
const SAVE_PROGRESS_HEIGHT: f32 = 2.;
30
30
const FILE_PREVIEW_HEIGHT: f32 = FILE_CARD_WIDTH * 9. / 16.;
31
const PORTRAIT_PAGE_RATIO: f32 = 1.414;
31
32
const PLAY_BUTTON_SIZE: f32 = 40.;
32
33
const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
33
34
const LOCAL_IMAGE_SUFFIX: &str = "/$value";
@@ -259,8 +260,11 @@ fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stat
259
260
.overflow_hidden()
260
261
.bg(theme::code_surface());
261
262
let frame = match image {
263
Some(path) if card.kind.is_document() && card.kind != FileKind::PowerPoint => frame
264
.bg(theme::white())
265
.child(img(path).w_full().h(px(FILE_CARD_WIDTH * PORTRAIT_PAGE_RATIO)).object_fit(ObjectFit::Cover)),
262
266
Some(path) => frame.child(img(path).size_full().object_fit(match card.kind {
263
FileKind::Video => ObjectFit::Cover,
267
FileKind::Video | FileKind::PowerPoint => ObjectFit::Cover,
264
268
_ => ObjectFit::Contain,
265
269
})),
266
270
None => frame,
@@ -350,8 +354,13 @@ fn file_view(
350
354
.bg(theme::surface())
351
355
.cursor_pointer()
352
356
.hover(|card| card.bg(theme::row_hover()))
353
.children(preview)
354
.child(row)
357
.map(|card_view| {
358
if card.kind.is_document() {
359
card_view.child(row).children(preview)
360
} else {
361
card_view.children(preview).child(row)
362
}
363
})
355
364
.when_some(progress, |card, fraction| {
356
365
card.child(
357
366
div()
@@ -28,6 +28,7 @@ const SAVE_BUTTON_SIZE: f32 = 28.;28
const SAVE_BUTTON_RADIUS: f32 = 6.;28
const SAVE_BUTTON_RADIUS: f32 = 6.;29
const SAVE_PROGRESS_HEIGHT: f32 = 2.;29
const SAVE_PROGRESS_HEIGHT: f32 = 2.;30
const FILE_PREVIEW_HEIGHT: f32 = FILE_CARD_WIDTH * 9. / 16.;30
const FILE_PREVIEW_HEIGHT: f32 = FILE_CARD_WIDTH * 9. / 16.;31
const PORTRAIT_PAGE_RATIO: f32 = 1.414;31
const PLAY_BUTTON_SIZE: f32 = 40.;32
const PLAY_BUTTON_SIZE: f32 = 40.;32
const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";33
const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";33
const LOCAL_IMAGE_SUFFIX: &str = "/$value";34
const LOCAL_IMAGE_SUFFIX: &str = "/$value";@@ -259,8 +260,11 @@ fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stat259
.overflow_hidden()260
.overflow_hidden()260
.bg(theme::code_surface());261
.bg(theme::code_surface());261
let frame = match image {262
let frame = match image {263
Some(path) if card.kind.is_document() && card.kind != FileKind::PowerPoint => frame264
.bg(theme::white())265
.child(img(path).w_full().h(px(FILE_CARD_WIDTH * PORTRAIT_PAGE_RATIO)).object_fit(ObjectFit::Cover)),262
Some(path) => frame.child(img(path).size_full().object_fit(match card.kind {266
Some(path) => frame.child(img(path).size_full().object_fit(match card.kind {263
FileKind::Video => ObjectFit::Cover,267
FileKind::Video | FileKind::PowerPoint => ObjectFit::Cover,264
_ => ObjectFit::Contain,268
_ => ObjectFit::Contain,265
})),269
})),266
None => frame,270
None => frame,@@ -350,8 +354,13 @@ fn file_view(350
.bg(theme::surface())354
.bg(theme::surface())351
.cursor_pointer()355
.cursor_pointer()352
.hover(|card| card.bg(theme::row_hover()))356
.hover(|card| card.bg(theme::row_hover()))353
.children(preview)357
.map(|card_view| {354
.child(row)358
if card.kind.is_document() {359
card_view.child(row).children(preview)360
} else {361
card_view.children(preview).child(row)362
}363
})355
.when_some(progress, |card, fraction| {364
.when_some(progress, |card, fraction| {356
card.child(365
card.child(357
div()366
div()@@ -55,6 +55,10 @@ pub enum FileKind {
55
55
}
56
56
57
57
impl FileKind {
58
pub fn is_document(self) -> bool {
59
matches!(self, FileKind::Word | FileKind::Excel | FileKind::PowerPoint | FileKind::Pdf)
60
}
61
58
62
pub fn from_name(name: &str) -> FileKind {
59
63
let Some((_, extension)) = name.rsplit_once('.') else {
60
64
return FileKind::Other;
@@ -421,7 +425,7 @@ pub struct FileCard {
421
425
422
426
impl FileCard {
423
427
pub fn preview(&self) -> Option<ImageRef> {
424
if !matches!(self.kind, FileKind::Image | FileKind::Video) {
428
if !(matches!(self.kind, FileKind::Image | FileKind::Video) || self.kind.is_document()) {
425
429
return None;
426
430
}
427
431
Some(ImageRef {
@@ -1139,7 +1143,9 @@ mod tests {
1139
1143
assert!(preview.url.starts_with("https://graph.microsoft.com/v1.0/shares/u!"));
1140
1144
assert!(preview.url.ends_with("/driveItem/thumbnails/0/large/content"));
1141
1145
assert!(card("shot.PNG", sharepoint).preview().is_some());
1142
assert_eq!(card("plan.docx", sharepoint).preview(), None);
1146
assert!(card("plan.docx", sharepoint).preview().is_some());
1147
assert!(card("report.pdf", sharepoint).preview().is_some());
1148
assert_eq!(card("bundle.zip", sharepoint).preview(), None);
1143
1149
assert_eq!(card("clip.mov", "https://example.com/clip.mov").preview(), None);
1144
1150
}
1145
1151
@@ -55,6 +55,10 @@ pub enum FileKind {55
}55
}56
56
57
impl FileKind {57
impl FileKind {58
pub fn is_document(self) -> bool {59
matches!(self, FileKind::Word | FileKind::Excel | FileKind::PowerPoint | FileKind::Pdf)60
}61
58
pub fn from_name(name: &str) -> FileKind {62
pub fn from_name(name: &str) -> FileKind {59
let Some((_, extension)) = name.rsplit_once('.') else {63
let Some((_, extension)) = name.rsplit_once('.') else {60
return FileKind::Other;64
return FileKind::Other;@@ -421,7 +425,7 @@ pub struct FileCard {421
425
422
impl FileCard {426
impl FileCard {423
pub fn preview(&self) -> Option<ImageRef> {427
pub fn preview(&self) -> Option<ImageRef> {424
if !matches!(self.kind, FileKind::Image | FileKind::Video) {428
if !(matches!(self.kind, FileKind::Image | FileKind::Video) || self.kind.is_document()) {425
return None;429
return None;426
}430
}427
Some(ImageRef {431
Some(ImageRef {@@ -1139,7 +1143,9 @@ mod tests {1139
assert!(preview.url.starts_with("https://graph.microsoft.com/v1.0/shares/u!"));1143
assert!(preview.url.starts_with("https://graph.microsoft.com/v1.0/shares/u!"));1140
assert!(preview.url.ends_with("/driveItem/thumbnails/0/large/content"));1144
assert!(preview.url.ends_with("/driveItem/thumbnails/0/large/content"));1141
assert!(card("shot.PNG", sharepoint).preview().is_some());1145
assert!(card("shot.PNG", sharepoint).preview().is_some());1142
assert_eq!(card("plan.docx", sharepoint).preview(), None);1146
assert!(card("plan.docx", sharepoint).preview().is_some());1147
assert!(card("report.pdf", sharepoint).preview().is_some());1148
assert_eq!(card("bundle.zip", sharepoint).preview(), None);1143
assert_eq!(card("clip.mov", "https://example.com/clip.mov").preview(), None);1149
assert_eq!(card("clip.mov", "https://example.com/clip.mov").preview(), None);1144
}1150
}1145
1151