Skip to content

Commit 367b50c

Browse files
committed
unmemoize foldertree & main library
1 parent 26fbe53 commit 367b50c

1 file changed

Lines changed: 124 additions & 176 deletions

File tree

src/App.tsx

Lines changed: 124 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ function App() {
19131913
? currentPins.filter((p) => p !== path)
19141914
: [...currentPins, path].sort((a, b) => a.localeCompare(b));
19151915

1916-
if (!isPinned && path === currentFolderPath) {
1916+
if (!isPinned) {
19171917
handleActiveTreeSectionChange('pinned');
19181918
}
19191919

@@ -1930,7 +1930,7 @@ function App() {
19301930
console.error('Failed to refresh pinned folders:', err);
19311931
}
19321932
},
1933-
[appSettings, currentFolderPath, expandedFolders, handleSettingsChange],
1933+
[appSettings, expandedFolders, handleSettingsChange],
19341934
);
19351935

19361936
const handleActiveTreeSectionChange = (section: string | null) => {
@@ -4774,181 +4774,129 @@ function App() {
47744774
showContextMenu(event.clientX, event.clientY, options);
47754775
};
47764776

4777-
const memoizedFolderTree = useMemo(
4778-
() =>
4779-
rootPath && (
4780-
<div
4781-
className={clsx(
4782-
'flex h-full overflow-hidden shrink-0',
4783-
!isResizing && !isInstantTransition && 'transition-all duration-300 ease-in-out',
4784-
)}
4785-
style={{
4786-
maxWidth: isFullScreen ? '0px' : '1000px',
4787-
opacity: isFullScreen ? 0 : 1,
4788-
}}
4789-
>
4790-
<FolderTree
4791-
expandedFolders={expandedFolders}
4792-
isLoading={isTreeLoading}
4793-
isResizing={isResizing}
4794-
isVisible={uiVisibility.folderTree}
4795-
onContextMenu={handleFolderTreeContextMenu}
4796-
onFolderSelect={(path) => handleSelectSubfolder(path, false)}
4797-
onToggleFolder={handleToggleFolder}
4798-
selectedPath={currentFolderPath}
4799-
setIsVisible={(value: boolean) => setUiVisibility((prev: UiVisibility) => ({ ...prev, folderTree: value }))}
4800-
style={{ width: uiVisibility.folderTree ? `${leftPanelWidth}px` : '32px' }}
4801-
tree={folderTree}
4802-
pinnedFolderTrees={pinnedFolderTrees}
4803-
pinnedFolders={pinnedFolders}
4804-
activeSection={activeTreeSection}
4805-
onActiveSectionChange={handleActiveTreeSectionChange}
4806-
showImageCounts={appSettings?.enableFolderImageCounts ?? false}
4807-
isInstantTransition={isInstantTransition}
4777+
const renderFolderTree = () => {
4778+
if (!rootPath) return null;
4779+
4780+
return (
4781+
<div
4782+
className={clsx(
4783+
'flex h-full overflow-hidden shrink-0',
4784+
!isResizing && !isInstantTransition && 'transition-all duration-300 ease-in-out',
4785+
)}
4786+
style={{
4787+
maxWidth: isFullScreen ? '0px' : '1000px',
4788+
opacity: isFullScreen ? 0 : 1,
4789+
}}
4790+
>
4791+
<FolderTree
4792+
expandedFolders={expandedFolders}
4793+
isLoading={isTreeLoading}
4794+
isResizing={isResizing}
4795+
isVisible={uiVisibility.folderTree}
4796+
onContextMenu={handleFolderTreeContextMenu}
4797+
onFolderSelect={(path) => handleSelectSubfolder(path, false)}
4798+
onToggleFolder={handleToggleFolder}
4799+
selectedPath={currentFolderPath}
4800+
setIsVisible={(value: boolean) => setUiVisibility((prev: UiVisibility) => ({ ...prev, folderTree: value }))}
4801+
style={{ width: uiVisibility.folderTree ? `${leftPanelWidth}px` : '32px' }}
4802+
tree={folderTree}
4803+
pinnedFolderTrees={pinnedFolderTrees}
4804+
pinnedFolders={pinnedFolders}
4805+
activeSection={activeTreeSection}
4806+
onActiveSectionChange={handleActiveTreeSectionChange}
4807+
showImageCounts={appSettings?.enableFolderImageCounts ?? false}
4808+
isInstantTransition={isInstantTransition}
4809+
/>
4810+
<Resizer
4811+
direction={Orientation.Vertical}
4812+
onMouseDown={createResizeHandler(setLeftPanelWidth, leftPanelWidth)}
4813+
/>
4814+
</div>
4815+
);
4816+
};
4817+
4818+
const renderLibraryView = () => (
4819+
<div className="flex flex-row grow h-full min-h-0">
4820+
<div className="flex-1 flex flex-col min-w-0 gap-2">
4821+
{activeView === 'community' ? (
4822+
<CommunityPage
4823+
onBackToLibrary={() => setActiveView('library')}
4824+
supportedTypes={supportedTypes}
4825+
imageList={sortedImageList}
4826+
currentFolderPath={currentFolderPath}
48084827
/>
4809-
<Resizer
4810-
direction={Orientation.Vertical}
4811-
onMouseDown={createResizeHandler(setLeftPanelWidth, leftPanelWidth)}
4828+
) : (
4829+
<MainLibrary
4830+
activePath={libraryActivePath}
4831+
aiModelDownloadStatus={aiModelDownloadStatus}
4832+
appSettings={appSettings}
4833+
currentFolderPath={currentFolderPath}
4834+
filterCriteria={filterCriteria}
4835+
imageList={sortedImageList}
4836+
imageRatings={imageRatings}
4837+
importState={importState}
4838+
indexingProgress={indexingProgress}
4839+
isIndexing={isIndexing}
4840+
isThumbnailsLoading={isThumbnailsLoading}
4841+
isLoading={isViewLoading}
4842+
isTreeLoading={isTreeLoading}
4843+
libraryScrollTop={libraryScrollTop}
4844+
libraryViewMode={libraryViewMode}
4845+
multiSelectedPaths={multiSelectedPaths}
4846+
onClearSelection={handleClearSelection}
4847+
onContextMenu={handleThumbnailContextMenu}
4848+
onContinueSession={handleContinueSession}
4849+
onEmptyAreaContextMenu={handleMainLibraryContextMenu}
4850+
onGoHome={handleGoHome}
4851+
onImageClick={handleLibraryImageSingleClick}
4852+
onImageDoubleClick={handleImageSelect}
4853+
onLibraryRefresh={handleLibraryRefresh}
4854+
onOpenFolder={handleOpenFolder}
4855+
onSettingsChange={handleSettingsChange}
4856+
onThumbnailAspectRatioChange={setThumbnailAspectRatio}
4857+
onThumbnailSizeChange={setThumbnailSize}
4858+
onRequestThumbnails={requestThumbnails}
4859+
rootPath={rootPath}
4860+
searchCriteria={searchCriteria}
4861+
setFilterCriteria={setFilterCriteria}
4862+
setLibraryScrollTop={setLibraryScrollTop}
4863+
setLibraryViewMode={setLibraryViewMode}
4864+
setSearchCriteria={setSearchCriteria}
4865+
setSortCriteria={setSortCriteria}
4866+
sortCriteria={sortCriteria}
4867+
theme={theme}
4868+
thumbnailAspectRatio={thumbnailAspectRatio}
4869+
thumbnails={thumbnails}
4870+
thumbnailSize={thumbnailSize}
4871+
onNavigateToCommunity={() => setActiveView('community')}
4872+
listColumnWidths={listColumnWidths}
4873+
setListColumnWidths={setListColumnWidths}
48124874
/>
4813-
</div>
4814-
),
4815-
[
4816-
rootPath,
4817-
expandedFolders,
4818-
isTreeLoading,
4819-
isResizing,
4820-
handleSelectSubfolder,
4821-
uiVisibility.folderTree,
4822-
currentFolderPath,
4823-
leftPanelWidth,
4824-
folderTree,
4825-
pinnedFolderTrees,
4826-
pinnedFolders,
4827-
activeTreeSection,
4828-
copiedFilePaths,
4829-
isFullScreen,
4830-
isInstantTransition,
4831-
appSettings?.enableFolderImageCounts,
4832-
],
4833-
);
4834-
4835-
const memoizedLibraryView = useMemo(
4836-
() => (
4837-
<div className="flex flex-row grow h-full min-h-0">
4838-
<div className="flex-1 flex flex-col min-w-0 gap-2">
4839-
{activeView === 'community' ? (
4840-
<CommunityPage
4841-
onBackToLibrary={() => setActiveView('library')}
4842-
supportedTypes={supportedTypes}
4843-
imageList={sortedImageList}
4844-
currentFolderPath={currentFolderPath}
4845-
/>
4846-
) : (
4847-
<MainLibrary
4848-
activePath={libraryActivePath}
4849-
aiModelDownloadStatus={aiModelDownloadStatus}
4850-
appSettings={appSettings}
4851-
currentFolderPath={currentFolderPath}
4852-
filterCriteria={filterCriteria}
4853-
imageList={sortedImageList}
4854-
imageRatings={imageRatings}
4855-
importState={importState}
4856-
indexingProgress={indexingProgress}
4857-
isIndexing={isIndexing}
4858-
isThumbnailsLoading={isThumbnailsLoading}
4859-
isLoading={isViewLoading}
4860-
isTreeLoading={isTreeLoading}
4861-
libraryScrollTop={libraryScrollTop}
4862-
libraryViewMode={libraryViewMode}
4863-
multiSelectedPaths={multiSelectedPaths}
4864-
onClearSelection={handleClearSelection}
4865-
onContextMenu={handleThumbnailContextMenu}
4866-
onContinueSession={handleContinueSession}
4867-
onEmptyAreaContextMenu={handleMainLibraryContextMenu}
4868-
onGoHome={handleGoHome}
4869-
onImageClick={handleLibraryImageSingleClick}
4870-
onImageDoubleClick={handleImageSelect}
4871-
onLibraryRefresh={handleLibraryRefresh}
4872-
onOpenFolder={handleOpenFolder}
4873-
onSettingsChange={handleSettingsChange}
4874-
onThumbnailAspectRatioChange={setThumbnailAspectRatio}
4875-
onThumbnailSizeChange={setThumbnailSize}
4876-
onRequestThumbnails={requestThumbnails}
4877-
rootPath={rootPath}
4878-
searchCriteria={searchCriteria}
4879-
setFilterCriteria={setFilterCriteria}
4880-
setLibraryScrollTop={setLibraryScrollTop}
4881-
setLibraryViewMode={setLibraryViewMode}
4882-
setSearchCriteria={setSearchCriteria}
4883-
setSortCriteria={setSortCriteria}
4884-
sortCriteria={sortCriteria}
4885-
theme={theme}
4886-
thumbnailAspectRatio={thumbnailAspectRatio}
4887-
thumbnails={thumbnails}
4888-
thumbnailSize={thumbnailSize}
4889-
onNavigateToCommunity={() => setActiveView('community')}
4890-
listColumnWidths={listColumnWidths}
4891-
setListColumnWidths={setListColumnWidths}
4892-
/>
4893-
)}
4894-
{rootPath && (
4895-
<BottomBar
4896-
isCopied={isCopied}
4897-
isCopyDisabled={multiSelectedPaths.length !== 1}
4898-
isExportDisabled={multiSelectedPaths.length === 0}
4899-
isLibraryView={true}
4900-
isPasted={isPasted}
4901-
isPasteDisabled={copiedAdjustments === null || multiSelectedPaths.length === 0}
4902-
isRatingDisabled={multiSelectedPaths.length === 0}
4903-
isResetDisabled={multiSelectedPaths.length === 0}
4904-
multiSelectedPaths={multiSelectedPaths}
4905-
onCopy={handleCopyAdjustments}
4906-
onExportClick={() => setIsLibraryExportPanelVisible((prev) => !prev)}
4907-
onOpenCopyPasteSettings={() => setIsCopyPasteSettingsModalOpen(true)}
4908-
onPaste={() => handlePasteAdjustments()}
4909-
onRate={handleRate}
4910-
onReset={() => handleResetAdjustments()}
4911-
rating={libraryActiveAdjustments.rating || 0}
4912-
thumbnailAspectRatio={thumbnailAspectRatio}
4913-
totalImages={imageList.length}
4914-
/>
4915-
)}
4916-
</div>
4875+
)}
4876+
{rootPath && (
4877+
<BottomBar
4878+
isCopied={isCopied}
4879+
isCopyDisabled={multiSelectedPaths.length !== 1}
4880+
isExportDisabled={multiSelectedPaths.length === 0}
4881+
isLibraryView={true}
4882+
isPasted={isPasted}
4883+
isPasteDisabled={copiedAdjustments === null || multiSelectedPaths.length === 0}
4884+
isRatingDisabled={multiSelectedPaths.length === 0}
4885+
isResetDisabled={multiSelectedPaths.length === 0}
4886+
multiSelectedPaths={multiSelectedPaths}
4887+
onCopy={handleCopyAdjustments}
4888+
onExportClick={() => setIsLibraryExportPanelVisible((prev) => !prev)}
4889+
onOpenCopyPasteSettings={() => setIsCopyPasteSettingsModalOpen(true)}
4890+
onPaste={() => handlePasteAdjustments()}
4891+
onRate={handleRate}
4892+
onReset={() => handleResetAdjustments()}
4893+
rating={libraryActiveAdjustments.rating || 0}
4894+
thumbnailAspectRatio={thumbnailAspectRatio}
4895+
totalImages={imageList.length}
4896+
/>
4897+
)}
49174898
</div>
4918-
),
4919-
[
4920-
activeView,
4921-
sortedImageList,
4922-
currentFolderPath,
4923-
libraryActivePath,
4924-
aiModelDownloadStatus,
4925-
appSettings,
4926-
filterCriteria,
4927-
imageRatings,
4928-
importState,
4929-
indexingProgress,
4930-
isIndexing,
4931-
isThumbnailsLoading,
4932-
isViewLoading,
4933-
isTreeLoading,
4934-
libraryScrollTop,
4935-
libraryViewMode,
4936-
multiSelectedPaths,
4937-
rootPath,
4938-
searchCriteria,
4939-
sortCriteria,
4940-
theme,
4941-
thumbnailAspectRatio,
4942-
thumbnails,
4943-
thumbnailSize,
4944-
isCopied,
4945-
isPasted,
4946-
copiedAdjustments,
4947-
libraryActiveAdjustments,
4948-
supportedTypes,
4949-
copiedFilePaths,
4950-
listColumnWidths,
4951-
],
4899+
</div>
49524900
);
49534901

49544902
const renderMainView = () => {
@@ -5260,7 +5208,7 @@ function App() {
52605208
</div>
52615209
);
52625210
}
5263-
return memoizedLibraryView;
5211+
return renderLibraryView();
52645212
};
52655213

52665214
const renderContent = () => {
@@ -5294,7 +5242,7 @@ function App() {
52945242
)}
52955243
>
52965244
<div className="flex flex-row grow h-full min-h-0">
5297-
{memoizedFolderTree}
5245+
{renderFolderTree()}
52985246
<div className="flex-1 flex flex-col min-w-0">{renderContent()}</div>
52995247
{!selectedImage && isLibraryExportPanelVisible && (
53005248
<Resizer

0 commit comments

Comments
 (0)