Fix thumbnail generation reactivity (#2392)

fix
This commit is contained in:
Jamie Pine 2024-04-25 09:14:43 -07:00 committed by GitHub
parent 73f521a3b8
commit b1ffbee9b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 14 deletions

View file

@ -40,19 +40,22 @@ pub type ThumbnailKey = Vec<String>;
pub enum ExplorerItem { pub enum ExplorerItem {
Path { Path {
thumbnail: Option<ThumbnailKey>, thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool, // this is important
item: file_path_with_object::Data, item: file_path_with_object::Data,
}, },
Object { Object {
thumbnail: Option<ThumbnailKey>, thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool,
item: object_with_file_paths::Data, item: object_with_file_paths::Data,
}, },
Location {
item: location::Data,
},
NonIndexedPath { NonIndexedPath {
thumbnail: Option<ThumbnailKey>, thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool,
item: NonIndexedPathItem, item: NonIndexedPathItem,
}, },
Location {
item: location::Data,
},
SpacedropPeer { SpacedropPeer {
item: PeerMetadata, item: PeerMetadata,
}, },

View file

@ -228,6 +228,8 @@ pub fn mount() -> AlphaRouter<Ctx> {
} else { } else {
ExplorerItem::NonIndexedPath { ExplorerItem::NonIndexedPath {
thumbnail, thumbnail,
// TODO: Actually check fs for existence of thumb
has_created_thumbnail: false,
item, item,
} }
}); });
@ -321,7 +323,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
let mut items = Vec::with_capacity(file_paths.len()); let mut items = Vec::with_capacity(file_paths.len());
for file_path in file_paths { 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 library
.thumbnail_exists(&node, cas_id) .thumbnail_exists(&node, cas_id)
.await .await
@ -334,8 +336,9 @@ pub fn mount() -> AlphaRouter<Ctx> {
thumbnail: file_path thumbnail: file_path
.cas_id .cas_id
.as_ref() .as_ref()
.filter(|_| thumbnail_exists_locally) // .filter(|_| thumbnail_exists_locally)
.map(|i| get_indexed_thumb_key(i, library.id)), .map(|i| get_indexed_thumb_key(i, library.id)),
has_created_thumbnail,
item: file_path, item: file_path,
}) })
} }
@ -440,7 +443,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
.map(|fp| fp.cas_id.as_ref()) .map(|fp| fp.cas_id.as_ref())
.find_map(|c| c); .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| { library.thumbnail_exists(&node, cas_id).await.map_err(|e| {
rspc::Error::with_cause( rspc::Error::with_cause(
ErrorCode::InternalServerError, ErrorCode::InternalServerError,
@ -454,8 +457,8 @@ pub fn mount() -> AlphaRouter<Ctx> {
items.push(ExplorerItem::Object { items.push(ExplorerItem::Object {
thumbnail: cas_id thumbnail: cas_id
.filter(|_| thumbnail_exists_locally)
.map(|cas_id| get_indexed_thumb_key(cas_id, library.id)), .map(|cas_id| get_indexed_thumb_key(cas_id, library.id)),
has_created_thumbnail,
item: object, item: object,
}); });
} }

View file

@ -11,12 +11,14 @@ export function useExplorerSearchParams() {
export function useExplorerItemData(explorerItem: ExplorerItem) { export function useExplorerItemData(explorerItem: ExplorerItem) {
const newThumbnail = useSelector(explorerStore, (s) => { const newThumbnail = useSelector(explorerStore, (s) => {
const firstThumbnail = const thumbnailKey =
explorerItem.type === 'Label' explorerItem.type === 'Label'
? explorerItem.thumbnails?.[0] ? // labels have .thumbnails, plural
: 'thumbnail' in explorerItem && explorerItem.thumbnail; 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(() => { return useMemo(() => {

View file

@ -249,7 +249,7 @@ export type EphemeralRenameMany = { from_pattern: FromPattern; to_pattern: strin
export type EphemeralRenameOne = { from_path: string; to: string } 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" export type ExplorerLayout = "grid" | "list" | "media"

View file

@ -58,7 +58,7 @@ export function getExplorerItemData(data?: ExplorerItem | null): ItemData {
itemData.thumbnailKeys = [data.thumbnail]; itemData.thumbnailKeys = [data.thumbnail];
} }
itemData.hasLocalThumbnail = !!data.thumbnail; itemData.hasLocalThumbnail = data.has_created_thumbnail;
// handle file path // handle file path
const filePath = getItemFilePath(data); const filePath = getItemFilePath(data);
if (filePath) { if (filePath) {
@ -89,7 +89,7 @@ export function getExplorerItemData(data?: ExplorerItem | null): ItemData {
itemData.thumbnailKeys = [data.thumbnail]; itemData.thumbnailKeys = [data.thumbnail];
} }
itemData.hasLocalThumbnail = !!data.thumbnail; itemData.hasLocalThumbnail = data.has_created_thumbnail;
// handle file path // handle file path
const filePath = getItemFilePath(data); const filePath = getItemFilePath(data);
if (filePath) { if (filePath) {