TagSpaces is an offline, open source, document manager with tagging support
fix load meta by fixing loadDirectoryContent (#1684)
Stanimir41d7e6e63ff9
diff --git a/app/components/DirectoryTreeView.tsx b/app/components/DirectoryTreeView.tsxindex 4bbe3c265..6fbfc8158 100644--- a/app/components/DirectoryTreeView.tsx+++ b/app/components/DirectoryTreeView.tsx@@ -29,7 +29,11 @@ import { locationType } from '-/utils/misc';interface Props {classes: any;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (+ path: string,+ generateThumbnails: boolean,+ loadDirMeta?: boolean+ ) => void;location: TS.Location;data?: any;isReadOnlyMode?: boolean;@@ -169,7 +173,8 @@ const DirectoryTreeView = forwardRef(.then(() => {loadSubDirectories(subDir);props.changeLocation(subDir);- props.loadDirectoryContent(subDir.path, true);+ props.loadDirectoryContent(subDir.path, true, true);+ return true;}).catch(error => {console.log('enableObjectStoreSupport', error);@@ -178,7 +183,7 @@ const DirectoryTreeView = forwardRef(PlatformIO.disableObjectStoreSupport();loadSubDirectories(subDir);props.changeLocation(subDir);- props.loadDirectoryContent(subDir.path, true);+ props.loadDirectoryContent(subDir.path, true, true);}};diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex b999f7b9a..38ed10ce6 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -201,7 +201,7 @@ interface Props {showInFileManager: () => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;reflectCreateEntry: (path: string, isFile: boolean) => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;loadParentDirectoryContent: () => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;isReadOnlyMode: boolean;diff --git a/app/components/LocationView.tsx b/app/components/LocationView.tsxindex 77e5d5b5a..caa2fe9d4 100644--- a/app/components/LocationView.tsx+++ b/app/components/LocationView.tsx@@ -57,7 +57,7 @@ interface Props {location: TS.Location;currentLocationId: string;openLocation: (location: TS.Location) => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;hideDrawer: () => void;isReadOnlyMode: boolean;diff --git a/app/components/PathBreadcrumbs.tsx b/app/components/PathBreadcrumbs.tsxindex c4093f818..384231c65 100644--- a/app/components/PathBreadcrumbs.tsx+++ b/app/components/PathBreadcrumbs.tsx@@ -56,7 +56,7 @@ const NoWrapBreadcrumb = withStyles({interface Props {currentDirectoryPath: string;currentLocationPath: string;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;switchPerspective: (perspectiveId: string) => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;openDirectory: () => void;diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex 858963b6d..b3ac83f4e 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -58,7 +58,7 @@ interface Props {searchLocationIndex: (searchQuery: TS.SearchQuery) => void;createLocationsIndexes: () => void;searchAllLocations: (searchQuery: TS.SearchQuery) => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ // loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openURLExternally: (url: string) => void;searchQuery: TS.SearchQuery; // () => any;openCurrentDirectory: () => void;@@ -80,7 +80,7 @@ const useStyles = makeStyles(theme => ({}}));-const SearchInline = (props: Props) => {+function SearchInline(props: Props) {// const [, forceUpdate] = useReducer(x => x + 1, 0);const textQuery = useRef<string>(props.searchQuery.textQuery);const textQueryMask = useRef<string>('');@@ -144,7 +144,7 @@ const SearchInline = (props: Props) => {useEffect(() => {if (Object.keys(props.searchQuery).length > 0) {- let emptySearch: boolean = true;+ let emptySearch = true;textQueryMask.current = '';if (props.searchQuery.tagsAND && props.searchQuery.tagsAND.length > 0) {@@ -480,7 +480,7 @@ const SearchInline = (props: Props) => {</Tooltip></div>);-};+}function mapStateToProps(state) {return {@@ -501,7 +501,7 @@ function mapDispatchToProps(dispatch) {setSearchQuery: LocationIndexActions.setSearchQuery,searchLocationIndex: LocationIndexActions.searchLocationIndex,createLocationsIndexes: LocationIndexActions.createLocationsIndexes,- loadDirectoryContent: AppActions.loadDirectoryContent,+ // loadDirectoryContent: AppActions.loadDirectoryContent,openURLExternally: AppActions.openURLExternally,openCurrentDirectory: AppActions.openCurrentDirectory},diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsxindex 0b048c87f..84632df61 100644--- a/app/components/SearchPopover.tsx+++ b/app/components/SearchPopover.tsx@@ -85,7 +85,7 @@ type PropsClasses = Record<keyof StyleProps, string>;interface Props {style?: any;theme?: any;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openURLExternally: (url: string, skipConfirmation?: boolean) => void;hideDrawer?: () => void;searchQuery: TS.SearchQuery; // () => any;@@ -395,7 +395,7 @@ const SearchPopover = (props: Props) => {function openCurrentDirectory() {if (props.currentDirectory) {- props.loadDirectoryContent(props.currentDirectory, false);+ props.loadDirectoryContent(props.currentDirectory, false, true);} else {props.setSearchResults([]);}diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex 7fcfd2fe0..7e8a41ba0 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -70,7 +70,7 @@ interface Props {onClose: (param?: any) => void;anchorEl: Element;directoryPath: string;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openDirectory: (path: string) => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;reflectCreateEntry?: (path: string, isFile: boolean) => void;@@ -164,12 +164,12 @@ const DirectoryMenu = (props: Props) => {function reloadDirectory() {onClose();- props.loadDirectoryContent(props.directoryPath, true);+ props.loadDirectoryContent(props.directoryPath, true, true);}function openDirectory() {onClose();- props.loadDirectoryContent(props.directoryPath, true);+ props.loadDirectoryContent(props.directoryPath, true, true);}function showProperties() {diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsxindex b27fd2a81..d2ecc57b6 100644--- a/app/components/menus/FileMenu.tsx+++ b/app/components/menus/FileMenu.tsx@@ -64,7 +64,7 @@ interface Props {openMoveCopyFilesDialog: () => void;openAddRemoveTagsDialog: () => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openFileNatively: (path: string) => void;showInFileManager: (path: string) => void;showNotification: (diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex ba538d36f..f3e25d93d 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -190,7 +190,7 @@ interface Props {autohide?: boolean) => void;reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;uploadFilesAPI: (files: Array<File>,destination: string,@@ -415,7 +415,7 @@ function MainPage(props: Props) {}}Promise.all(promises)- .then(() => props.loadDirectoryContent(props.directoryPath, true))+ .then(() => props.loadDirectoryContent(props.directoryPath, true, true)).catch(error => {console.log('promises', error);});diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsxindex c6a5e8774..465105cbb 100644--- a/app/perspectives/grid-perspective/components/GridPagination.tsx+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx@@ -68,6 +68,7 @@ interface Props {settings; // cache only// eslint-disable-next-line react/no-unused-prop-typesselectedEntries; // cache only+ // setMetaForCurrentDir: (metaFiles: Array<any>) => void;}function GridPagination(props: Props) {@@ -112,6 +113,7 @@ function GridPagination(props: Props) {.then(meta => {metaLoadedLock.current = false;props.setIsMetaLoaded(true);+ // props.setMetaForCurrentDir(meta);const dirEntriesPromises = getDirEntriesPromises();const fileEntriesPromises = getFileEntriesPromises(meta);const thumbs = getThumbs(meta);@@ -383,6 +385,7 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators({+ // setMetaForCurrentDir: AppActions.setMetaForCurrentDir,updateCurrentDirEntries: AppActions.updateCurrentDirEntries,setIsMetaLoaded: AppActions.setIsMetaLoaded},@@ -397,7 +400,9 @@ const areEqual = (prevProp: Props, nextProp: Props) =>JSON.stringify(prevProp.directories) &&JSON.stringify(nextProp.settings) === JSON.stringify(prevProp.settings) &&JSON.stringify(nextProp.selectedEntries) ===- JSON.stringify(prevProp.selectedEntries);+ JSON.stringify(prevProp.selectedEntries) &&+ JSON.stringify(nextProp.currentDirectoryColor) ===+ JSON.stringify(prevProp.currentDirectoryColor);export default connect(mapStateToProps,diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex 77733a9de..f8a14f40f 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -83,7 +83,7 @@ interface Props {openNextFile: () => any;openPrevFile: () => any;openRenameEntryDialog: () => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openDirectory: (path: string) => void;showInFileManager: (path: string) => void;openFileNatively: (path?: string) => void;@@ -434,7 +434,7 @@ function GridPerspective(props: Props) {props.openFsEntry(fsEntry);} else {console.log('Handle Grid cell db click, selected path : ', fsEntry.path);- props.loadDirectoryContent(fsEntry.path, true);+ props.loadDirectoryContent(fsEntry.path, true, true);}};diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex 2f6a28089..5fb7f1a1f 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -83,7 +83,7 @@ interface Props {openNextFile: () => any;openPrevFile: () => any;openRenameEntryDialog: () => void;- loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openDirectory: (path: string) => void;showInFileManager: (path: string) => void;openFileNatively: (path?: string) => void;@@ -435,7 +435,7 @@ const GridPerspective = (props: Props) => {// props.openFsEntry(fsEntry);} else {console.log('Handle Grid cell db click, selected path : ', fsEntry.path);- props.loadDirectoryContent(fsEntry.path, true);+ props.loadDirectoryContent(fsEntry.path, true, true);}};diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 571cc4bf5..3fc04b211 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -28,7 +28,8 @@ import {prepareDirectoryContent,findExtensionsForEntry,getNextFile,- getPrevFile+ getPrevFile,+ loadJSONFile} from '-/services/utils-io';import {extractFileExtension,@@ -40,7 +41,8 @@ import {extractTagsAsObjects,normalizePath,extractContainingDirectoryPath,- getLocationPath+ getLocationPath,+ getMetaFileLocationForDir} from '-/utils/paths';import {formatDateTime4Tag,@@ -934,6 +936,48 @@ export const actions = {type: types.SET_ISLOADING,isLoading}),+ /* setMetaForCurrentDir: (metaFiles: Array<any>) => (+ dispatch: (action: any) => void,+ getState: () => any+ ) => {+ const state = getState();+ const {+ currentDirectoryPath,+ currentDirectoryColor,+ currentDirectoryPerspective+ } = state.app;+ if (+ metaFiles.some(metaFile => metaFile.path === AppConfig.metaFolderFile)+ // && !props.currentDirectoryColor+ ) {+ const metaFilePath = getMetaFileLocationForDir(+ currentDirectoryPath,+ PlatformIO.getDirSeparator()+ );+ loadJSONFile(metaFilePath)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ if (+ fsEntryMeta.color &&+ currentDirectoryColor !== fsEntryMeta.color+ ) {+ dispatch(actions.setCurrentDirectoryColor(fsEntryMeta.color));+ }+ if (+ fsEntryMeta.perspective &&+ fsEntryMeta.perspective !== PerspectiveIDs.UNSPECIFIED &&+ currentDirectoryPerspective !== fsEntryMeta.perspective+ ) {+ dispatch(+ actions.setCurrentDirectoryPerspective(fsEntryMeta.perspective)+ );+ }+ return fsEntryMeta;+ })+ .catch(err => {+ console.error(err);+ });+ }+ }, */loadParentDirectoryContent: () => (dispatch: (actions: Object) => void,getState: () => any@@ -1028,8 +1072,8 @@ export const actions = {loadDirectoryContent: (directoryPath: string,generateThumbnails: boolean,- loadDirMeta: boolean = false- ) => async (dispatch: (actions: Object) => void, getState: () => any) => {+ loadDirMeta = false+ ) => async (dispatch: (action: any) => void, getState: () => any) => {// console.debug('loadDirectoryContent:' + directoryPath);window.walkCanceled = false;@@ -1042,9 +1086,14 @@ export const actions = {}if (loadDirMeta) {try {- const fsEntryMeta = await loadMetaDataPromise(- normalizePath(directoryPath) + PlatformIO.getDirSeparator()+ const metaFilePath = getMetaFileLocationForDir(+ directoryPath,+ PlatformIO.getDirSeparator());+ const fsEntryMeta = await loadJSONFile(metaFilePath);+ /* const fsEntryMeta = await loadMetaDataPromise(+ normalizePath(directoryPath) + PlatformIO.getDirSeparator()+ ); */// console.debug('Loading meta succeeded for:' + directoryPath);dispatch(actions.loadDirectoryContentInt(@@ -1053,14 +1102,6 @@ export const actions = {fsEntryMeta));- /* if (fsEntryMeta.color) { // TODO rethink this states changes are expensive- dispatch(actions.setCurrentDirectoryColor(fsEntryMeta.color));- }- if (fsEntryMeta.perspective) {- dispatch(actions.setCurrentDirPerspective(fsEntryMeta.perspective));- } */-- // return true;} catch (err) {console.debug('Error loading meta of:' + directoryPath + ' ' + err);dispatch(