TagSpaces is an offline, open source, document manager with tagging support
fix TSN482 (#1222)
Stanimirbce0db9eba16
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex 3f5a7eaba..84b3837c9 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -318,7 +318,8 @@ const FolderContainer = (props: Props) => {props.showNotification(i18n.t('core:needProVersion'));return;} */- savePerspective(props.currentDirectoryPath, perspectiveId || 'default')+ props.setCurrentDirectoryPerspective(perspectiveId);+ /* savePerspective(props.currentDirectoryPath, perspectiveId || 'default').then((entryMeta: FileSystemEntryMeta) => {props.setCurrentDirectoryPerspective(entryMeta.perspective);return true;@@ -326,7 +327,7 @@ const FolderContainer = (props: Props) => {.catch(error => {console.warn('Error saving perspective for folder ' + error);props.showNotification(i18n.t('Error saving perspective for folder'));- });+ }); */};/* const togglePerspectiveChooserClose = (event?: any) => {diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsxindex 8221da111..96567bfef 100644--- a/app/components/TagLibrary.tsx+++ b/app/components/TagLibrary.tsx@@ -447,6 +447,7 @@ function mapDispatchToProps(dispatch) {moveTag: TagLibraryActions.moveTag,editTagGroup: TagLibraryActions.editTagGroup,deleteTag: TagLibraryActions.deleteTag,+ addTag: TagLibraryActions.addTag,addTags: TaggingActions.addTags,collectTagsFromLocation: TaggingActions.collectTagsFromLocation,openURLExternally: AppActions.openURLExternallydiff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 37fcdcf4b..37839af3d 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -100,7 +100,7 @@ export const types = {REFLECT_RENAME_ENTRY: 'APP/REFLECT_RENAME_ENTRY',REFLECT_CREATE_ENTRY: 'APP/REFLECT_CREATE_ENTRY',// REFLECT_UPDATE_SIDECARTAGS: 'APP/REFLECT_UPDATE_SIDECARTAGS',- REFLECT_UPDATE_SIDECARMETA: 'APP/REFLECT_UPDATE_SIDECARMETA',+ // REFLECT_UPDATE_SIDECARMETA: 'APP/REFLECT_UPDATE_SIDECARMETA',UPDATE_CURRENTDIR_ENTRY: 'APP/UPDATE_CURRENTDIR_ENTRY'};export const perspectives = {@@ -576,7 +576,7 @@ export default (state: any = initialState, action: any) => {})};}- case types.REFLECT_UPDATE_SIDECARMETA: {+ /* case types.REFLECT_UPDATE_SIDECARMETA: {return {...state,currentDirectoryEntries: state.currentDirectoryEntries.map(entry => {@@ -598,7 +598,7 @@ export default (state: any = initialState, action: any) => {};})};- }+ } */case types.CLOSE_ALL_FILES: {// eslint-disable-next-line no-restricted-globalswindow.history.pushState('', 'TagSpaces', location.pathname);@@ -1116,18 +1116,10 @@ export const actions = {newHTMLFileContent.split('<body></body>')[1];}PlatformIO.saveFilePromise(filePath, fileContent, true)- .then(() => {+ .then((fsEntry: FileSystemEntry) => {dispatch(actions.reflectCreateEntry(filePath, true));- getAllPropertiesPromise(filePath)- .then((fsEntry: FileSystemEntry) => {- dispatch(actions.openFsEntry(fsEntry)); // TODO return fsEntry from saveFilePromise and simplify- return true;- })- .catch(error =>- console.warn(- 'Error getting properties for entry: ' + filePath + ' - ' + error- )- );+ dispatch(actions.openFsEntry(fsEntry)); // TODO return fsEntry from saveFilePromise and simplify+dispatch(actions.setLastSelectedEntry(filePath));dispatch(actions.showNotification(@@ -1281,53 +1273,56 @@ export const actions = {fsEntryMeta: any // FileSystemEntryMeta,// isFile: boolean = true) => (dispatch: (actions: Object) => void, getState: () => any) => {- PlatformIO.getPropertiesPromise(entryPath)- .then(entryProps => {- if (entryProps) {- const { supportedFileTypes } = getState().settings;- const { openedFiles } = getState().app;- let entryForOpening: OpenedEntry;- if (openedFiles && openedFiles.length > 0) {- entryForOpening = openedFiles.find(obj => obj.path === entryPath);- }- if (!entryForOpening) {- entryForOpening = findExtensionsForEntry(- supportedFileTypes,- entryPath,- entryProps.isFile+ const { openedFiles } = getState().app;+ if (openedFiles && openedFiles.length > 0) {+ PlatformIO.getPropertiesPromise(entryPath)+ .then(entryProps => {+ if (entryProps) {+ const { supportedFileTypes } = getState().settings;++ let entryForOpening: OpenedEntry = openedFiles.find(+ obj => obj.path === entryPath);- }- if (fsEntryMeta.changed !== undefined) {- entryForOpening.changed = fsEntryMeta.changed;- } /* else {+ if (!entryForOpening) {+ entryForOpening = findExtensionsForEntry(+ supportedFileTypes,+ entryPath,+ entryProps.isFile+ );+ }++ if (fsEntryMeta.changed !== undefined) {+ entryForOpening.changed = fsEntryMeta.changed;+ } /* else {entryForOpening.changed = true;} */- if (fsEntryMeta.editMode !== undefined) {- entryForOpening.editMode = fsEntryMeta.editMode;- }- if (fsEntryMeta.shouldReload !== undefined) {- entryForOpening.shouldReload = fsEntryMeta.shouldReload;- }- if (fsEntryMeta.color) {- entryForOpening.color = fsEntryMeta.color;- }- if (fsEntryMeta.description) {- entryForOpening.description = fsEntryMeta.description;- }- if (fsEntryMeta.perspective) {- entryForOpening.perspective = fsEntryMeta.perspective;+ if (fsEntryMeta.editMode !== undefined) {+ entryForOpening.editMode = fsEntryMeta.editMode;+ }+ if (fsEntryMeta.shouldReload !== undefined) {+ entryForOpening.shouldReload = fsEntryMeta.shouldReload;+ }+ if (fsEntryMeta.color) {+ entryForOpening.color = fsEntryMeta.color;+ }+ if (fsEntryMeta.description) {+ entryForOpening.description = fsEntryMeta.description;+ }+ if (fsEntryMeta.perspective) {+ entryForOpening.perspective = fsEntryMeta.perspective;+ }+ if (fsEntryMeta.tags) {+ entryForOpening.tags = fsEntryMeta.tags;+ }+ dispatch(actions.addToEntryContainer(entryForOpening));}- if (fsEntryMeta.tags) {- entryForOpening.tags = fsEntryMeta.tags;- }- dispatch(actions.addToEntryContainer(entryForOpening));- }- return true;- })- .catch(err => {- console.error('updateOpenedFile ' + entryPath + ' not exist ' + err);- });+ return true;+ })+ .catch(err => {+ console.error('updateOpenedFile ' + entryPath + ' not exist ' + err);+ });+ }},openFsEntry: (fsEntry: FileSystemEntry) => (dispatch: (actions: Object) => void,@@ -1354,10 +1349,10 @@ export const actions = {fsEntry.path,fsEntry.isFile);- if (fsEntry.url) {- entryForOpening.url = fsEntry.url;- } else if (PlatformIO.haveObjectStoreSupport()) {+ if (PlatformIO.haveObjectStoreSupport()) {entryForOpening.url = PlatformIO.getURLforPath(fsEntry.path);+ } else if (fsEntry.url) {+ entryForOpening.url = fsEntry.url;}if (fsEntry.perspective) {entryForOpening.perspective = fsEntry.perspective;@@ -1374,6 +1369,9 @@ export const actions = {if (fsEntry.size) {entryForOpening.size = fsEntry.size;}+ if (fsEntry.isNewFile) {+ entryForOpening.editMode = true;+ }const localePar = getURLParameter(fsEntry.path);let startPar = '?open=' + encodeURIComponent(fsEntry.path);if (localePar && localePar.length > 1) {@@ -1513,22 +1511,22 @@ export const actions = {* @param path* @param entryMeta*/- reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => (+ /* reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => (dispatch: (actions: Object) => void) => {dispatch(actions.reflectUpdateSidecarMetaInt(path, entryMeta));dispatch(LocationIndexActions.reflectUpdateSidecarMeta(path, entryMeta));- },+ }, *//*** @deprecated use updateCurrentDirEntry instead* @param path* @param entryMeta*/- reflectUpdateSidecarMetaInt: (path: string, entryMeta: Object) => ({+ /* reflectUpdateSidecarMetaInt: (path: string, entryMeta: Object) => ({type: types.REFLECT_UPDATE_SIDECARMETA,path,entryMeta- }),+ }), */reflectUpdateSidecarTags: (path: string,tags: Array<Tag>,diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.tsindex 150ae5d87..b7dcb772c 100644--- a/app/reducers/io-actions.ts+++ b/app/reducers/io-actions.ts@@ -203,7 +203,10 @@ const actions = {normalizePath(targetPath) +PlatformIO.getDirSeparator() +decodeURIComponent(file.name);- if (PlatformIO.haveObjectStoreSupport() && filePath.startsWith('/')) {+ if (+ PlatformIO.haveObjectStoreSupport() &&+ (filePath.startsWith('\\') || filePath.startsWith('/'))+ ) {filePath = filePath.substr(1);}reader.onload = (event: any) => {@@ -303,15 +306,17 @@ const actions = {) {target = target.substr(1);}- uploadJobs.push([path, target]);+ uploadJobs.push([path, target, 'file']);// copy metauploadJobs.push([getMetaFileLocationForFile(path, AppConfig.dirSeparator),- getMetaFileLocationForFile(target, AppConfig.dirSeparator)+ getMetaFileLocationForFile(target, AppConfig.dirSeparator),+ 'meta']);uploadJobs.push([getThumbFileLocationForFile(path, AppConfig.dirSeparator),- getThumbFileLocationForFile(target, AppConfig.dirSeparator)+ getThumbFileLocationForFile(target, AppConfig.dirSeparator),+ 'thumb']);return true;});@@ -319,6 +324,7 @@ const actions = {// console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));// const file = selection.currentTarget.files[0];const filePath = job[1];+ const fileType = job[2];/* normalizePath(props.directoryPath) +PlatformIO.getDirSeparator() +decodeURIComponent(file.name); */@@ -350,18 +356,19 @@ const actions = {onUploadProgress).then((fsEntry: FileSystemEntry) => {- if (filePath.indexOf('.ts/') !== -1) {- // handle meta file TODO catch thumb- if (fsEntry.path.endsWith('.json')) {- try {- // eslint-disable-next-line no-param-reassign- fsEntry.meta = loadJSONString(- fileContent.toString()- );- } catch (e) {- console.debug('cannot parse entry meta');- }+ // handle meta files+ if (fileType === 'meta') {+ try {+ // eslint-disable-next-line no-param-reassign+ fsEntry.meta = loadJSONString(+ fileContent.toString()+ );+ } catch (e) {+ console.debug('cannot parse entry meta');}+ } else if (fileType === 'thumb') {+ // eslint-disable-next-line no-param-reassign+ fsEntry.thumbPath = fsEntry.path;}return fsEntry;@@ -400,22 +407,14 @@ const actions = {filesProm.map(file => {if (file) {- if (file.path.indexOf('.ts/') === -1) {- arrFiles.push(file); // enhanceEntry(file));- } else if (file.meta) {+ if (file.meta) {arrMeta.push(file);- } else {+ } else if (file.thumbPath) {arrThumb.push(file);+ } else {+ arrFiles.push(file);}}- /* if (file !== undefined) {- // dispatch(AppActions.reflectCreateEntryInt(entryEnhanced));- const metaFileProps = await PlatformIO.getPropertiesPromise(metaFilePath);- if (metaFileProps.isFile) {- entryProps.meta = await loadJSONFile(metaFilePath);- }- arrFiles.push(enhanceEntry(file)); // TODO optimize and Enhance Entry with uploaded .ts metafiles- } */return true;});dispatch(@@ -434,14 +433,27 @@ const actions = {const metaFilePath = getMetaFileLocationForFile(file.path,AppConfig.dirSeparator- );+ ).replace(/[/\\]/g, '');+ const thumbFilePath = getThumbFileLocationForFile(+ file.path,+ AppConfig.dirSeparator+ ).replace(/[/\\]/g, '');for (let i = 0; i < arrMeta.length; i += 1) {const metaFile = arrMeta[i];- if (metaFile.path === metaFilePath) {+ if (metaFile.path.replace(/[/\\]/g, '') === metaFilePath) {// eslint-disable-next-line no-param-reassignfile.meta = metaFile.meta;}}+ for (let i = 0; i < arrThumb.length; i += 1) {+ const thumbFile = arrThumb[i];+ if (thumbFile.path.replace(/[/\\]/g, '') === thumbFilePath) {+ // eslint-disable-next-line no-param-reassign+ file.thumbPath = PlatformIO.getURLforPath(+ thumbFile.thumbPath+ );+ }+ }if (file.meta) {return enhanceEntry(file);}diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.tsindex 7920f70db..e95f5755a 100644--- a/app/reducers/tagging-actions.ts+++ b/app/reducers/tagging-actions.ts@@ -170,15 +170,19 @@ const actions = {};saveMetaDataPromise(path, updatedFsEntryMeta).then(() => {- /* dispatch(- AppActions.reflectUpdateSidecarTags(path, newTags, updateIndex)- ); */dispatch(- AppActions.updateOpenedFile(path, {- tags: newTags,- changed: true- })+ // TODO rethink this updateCurrentDirEntry and not need for KanBan+ AppActions.reflectUpdateSidecarTags(path, newTags, updateIndex));+ const { openedFiles } = getState().app;+ if (openedFiles.find(obj => obj.path === path)) {+ dispatch(+ AppActions.updateOpenedFile(path, {+ tags: newTags,+ changed: true+ })+ );+ }return true;}).catch(err => {@@ -197,11 +201,15 @@ const actions = {saveMetaDataPromise(path, newFsEntryMeta).then(() => {dispatch(- AppActions.updateOpenedFile(path, { tags, changed: true })- );- /* dispatch(+ // TODO rethink this updateCurrentDirEntry and not need for KanBanAppActions.reflectUpdateSidecarTags(path, tags, updateIndex)- ); */+ );+ const { openedFiles } = getState().app;+ if (openedFiles.find(obj => obj.path === path)) {+ dispatch(+ AppActions.updateOpenedFile(path, { tags, changed: true })+ );+ }return true;}).catch(error => {@@ -238,8 +246,9 @@ const actions = {extractedTags.push(uniqueTags[i].title);}const newFilePath =- containingDirectoryPath +- PlatformIO.getDirSeparator() ++ (containingDirectoryPath+ ? containingDirectoryPath + PlatformIO.getDirSeparator()+ : '') +generateFileName(fileName, extractedTags, settings.tagDelimiter);dispatch(AppActions.renameFile(path, newFilePath));}@@ -263,8 +272,9 @@ const actions = {}}const newFilePath =- containingDirectoryPath +- PlatformIO.getDirSeparator() ++ (containingDirectoryPath+ ? containingDirectoryPath + PlatformIO.getDirSeparator()+ : '') +generateFileName(fileName, extractedTags, settings.tagDelimiter);if (path !== newFilePath) {dispatch(AppActions.renameFile(path, newFilePath));@@ -559,8 +569,9 @@ const actions = {}}const newFilePath =- containingDirectoryPath +- PlatformIO.getDirSeparator() ++ (containingDirectoryPath+ ? containingDirectoryPath + PlatformIO.getDirSeparator()+ : '') +generateFileName(fileName, extractedTags, settings.tagDelimiter);if (path !== newFilePath) {dispatch(AppActions.renameFile(path, newFilePath));@@ -639,8 +650,9 @@ const actions = {fileExt = '.' + fileExt;}const newFilePath =- containingDirectoryPath +- PlatformIO.getDirSeparator() ++ (containingDirectoryPath+ ? containingDirectoryPath + PlatformIO.getDirSeparator()+ : '') +fileTitle +fileExt;dispatch(AppActions.renameFile(path, newFilePath));diff --git a/app/services/platform-io.ts b/app/services/platform-io.tsindex 17ea6be0f..d612fa5d6 100644--- a/app/services/platform-io.ts+++ b/app/services/platform-io.ts@@ -121,6 +121,7 @@ export default class PlatformIO {return objectStoreAPI.getURLforPath(path);}// console.log('getURLforPath not supported');+ return path;};static createDirectoryTree = (directoryPath: string): Object =>diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 07ea5a141..0a6c5ed12 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -387,6 +387,8 @@ export function loadJSONString(jsonContent: string) {const UTF8_BOM = '\ufeff';if (jsonContent.indexOf(UTF8_BOM) === 0) {json = jsonContent.substring(1, jsonContent.length);+ } else {+ json = jsonContent;}try {jsonObject = JSON.parse(json);