Skip to content

Commit

Permalink
Fix thumbnail generation reactivity (#2392)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
jamiepine committed Apr 25, 2024
1 parent 73f521a commit b1ffbee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
9 changes: 6 additions & 3 deletions core/src/api/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ pub type ThumbnailKey = Vec<String>;
pub enum ExplorerItem {
Path {
thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool, // this is important
item: file_path_with_object::Data,
},
Object {
thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool,
item: object_with_file_paths::Data,
},
Location {
item: location::Data,
},
NonIndexedPath {
thumbnail: Option<ThumbnailKey>,
has_created_thumbnail: bool,
item: NonIndexedPathItem,
},
Location {
item: location::Data,
},
SpacedropPeer {
item: PeerMetadata,
},
Expand Down
11 changes: 7 additions & 4 deletions core/src/api/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ pub fn mount() -> AlphaRouter<Ctx> {
} else {
ExplorerItem::NonIndexedPath {
thumbnail,
// TODO: Actually check fs for existence of thumb
has_created_thumbnail: false,
item,
}
});
Expand Down Expand Up @@ -321,7 +323,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
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
Expand All @@ -334,8 +336,9 @@ pub fn mount() -> AlphaRouter<Ctx> {
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,
})
}
Expand Down Expand Up @@ -440,7 +443,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
.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,
Expand All @@ -454,8 +457,8 @@ pub fn mount() -> AlphaRouter<Ctx> {

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,
});
}
Expand Down
10 changes: 6 additions & 4 deletions interface/app/$libraryId/Explorer/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/lib/explorerItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b1ffbee

Please sign in to comment.