From b1ffbee9b14b60dd82cf90d4c1f453d88a33ea41 Mon Sep 17 00:00:00 2001 From: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:14:43 -0700 Subject: [PATCH] Fix thumbnail generation reactivity (#2392) fix --- core/src/api/locations.rs | 9 ++++++--- core/src/api/search/mod.rs | 11 +++++++---- interface/app/$libraryId/Explorer/util.ts | 10 ++++++---- packages/client/src/core.ts | 2 +- packages/client/src/lib/explorerItem.ts | 4 ++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core/src/api/locations.rs b/core/src/api/locations.rs index cdd30762d..0c8135536 100644 --- a/core/src/api/locations.rs +++ b/core/src/api/locations.rs @@ -40,19 +40,22 @@ pub type ThumbnailKey = Vec; pub enum ExplorerItem { Path { thumbnail: Option, + has_created_thumbnail: bool, // this is important item: file_path_with_object::Data, }, Object { thumbnail: Option, + has_created_thumbnail: bool, item: object_with_file_paths::Data, }, - Location { - item: location::Data, - }, NonIndexedPath { thumbnail: Option, + has_created_thumbnail: bool, item: NonIndexedPathItem, }, + Location { + item: location::Data, + }, SpacedropPeer { item: PeerMetadata, }, diff --git a/core/src/api/search/mod.rs b/core/src/api/search/mod.rs index 2f90ea7d6..9eb1d8a82 100644 --- a/core/src/api/search/mod.rs +++ b/core/src/api/search/mod.rs @@ -228,6 +228,8 @@ pub fn mount() -> AlphaRouter { } else { ExplorerItem::NonIndexedPath { thumbnail, + // TODO: Actually check fs for existence of thumb + has_created_thumbnail: false, item, } }); @@ -321,7 +323,7 @@ pub fn mount() -> AlphaRouter { let mut items = Vec::with_capacity(file_paths.len()); for file_path in file_paths { - let thumbnail_exists_locally = if let Some(cas_id) = &file_path.cas_id { + let has_created_thumbnail = if let Some(cas_id) = &file_path.cas_id { library .thumbnail_exists(&node, cas_id) .await @@ -334,8 +336,9 @@ pub fn mount() -> AlphaRouter { thumbnail: file_path .cas_id .as_ref() - .filter(|_| thumbnail_exists_locally) + // .filter(|_| thumbnail_exists_locally) .map(|i| get_indexed_thumb_key(i, library.id)), + has_created_thumbnail, item: file_path, }) } @@ -440,7 +443,7 @@ pub fn mount() -> AlphaRouter { .map(|fp| fp.cas_id.as_ref()) .find_map(|c| c); - let thumbnail_exists_locally = if let Some(cas_id) = cas_id { + let has_created_thumbnail = if let Some(cas_id) = cas_id { library.thumbnail_exists(&node, cas_id).await.map_err(|e| { rspc::Error::with_cause( ErrorCode::InternalServerError, @@ -454,8 +457,8 @@ pub fn mount() -> AlphaRouter { items.push(ExplorerItem::Object { thumbnail: cas_id - .filter(|_| thumbnail_exists_locally) .map(|cas_id| get_indexed_thumb_key(cas_id, library.id)), + has_created_thumbnail, item: object, }); } diff --git a/interface/app/$libraryId/Explorer/util.ts b/interface/app/$libraryId/Explorer/util.ts index eeef7d99d..7b108cf37 100644 --- a/interface/app/$libraryId/Explorer/util.ts +++ b/interface/app/$libraryId/Explorer/util.ts @@ -11,12 +11,14 @@ export function useExplorerSearchParams() { export function useExplorerItemData(explorerItem: ExplorerItem) { const newThumbnail = useSelector(explorerStore, (s) => { - const firstThumbnail = + const thumbnailKey = explorerItem.type === 'Label' - ? explorerItem.thumbnails?.[0] - : 'thumbnail' in explorerItem && explorerItem.thumbnail; + ? // labels have .thumbnails, plural + explorerItem.thumbnails?.[0] + : // all other explorer items have .thumbnail singular + 'thumbnail' in explorerItem && explorerItem.thumbnail; - return !!(firstThumbnail && s.newThumbnails.has(flattenThumbnailKey(firstThumbnail))); + return !!(thumbnailKey && s.newThumbnails.has(flattenThumbnailKey(thumbnailKey))); }); return useMemo(() => { diff --git a/packages/client/src/core.ts b/packages/client/src/core.ts index c38ecdade..f9dcc3f02 100644 --- a/packages/client/src/core.ts +++ b/packages/client/src/core.ts @@ -249,7 +249,7 @@ export type EphemeralRenameMany = { from_pattern: FromPattern; to_pattern: strin export type EphemeralRenameOne = { from_path: string; to: string } -export type ExplorerItem = { type: "Path"; thumbnail: string[] | null; item: FilePathWithObject } | { type: "Object"; thumbnail: string[] | null; item: ObjectWithFilePaths } | { type: "Location"; item: Location } | { type: "NonIndexedPath"; thumbnail: string[] | null; item: NonIndexedPathItem } | { type: "SpacedropPeer"; item: PeerMetadata } | { type: "Label"; thumbnails: string[][]; item: LabelWithObjects } +export type ExplorerItem = { type: "Path"; thumbnail: string[] | null; has_created_thumbnail: boolean; item: FilePathWithObject } | { type: "Object"; thumbnail: string[] | null; has_created_thumbnail: boolean; item: ObjectWithFilePaths } | { type: "NonIndexedPath"; thumbnail: string[] | null; has_created_thumbnail: boolean; item: NonIndexedPathItem } | { type: "Location"; item: Location } | { type: "SpacedropPeer"; item: PeerMetadata } | { type: "Label"; thumbnails: string[][]; item: LabelWithObjects } export type ExplorerLayout = "grid" | "list" | "media" diff --git a/packages/client/src/lib/explorerItem.ts b/packages/client/src/lib/explorerItem.ts index ad93fea2a..ed3f682bf 100644 --- a/packages/client/src/lib/explorerItem.ts +++ b/packages/client/src/lib/explorerItem.ts @@ -58,7 +58,7 @@ export function getExplorerItemData(data?: ExplorerItem | null): ItemData { itemData.thumbnailKeys = [data.thumbnail]; } - itemData.hasLocalThumbnail = !!data.thumbnail; + itemData.hasLocalThumbnail = data.has_created_thumbnail; // handle file path const filePath = getItemFilePath(data); if (filePath) { @@ -89,7 +89,7 @@ export function getExplorerItemData(data?: ExplorerItem | null): ItemData { itemData.thumbnailKeys = [data.thumbnail]; } - itemData.hasLocalThumbnail = !!data.thumbnail; + itemData.hasLocalThumbnail = data.has_created_thumbnail; // handle file path const filePath = getItemFilePath(data); if (filePath) {