-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reactive file identification (#2396)
* yes * Explain mysterious if * Use id alias just for consistency reasons * yes * Rust fmt * fix ts --------- Co-authored-by: Ericson "Fogo" Soares <[email protected]> Co-authored-by: Utku Bakir <[email protected]>
- Loading branch information
1 parent
64bbce3
commit ab46cff
Showing
16 changed files
with
96 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useEffect, useMemo } from 'react'; | ||
import { getExplorerItemData, useSelector, type ExplorerItem } from '@sd/client'; | ||
|
||
import { explorerStore, flattenThumbnailKey } from './store'; | ||
|
||
// This is where we intercept the state of the explorer item to determine if we should rerender | ||
// This hook is used inside every thumbnail in the explorer | ||
export function useExplorerItemData(explorerItem: ExplorerItem) { | ||
const newThumbnail = useSelector(explorerStore, (s) => { | ||
const thumbnailKey = | ||
explorerItem.type === 'Label' | ||
? // labels have .thumbnails, plural | ||
explorerItem.thumbnails?.[0] | ||
: // all other explorer items have .thumbnail singular | ||
'thumbnail' in explorerItem && explorerItem.thumbnail; | ||
|
||
return !!(thumbnailKey && s.newThumbnails.has(flattenThumbnailKey(thumbnailKey))); | ||
}); | ||
|
||
return useMemo(() => { | ||
const itemData = getExplorerItemData(explorerItem); | ||
|
||
if (!itemData.hasLocalThumbnail) { | ||
itemData.hasLocalThumbnail = newThumbnail; | ||
} | ||
|
||
return itemData; | ||
// whatever goes here, is what can cause an atomic re-render of an explorer item | ||
// this is used for when new thumbnails are generated, and files identified | ||
}, [explorerItem, newThumbnail]); | ||
} | ||
|
||
export type ExplorerItemData = ReturnType<typeof useExplorerItemData>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters