TagSpaces is an offline, open source, document manager with tagging support
fix load dir meta issue (#1986)
Stanimir0f67df77f1c2
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex f2cb70fb1..5a2518937 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -71,6 +71,7 @@ import MainSearchField from '-/components/MainSearchField';import SearchBox from '-/components/SearchBox';import useFirstRender from '-/utils/useFirstRender';import { useTranslation } from 'react-i18next';+import { SortedDirContextProvider } from '-/perspectives/grid-perspective/hooks/SortedDirContextProvider';const PREFIX = 'FolderContainer';@@ -111,7 +112,9 @@ const GridPerspective = React.lazy(() =>function GridPerspectiveAsync(props) {return (<React.Suspense fallback={<LoadingLazy />}>- <GridPerspective {...props} />+ <SortedDirContextProvider>+ <GridPerspective {...props} />+ </SortedDirContextProvider></React.Suspense>);}@@ -122,7 +125,9 @@ const ListPerspective = React.lazy(() =>function ListPerspectiveAsync(props) {return (<React.Suspense fallback={<LoadingLazy />}>- <ListPerspective {...props} />+ <SortedDirContextProvider>+ <ListPerspective {...props} />+ </SortedDirContextProvider></React.Suspense>);}@@ -218,6 +223,20 @@ interface Props {}function FolderContainer(props: Props) {+ const {+ directoryContent,+ toggleDrawer,+ toggleProTeaser,+ isDesktopMode,+ currentDirectoryPerspective,+ setSelectedEntries,+ reflectCreateEntry,+ openEntry,+ defaultPerspective,+ goBack,+ goForward+ } = props;+const { t } = useTranslation();const theme = useTheme();const havePrevOpenedFile = React.useRef<boolean>(false);@@ -278,20 +297,6 @@ function FolderContainer(props: Props) {boolean>(false);- const {- directoryContent,- toggleDrawer,- toggleProTeaser,- isDesktopMode,- currentDirectoryPerspective,- setSelectedEntries,- reflectCreateEntry,- openEntry,- defaultPerspective,- goBack,- goForward- } = props;-let currentPerspective =currentDirectoryPerspective || defaultPerspective || PerspectiveIDs.GRID;@@ -308,6 +313,7 @@ function FolderContainer(props: Props) {() => setIsRenameEntryDialogOpened(true),[]);+const renderPerspective = () => {if (showWelcomePanel) {return AppConfig.showWelcomePanel ? <WelcomePanelAsync /> : null;diff --git a/app/components/RenderHistory.tsx b/app/components/RenderHistory.tsxindex 5db13b77f..21452bcc4 100644--- a/app/components/RenderHistory.tsx+++ b/app/components/RenderHistory.tsx@@ -33,19 +33,30 @@ import { useTranslation } from 'react-i18next';* along with this program. If not, see <https://www.gnu.org/licenses/>.**/--export const renderHistory = (- key: string,- items: Array<TS.HistoryItem> | Array<TS.BookmarkItem>,- update: () => void,- currentLocationId: string,- openLink: (url: string, options: any) => void,- openLocationById: (locationId: string) => void,- openEntry: (entryPath: string) => void,- maxItems: number | undefined = undefined,- showDelete: boolean = true-) => {+interface Props {+ key: string;+ items: Array<TS.HistoryItem> | Array<TS.BookmarkItem>;+ update: () => void;+ currentLocationId: string;+ openLink: (url: string, options: any) => void;+ openLocationById: (locationId: string) => void;+ openEntry: (entryPath: string) => void;+ maxItems?: number | undefined;+ showDelete?: boolean;+}+function RenderHistory(props: Props) {const { t } = useTranslation();+ const {+ key,+ items,+ update,+ currentLocationId,+ openLink,+ openLocationById,+ openEntry,+ maxItems,+ showDelete+ } = props;return (<>{items &&@@ -131,4 +142,6 @@ export const renderHistory = (})}</>);-};+}++export default RenderHistory;diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsxindex a7b1f992e..65781184a 100644--- a/app/components/StoredSearches.tsx+++ b/app/components/StoredSearches.tsx@@ -50,9 +50,9 @@ import SearchMenu from '-/components/menus/SearchMenu';import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';import HistoryMenu from '-/components/menus/HistoryMenu';import BookmarksMenu from '-/components/menus/BookmarksMenu';-import { renderHistory } from '-/components/RenderHistory';import { classes, SidePanel } from '-/components/SidePanels.css';import { useTranslation } from 'react-i18next';+import RenderHistory from '-/components/RenderHistory';interface Props {style?: any;@@ -352,17 +352,17 @@ function StoredSearches(props: Props) {</Grid>)}</Grid>- {Pro &&- props.showBookmarks &&- renderHistory(- Pro.bookmarks.bookmarksKey,- bookmarkItems,- forceUpdate,- props.currentLocationId,- props.openLink,- props.openLocationById,- props.openEntry- )}+ {Pro && props.showBookmarks && (+ <RenderHistory+ key={Pro.bookmarks.bookmarksKey}+ items={bookmarkItems}+ update={forceUpdate}+ currentLocationId={props.currentLocationId}+ openLink={props.openLink}+ openLocationById={props.openLocationById}+ openEntry={props.openEntry}+ />+ )}<Grid container direction="row"><Grid item xs={10} style={{ alignSelf: 'center' }}><IconButton@@ -403,16 +403,17 @@ function StoredSearches(props: Props) {</Grid>)}</Grid>- {props.fileOpenHistory &&- renderHistory(- historyKeys.fileOpenKey,- fileOpenHistoryItems,- forceUpdate,- props.currentLocationId,- props.openLink,- props.openLocationById,- props.openEntry- )}+ {props.fileOpenHistory && (+ <RenderHistory+ key={historyKeys.fileOpenKey}+ items={fileOpenHistoryItems}+ update={forceUpdate}+ currentLocationId={props.currentLocationId}+ openLink={props.openLink}+ openLocationById={props.openLocationById}+ openEntry={props.openEntry}+ />+ )}<Grid container direction="row"><Grid item xs={10} style={{ alignSelf: 'center' }}><IconButton@@ -454,16 +455,17 @@ function StoredSearches(props: Props) {</Grid>)}</Grid>- {props.fileEditHistory &&- renderHistory(- historyKeys.fileEditKey,- fileEditHistoryItems,- forceUpdate,- props.currentLocationId,- props.openLink,- props.openLocationById,- props.openEntry- )}+ {props.fileEditHistory && (+ <RenderHistory+ key={historyKeys.fileEditKey}+ items={fileEditHistoryItems}+ update={forceUpdate}+ currentLocationId={props.currentLocationId}+ openLink={props.openLink}+ openLocationById={props.openLocationById}+ openEntry={props.openEntry}+ />+ )}<Grid container direction="row"><Grid item xs={10} style={{ alignSelf: 'center' }}><IconButton@@ -532,16 +534,17 @@ function StoredSearches(props: Props) {</Grid>)}</Grid>- {props.folderOpenHistory &&- renderHistory(- historyKeys.folderOpenKey,- folderOpenHistoryItems,- forceUpdate,- props.currentLocationId,- props.openLink,- props.openLocationById,- props.openEntry- )}+ {props.folderOpenHistory && (+ <RenderHistory+ key={historyKeys.folderOpenKey}+ items={folderOpenHistoryItems}+ update={forceUpdate}+ currentLocationId={props.currentLocationId}+ openLink={props.openLink}+ openLocationById={props.openLocationById}+ openEntry={props.openEntry}+ />+ )}{SaveSearchDialog && saveSearchDialogOpened !== undefined && (<SaveSearchDialogopen={true}diff --git a/app/components/WelcomePanel.tsx b/app/components/WelcomePanel.tsxindex bf6d32d47..ba6993cb4 100644--- a/app/components/WelcomePanel.tsx+++ b/app/components/WelcomePanel.tsx@@ -51,11 +51,11 @@ import { getDesktopMode } from '-/reducers/settings';import Links from '-/content/links';import { Pro } from '-/pro';import { TS } from '-/tagspaces.namespace';-import { renderHistory } from '-/components/RenderHistory';import HowToStart from '-/components/HowToStart';import { openURLExternally } from '-/services/utils-io';import { styled, useTheme } from '@mui/material/styles';import { useTranslation } from 'react-i18next';+import RenderHistory from '-/components/RenderHistory';const PREFIX = 'WelcomePanel';@@ -142,17 +142,17 @@ function WelcomePanel() {</Typography>{fileOpenHistoryItems ? (<List>- {renderHistory(- historyKeys.fileOpenKey,- fileOpenHistoryItems,- forceUpdate,- currentLocationId,- openLinkDispatch,- openLocationByIdDispatch,- openEntryDispatch,- maxRecentItems,- showDelete- )}+ <RenderHistory+ key={historyKeys.fileOpenKey}+ items={fileOpenHistoryItems}+ update={forceUpdate}+ currentLocationId={currentLocationId}+ openLink={openLinkDispatch}+ openLocationById={openLocationByIdDispatch}+ openEntry={openEntryDispatch}+ maxItems={maxRecentItems}+ showDelete={showDelete}+ /></List>) : (<Typography className={classes.noRecentItems} variant="caption">@@ -164,17 +164,17 @@ function WelcomePanel() {</Typography>{fileEditHistoryItems ? (<List>- {renderHistory(- historyKeys.fileEditKey,- fileEditHistoryItems,- forceUpdate,- currentLocationId,- openLinkDispatch,- openLocationByIdDispatch,- openEntryDispatch,- maxRecentItems,- showDelete- )}+ <RenderHistory+ key={historyKeys.fileEditKey}+ items={fileEditHistoryItems}+ update={forceUpdate}+ currentLocationId={currentLocationId}+ openLink={openLinkDispatch}+ openLocationById={openLocationByIdDispatch}+ openEntry={openEntryDispatch}+ maxItems={maxRecentItems}+ showDelete={showDelete}+ /></List>) : (<Typography className={classes.noRecentItems} variant="caption">@@ -186,17 +186,17 @@ function WelcomePanel() {</Typography>{folderOpenHistoryItems ? (<List>- {renderHistory(- historyKeys.folderOpenKey,- folderOpenHistoryItems,- forceUpdate,- currentLocationId,- openLinkDispatch,- openLocationByIdDispatch,- openEntryDispatch,- maxRecentItems,- showDelete- )}+ <RenderHistory+ key={historyKeys.folderOpenKey}+ items={folderOpenHistoryItems}+ update={forceUpdate}+ currentLocationId={currentLocationId}+ openLink={openLinkDispatch}+ openLocationById={openLocationByIdDispatch}+ openEntry={openEntryDispatch}+ maxItems={maxRecentItems}+ showDelete={showDelete}+ /></List>) : (<Typography className={classes.noRecentItems} variant="caption">diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex cfb499938..a59987af2 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -89,7 +89,6 @@ import PageNotification from '-/containers/PageNotification';import listen from '-/containers/RendererListener';import { actions as LocationIndexActions } from '-/reducers/location-index';import MoveOrCopyFilesDialog from '-/components/dialogs/MoveOrCopyFilesDialog';-import PlatformIO from '-/services/platform-facade';import { Pro } from '-/pro';import NewFileDialog from '-/components/dialogs/NewFileDialog';import IsTruncatedConfirmDialog from '-/components/dialogs/IsTruncatedConfirmDialog';diff --git a/app/containers/Root.tsx b/app/containers/Root.tsxindex 31b6eddcf..778198ef6 100644--- a/app/containers/Root.tsx+++ b/app/containers/Root.tsx@@ -21,7 +21,6 @@ import { Provider } from 'react-redux';import { PersistGate } from 'redux-persist/integration/react';import { Store } from 'redux';import AppConfig from '-/AppConfig';-import LoadingScreen from '../components/LoadingScreen';import { actions as AppActions } from '../reducers/app';import App from '-/containers/App';import MainPage from '-/containers/MainPage';diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsxindex 12136354c..f11e09005 100644--- a/app/perspectives/grid-perspective/components/GridPagination.tsx+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx@@ -43,7 +43,8 @@ import {getLastBackgroundImageChange,getLastThumbnailImageChange,getLastSelectedEntryPath,- getLastSearchTimestamp+ getLastSearchTimestamp,+ getDirectoryContent} from '-/reducers/app';import EntryIcon from '-/components/EntryIcon';import TagsPreview from '-/components/TagsPreview';@@ -60,6 +61,7 @@ import { MilkdownEditor } from '@tagspaces/tagspaces-md';import { renderCell } from '-/perspectives/common/main-container';import { useTranslation } from 'react-i18next';import { getCurrentLocation } from '-/reducers/locations';+import GlobalSearch from '-/services/search-index';interface Props {isMetaLoaded: boolean;@@ -107,7 +109,6 @@ interface Props {setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;singleClickAction: string;lastSelectedEntryPath: string;- directoryContent: Array<TS.FileSystemEntry>;openEntry: (entryPath?: string) => void;openFileNatively: (path?: string) => void;loadDirectoryContent: (@@ -155,14 +156,18 @@ function GridPagination(props: Props) {setDirContextMenuAnchorEl,showNotification,moveFiles,- directoryContent,gridPageLimit,currentPage,selectedEntries,setSelectedEntries,clearSelection,- files+ files,+ lastSearchTimestamp} = props;++ const directoryContent: Array<TS.FileSystemEntry> = useSelector(+ getDirectoryContent+ );const currentLocation: TS.Location = useSelector(getCurrentLocation);if (!showDirectories) {directories = [];@@ -244,7 +249,7 @@ function GridPagination(props: Props) {}, [//props.currentLocationPath,props.currentDirectoryPath,- props.lastSearchTimestamp+ lastSearchTimestamp]);const setThumbs = (@@ -581,7 +586,9 @@ function GridPagination(props: Props) {selectedEntries,setSelectedEntries,lastSelectedEntryPath,- directoryContent,+ lastSearchTimestamp+ ? GlobalSearch.getInstance().getResults()+ : directoryContent,openEntry,openFileNatively,loadDirectoryContent,@@ -605,7 +612,9 @@ function GridPagination(props: Props) {selectedEntries,setSelectedEntries,lastSelectedEntryPath,- directoryContent,+ lastSearchTimestamp+ ? GlobalSearch.getInstance().getResults()+ : directoryContent,openEntry,openFileNatively,loadDirectoryContent,diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex eab0743ae..ca5e8e1f6 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -19,7 +19,7 @@import React, { useEffect, useReducer, useRef, useState } from 'react';import { useSelector, useDispatch } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';-import { isObj, sortByCriteria } from '@tagspaces/tagspaces-common/misc';+import { isObj } from '@tagspaces/tagspaces-common/misc';import { isVisibleOnScreen } from '-/utils/dom';import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';import FileMenu from '-/components/menus/FileMenu';@@ -32,12 +32,9 @@ import IOActions from '-/reducers/io-actions';import {actions as AppActions,AppDispatch,- getDirectoryContent,getDirectoryMeta,- getEditedEntryPaths,getLastSearchTimestamp,getLastSelectedEntryPath,- getSearchFilter,getSelectedEntries,isReadOnlyMode} from '-/reducers/app';@@ -58,6 +55,7 @@ import { fileOperationsEnabled } from '-/perspectives/common/main-container';import GlobalSearch from '-/services/search-index';import useFirstRender from '-/utils/useFirstRender';import { openURLExternally } from '-/services/utils-io';+import { useSortedDirContext } from '-/perspectives/grid-perspective/hooks/useSortedDirContext';interface Props {currentDirectoryPath: string;@@ -82,9 +80,8 @@ function GridPerspective(props: Props) {const { currentDirectoryPath, openRenameEntryDialog } = props;const dispatch: AppDispatch = useDispatch();- const directoryContent: Array<TS.FileSystemEntry> = useSelector(- getDirectoryContent- );++ const { sortedDirContent } = useSortedDirContext();const directoryMeta: TS.FileSystemEntryMeta = useSelector(getDirectoryMeta);const readOnlyMode = useSelector(isReadOnlyMode);const lastSearchTimestamp = useSelector(getLastSearchTimestamp);@@ -94,10 +91,10 @@ function GridPerspective(props: Props) {);const lastSelectedEntryPath = useSelector(getLastSelectedEntryPath);const keyBindings = useSelector(getKeyBindingObject);- const searchFilter: string = useSelector(getSearchFilter);- const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(+ //const searchFilter: string = useSelector(getSearchFilter);+ /*const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(getEditedEntryPaths- );+ );*/// Create functions that dispatch actionsconst handleMoveFiles = (files: Array<string>, destination: string) =>@@ -167,11 +164,6 @@ function GridPerspective(props: Props) {? settings.orderBy: defaultSettings.orderBy);- const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(- !lastSearchTimestamp- ? directoryContent- : GlobalSearch.getInstance().getResults()- );const layoutType = useRef<string>(settings && settings.layoutType? settings.layoutType@@ -247,7 +239,7 @@ function GridPerspective(props: Props) {}}, [selectedEntries]);- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {sortedDirContent.current = sortByCriteria(searchFilter@@ -260,19 +252,21 @@ function GridPerspective(props: Props) {);forceUpdate();}- }, [searchFilter]);+ }, [searchFilter]);*/- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {- setSortedDirContent();+ sortedDirContent.current = getSortedDirContent();+ forceUpdate();}}, [directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)+ // currentDirectoryPath,sortBy.current,orderBy.current- ]);+ ]);*/- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {if (lastSearchTimestamp) {sortBy.current = 'byRelevance';@@ -287,30 +281,25 @@ function GridPerspective(props: Props) {? settings.orderBy: defaultSettings.orderBy;}- setSortedDirContent();+ sortedDirContent.current = getSortedDirContent();+ forceUpdate();}- }, [lastSearchTimestamp]);+ }, [lastSearchTimestamp]);*/- function setSortedDirContent() {+ /*function getSortedDirContent() {if (!lastSearchTimestamp) {// not in search mode- sortedDirContent.current = sortByCriteria(- directoryContent,- sortBy.current,- orderBy.current- );+ return sortByCriteria(directoryContent, sortBy.current, orderBy.current);} else {if (sortBy.current === 'byRelevance') {// initial search results is sorted by relevanceif (orderBy.current) {- sortedDirContent.current = GlobalSearch.getInstance().getResults();+ return GlobalSearch.getInstance().getResults();} else {- sortedDirContent.current = [- ...GlobalSearch.getInstance().getResults()- ].reverse();+ return [...GlobalSearch.getInstance().getResults()].reverse();}} else {- sortedDirContent.current = sortByCriteria(+ return sortByCriteria(searchFilter? GlobalSearch.getInstance().getResults()@@ -323,16 +312,16 @@ function GridPerspective(props: Props) {);}}- forceUpdate();- }+ //forceUpdate();+ }*/- useEffect(() => {+ /*useEffect(() => {// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTSif (!firstRender && lastSearchTimestamp) {sortedDirContent.current = GlobalSearch.getInstance().getResults();forceUpdate();}- }, [editedEntryPaths]);+ }, [editedEntryPaths]);*/useEffect(() => {if (!firstRender) {@@ -437,6 +426,13 @@ function GridPerspective(props: Props) {gridPageLimit.current]);+ /*if ( // for debugging skip first re-renders+ directoryContent.length > 0 &&+ !directoryContent[0].path.startsWith(currentDirectoryPath)+ ) {+ return null;+ }*/+const makeFirstSelectedEntryVisible = () => {if (selectedEntries && selectedEntries.length > 0) {try {@@ -485,7 +481,7 @@ function GridPerspective(props: Props) {if (selectedEntries && selectedEntries.length > 0) {Pro.exportAsCsv.ExportAsCsv(selectedEntries);} else {- Pro.exportAsCsv.ExportAsCsv(sortedDirContent.current);+ Pro.exportAsCsv.ExportAsCsv(sortedDirContent);}}};@@ -500,7 +496,7 @@ function GridPerspective(props: Props) {clearSelection();} else {if (!lastSearchTimestamp) {- handleSetSelectedEntries(directoryContent);+ handleSetSelectedEntries(sortedDirContent);} else {handleSetSelectedEntries(GlobalSearch.getInstance().getResults());}@@ -651,10 +647,8 @@ function GridPerspective(props: Props) {}};- const sortedDirectories = sortedDirContent.current.filter(- entry => !entry.isFile- );- const sortedFiles = sortedDirContent.current.filter(entry => entry.isFile);+ const sortedDirectories = sortedDirContent.filter(entry => !entry.isFile);+ const sortedFiles = sortedDirContent.filter(entry => entry.isFile);/*const locationPath = currentLocation? PlatformIO.getLocationPath(currentLocation): '';*/@@ -787,11 +781,6 @@ function GridPerspective(props: Props) {selectedEntries={selectedEntries}setSelectedEntries={handleSetSelectedEntries}singleClickAction={singleClickAction.current}- directoryContent={- lastSearchTimestamp- ? GlobalSearch.getInstance().getResults()- : directoryContent- }openFileNatively={handleOpenFileNatively}setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}diff --git a/app/perspectives/grid-perspective/hooks/SortedDirContextProvider.tsx b/app/perspectives/grid-perspective/hooks/SortedDirContextProvider.tsxnew file mode 100644index 000000000..0bd0af889--- /dev/null+++ b/app/perspectives/grid-perspective/hooks/SortedDirContextProvider.tsx@@ -0,0 +1,129 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React, { createContext, useMemo } from 'react';+import { useSelector } from 'react-redux';+import {+ getDirectoryContent,+ getDirectoryMeta,+ getEditedEntryPaths,+ getLastSearchTimestamp,+ getSearchFilter+} from '-/reducers/app';+import { TS } from '-/tagspaces.namespace';+import GlobalSearch from '-/services/search-index';+import { sortByCriteria } from '@tagspaces/tagspaces-common/misc';+import { Pro } from '-/pro';+import { PerspectiveIDs } from '-/perspectives';+import { defaultSettings } from '-/perspectives/grid-perspective';++type SortedDirContextData = {+ sortedDirContent: Array<TS.FileSystemEntry>;+};++export const SortedDirContext = createContext<SortedDirContextData>({+ sortedDirContent: undefined+});++export type SortedDirContextProviderProps = {+ children: React.ReactNode;+};++export const SortedDirContextProvider = ({+ children+}: SortedDirContextProviderProps) => {+ const directoryContent: Array<TS.FileSystemEntry> = useSelector(+ getDirectoryContent+ );+ const lastSearchTimestamp = useSelector(getLastSearchTimestamp);+ const searchFilter: string = useSelector(getSearchFilter);+ const directoryMeta: TS.FileSystemEntryMeta = useSelector(getDirectoryMeta);+ const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(+ getEditedEntryPaths+ );++ function getSettings(): TS.FolderSettings {+ if (+ Pro &&+ directoryMeta &&+ directoryMeta.perspectiveSettings &&+ directoryMeta.perspectiveSettings[PerspectiveIDs.GRID]+ ) {+ return directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];+ } else {+ // loading settings for not Pro+ return JSON.parse(localStorage.getItem(defaultSettings.settingsKey));+ }+ }++ function getSortedDirContent() {+ const settings = getSettings();+ const sortBy =+ settings && settings.sortBy ? settings.sortBy : defaultSettings.sortBy;+ const orderBy =+ settings && typeof settings.orderBy !== 'undefined'+ ? settings.orderBy+ : defaultSettings.orderBy;+ if (!lastSearchTimestamp) {+ // not in search mode+ return sortByCriteria(directoryContent, sortBy, orderBy);+ } else {+ if (sortBy === 'byRelevance') {+ // initial search results is sorted by relevance+ if (orderBy) {+ return GlobalSearch.getInstance().getResults();+ } else {+ return [...GlobalSearch.getInstance().getResults()].reverse();+ }+ } else {+ return sortByCriteria(+ searchFilter+ ? GlobalSearch.getInstance()+ .getResults()+ .filter(entry =>+ entry.name.toLowerCase().includes(searchFilter.toLowerCase())+ )+ : GlobalSearch.getInstance().getResults(),+ sortBy,+ orderBy+ );+ }+ }+ }++ const context = useMemo(() => {+ const sortedDirContent = !lastSearchTimestamp+ ? getSortedDirContent()+ : GlobalSearch.getInstance().getResults();+ return {+ sortedDirContent+ };+ }, [+ directoryContent,+ lastSearchTimestamp,+ directoryMeta,+ searchFilter,+ editedEntryPaths+ ]);++ return (+ <SortedDirContext.Provider value={context}>+ {children}+ </SortedDirContext.Provider>+ );+};diff --git a/app/perspectives/grid-perspective/hooks/useSortedDirContext.tsx b/app/perspectives/grid-perspective/hooks/useSortedDirContext.tsxnew file mode 100644index 000000000..6bd95ff8f--- /dev/null+++ b/app/perspectives/grid-perspective/hooks/useSortedDirContext.tsx@@ -0,0 +1,5 @@+import { useContext } from 'react';++import { SortedDirContext } from './SortedDirContextProvider';++export const useSortedDirContext = () => useContext(SortedDirContext);diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex 04449edca..48d7f3407 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -19,7 +19,7 @@import React, { useEffect, useReducer, useRef, useState } from 'react';import { useSelector, useDispatch } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';-import { isObj, sortByCriteria } from '@tagspaces/tagspaces-common/misc';+import { isObj } from '@tagspaces/tagspaces-common/misc';import { isVisibleOnScreen } from '-/utils/dom';import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';import FileMenu from '-/components/menus/FileMenu';@@ -32,12 +32,9 @@ import IOActions from '-/reducers/io-actions';import {actions as AppActions,AppDispatch,- getDirectoryContent,getDirectoryMeta,- getEditedEntryPaths,getLastSearchTimestamp,getLastSelectedEntryPath,- getSearchFilter,getSelectedEntries,isReadOnlyMode} from '-/reducers/app';@@ -58,6 +55,7 @@ import { fileOperationsEnabled } from '-/perspectives/common/main-container';import GlobalSearch from '-/services/search-index';import useFirstRender from '-/utils/useFirstRender';import { openURLExternally } from '-/services/utils-io';+import { useSortedDirContext } from '-/perspectives/grid-perspective/hooks/useSortedDirContext';interface Props {currentDirectoryPath: string;@@ -82,9 +80,8 @@ function ListPerspective(props: Props) {const { currentDirectoryPath, openRenameEntryDialog } = props;const dispatch: AppDispatch = useDispatch();- const directoryContent: Array<TS.FileSystemEntry> = useSelector(- getDirectoryContent- );++ const { sortedDirContent } = useSortedDirContext();const directoryMeta: TS.FileSystemEntryMeta = useSelector(getDirectoryMeta);const readOnlyMode = useSelector(isReadOnlyMode);const lastSearchTimestamp = useSelector(getLastSearchTimestamp);@@ -94,10 +91,10 @@ function ListPerspective(props: Props) {);const lastSelectedEntryPath = useSelector(getLastSelectedEntryPath);const keyBindings = useSelector(getKeyBindingObject);- const searchFilter: string = useSelector(getSearchFilter);- const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(+ //const searchFilter: string = useSelector(getSearchFilter);+ /*const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(getEditedEntryPaths- );+ );*/// Create functions that dispatch actionsconst handleMoveFiles = (files: Array<string>, destination: string) =>@@ -167,11 +164,6 @@ function ListPerspective(props: Props) {? settings.orderBy: defaultSettings.orderBy);- const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(- !lastSearchTimestamp- ? directoryContent- : GlobalSearch.getInstance().getResults()- );const layoutType = useRef<string>(settings && settings.layoutType? settings.layoutType@@ -247,7 +239,7 @@ function ListPerspective(props: Props) {}}, [selectedEntries]);- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {sortedDirContent.current = sortByCriteria(searchFilter@@ -260,19 +252,21 @@ function ListPerspective(props: Props) {);forceUpdate();}- }, [searchFilter]);+ }, [searchFilter]);*/- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {- setSortedDirContent();+ sortedDirContent.current = getSortedDirContent();+ forceUpdate();}}, [directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)+ // currentDirectoryPath,sortBy.current,orderBy.current- ]);+ ]);*/- useEffect(() => {+ /*useEffect(() => {if (!firstRender) {if (lastSearchTimestamp) {sortBy.current = 'byRelevance';@@ -287,30 +281,25 @@ function ListPerspective(props: Props) {? settings.orderBy: defaultSettings.orderBy;}- setSortedDirContent();+ sortedDirContent.current = getSortedDirContent();+ forceUpdate();}- }, [lastSearchTimestamp]);+ }, [lastSearchTimestamp]);*/- function setSortedDirContent() {+ /*function getSortedDirContent() {if (!lastSearchTimestamp) {// not in search mode- sortedDirContent.current = sortByCriteria(- directoryContent,- sortBy.current,- orderBy.current- );+ return sortByCriteria(directoryContent, sortBy.current, orderBy.current);} else {if (sortBy.current === 'byRelevance') {// initial search results is sorted by relevanceif (orderBy.current) {- sortedDirContent.current = GlobalSearch.getInstance().getResults();+ return GlobalSearch.getInstance().getResults();} else {- sortedDirContent.current = [- ...GlobalSearch.getInstance().getResults()- ].reverse();+ return [...GlobalSearch.getInstance().getResults()].reverse();}} else {- sortedDirContent.current = sortByCriteria(+ return sortByCriteria(searchFilter? GlobalSearch.getInstance().getResults()@@ -323,16 +312,16 @@ function ListPerspective(props: Props) {);}}- forceUpdate();- }+ //forceUpdate();+ }*/- useEffect(() => {+ /*useEffect(() => {// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTSif (!firstRender && lastSearchTimestamp) {sortedDirContent.current = GlobalSearch.getInstance().getResults();forceUpdate();}- }, [editedEntryPaths]);+ }, [editedEntryPaths]);*/useEffect(() => {if (!firstRender) {@@ -485,7 +474,7 @@ function ListPerspective(props: Props) {if (selectedEntries && selectedEntries.length > 0) {Pro.exportAsCsv.ExportAsCsv(selectedEntries);} else {- Pro.exportAsCsv.ExportAsCsv(sortedDirContent.current);+ Pro.exportAsCsv.ExportAsCsv(sortedDirContent);}}};@@ -500,7 +489,7 @@ function ListPerspective(props: Props) {clearSelection();} else {if (!lastSearchTimestamp) {- handleSetSelectedEntries(directoryContent);+ handleSetSelectedEntries(sortedDirContent);} else {handleSetSelectedEntries(GlobalSearch.getInstance().getResults());}@@ -651,10 +640,8 @@ function ListPerspective(props: Props) {}};- const sortedDirectories = sortedDirContent.current.filter(- entry => !entry.isFile- );- const sortedFiles = sortedDirContent.current.filter(entry => entry.isFile);+ const sortedDirectories = sortedDirContent.filter(entry => !entry.isFile);+ const sortedFiles = sortedDirContent.filter(entry => entry.isFile);/*const locationPath = currentLocation? PlatformIO.getLocationPath(currentLocation): '';*/@@ -785,11 +772,6 @@ function ListPerspective(props: Props) {selectedEntries={selectedEntries}setSelectedEntries={handleSetSelectedEntries}singleClickAction={singleClickAction.current}- directoryContent={- lastSearchTimestamp- ? GlobalSearch.getInstance().getResults()- : directoryContent- }openFileNatively={handleOpenFileNatively}setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 3847e2cc6..8ec6fad0b 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -120,6 +120,7 @@ export const types = {SET_GENERATING_THUMBNAILS: 'APP/SET_GENERATING_THUMBNAILS',SET_NEW_VERSION_AVAILABLE: 'APP/SET_NEW_VERSION_AVAILABLE',SET_CURRENLOCATIONID: 'APP/SET_CURRENLOCATIONID',+ SET_CURRENT_LOCATION: 'APP/SET_CURRENT_LOCATION',SET_CURRENDIRECTORYCOLOR: 'APP/SET_CURRENDIRECTORYCOLOR',SET_CURRENDIRECTORYPERSPECTIVE: 'APP/SET_CURRENDIRECTORYPERSPECTIVE',SET_IS_META_LOADED: 'APP/SET_IS_META_LOADED',@@ -350,10 +351,13 @@ export default (state: any = initialState, action: any) => {return state;}case types.SET_NEW_VERSION_AVAILABLE: {- return {- ...state,- isUpdateAvailable: action.isUpdateAvailable- };+ if (action.isUpdateAvailable !== state.isUpdateAvailable) {+ return {+ ...state,+ isUpdateAvailable: action.isUpdateAvailable+ };+ }+ return state;}case types.SET_DIRECTORY_META: {return {@@ -420,10 +424,23 @@ export default (state: any = initialState, action: any) => {};}case types.SET_CURRENLOCATIONID: {- return {- ...state,- currentLocationId: action.locationId- };+ if (action.currentLocationId !== state.currentLocationId) {+ return {+ ...state,+ currentLocationId: action.locationId+ };+ }+ return state;+ }+ case types.SET_CURRENT_LOCATION: {+ if (action.location.uuid !== state.currentLocationId) {+ return {+ ...state,+ currentDirectoryPath: action.location.path,+ currentLocationId: action.location.uuid+ };+ }+ return state;}/* case types.SET_LAST_SELECTED_ENTRY: {return { ...state, lastSelectedEntry: action.entryPath };@@ -664,10 +681,13 @@ export default (state: any = initialState, action: any) => {};}*/case types.SET_GENERATING_THUMBNAILS: {- return {- ...state,- isGeneratingThumbs: action.isGeneratingThumbs- };+ if (action.isGeneratingThumbs !== state.isGeneratingThumbs) {+ return {+ ...state,+ isGeneratingThumbs: action.isGeneratingThumbs+ };+ }+ return state;}case types.OPEN_FILE: {return {@@ -686,7 +706,10 @@ export default (state: any = initialState, action: any) => {return { ...state, isEntryInFullWidth: !state.isEntryInFullWidth };}case types.SET_ENTRY_FULLWIDTH: {- return { ...state, isEntryInFullWidth: action.isFullWidth };+ if (action.isEntryInFullWidth !== state.isEntryInFullWidth) {+ return { ...state, isEntryInFullWidth: action.isFullWidth };+ }+ return state;}case types.UPDATE_THUMB_URL: {const dirEntries = state.currentDirectoryEntries.map(entry => {@@ -2005,8 +2028,21 @@ export const actions = {type: types.SET_CURRENLOCATIONID,locationId}),- changeLocation: (location: TS.Location) => (dispatch: (action) => void) => {- dispatch(actions.changeLocationByID(location.uuid));+ setCurrentLocation: (location: TS.Location) => ({+ type: types.SET_CURRENT_LOCATION,+ location+ }),+ changeLocation: (location: TS.Location) => (+ dispatch: (action) => void,+ getState: () => any+ ) => {+ //dispatch(actions.changeLocationByID(location.uuid));+ const { currentLocationId } = getState().app;+ if (location.uuid !== currentLocationId) {+ // dispatch(actions.exitSearchMode());+ dispatch(LocationIndexActions.clearDirectoryIndex());+ dispatch(actions.setCurrentLocation(location));+ }},changeLocationByID: (locationId: string) => (dispatch: (action) => void,@@ -2634,7 +2670,7 @@ export const actions = {tags: Array<TS.Tag>,updateIndex = true) => (dispatch: (action) => void, getState: () => any) => {- const { openedFiles, selectedEntries } = getState().app;+ // const { openedFiles, selectedEntries } = getState().app;// to reload cell in KanBan if add/remove sidecar tagsconst action: TS.EditedEntryAction = `edit${tags.map(tag => tag.title)