TagSpaces is an offline, open source, document manager with tagging support
reflecting changing of meta infos like description in file and search indexes
Ilian Sapundshiev74c127e2bbca
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.jsindex 9cc759754..75ba2da42 100644--- a/app/components/EntryContainer.js+++ b/app/components/EntryContainer.js@@ -23,7 +23,6 @@ import { bindActionCreators } from 'redux';import { HotKeys } from 'react-hotkeys';import Button from '@material-ui/core/Button';import IconButton from '@material-ui/core/IconButton';-import EditIcon from '@material-ui/icons/Edit';import uuidv1 from 'uuid';import SaveIcon from '@material-ui/icons/Save';import CloseIcon from '@material-ui/icons/Close';@@ -167,7 +166,8 @@ type Props = {deleteFile: (path: string) => void,toggleEntryFullWidth: () => void,isReadOnlyMode: boolean,- setEntryPropertiesSplitSize: (size: number) => void+ setEntryPropertiesSplitSize: (size: number) => void,+ reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => void};type State = {@@ -1071,26 +1071,18 @@ class EntryContainer extends React.Component<Props, State> {resetState={this.resetState}entryPath={currentEntry.path}shouldReload={currentEntry.shouldReload}- addTags={this.props.addTags}renameFile={this.props.renameFile}renameDirectory={this.props.renameDirectory}- removeTags={this.props.removeTags}editTagForEntry={this.props.editTagForEntry}settings={this.props.settings}deleteFile={this.props.deleteFile}- showNotification={this.props.showNotification}shouldCopyFile={this.state.shouldCopyFile}normalizeShouldCopyFile={() => this.setState({ shouldCopyFile: false })}- onEditTags={() => {- const tags = extractTagsAsObjects(currentEntry.path, this.props.settings.tagDelimiter);- this.setState({- selectedItem: {- ...currentEntry,- tags- },- isEditTagsModalOpened: true- });- }}+ addTags={this.props.addTags}+ removeTags={this.props.removeTags}+ removeAllTags={this.props.removeAllTags}+ reflectUpdateSidecarMeta={this.props.reflectUpdateSidecarMeta}+ showNotification={this.props.showNotification}/></div></div>@@ -1147,8 +1139,9 @@ function mapActionCreatorsToProps(dispatch) {toggleEntryFullWidth: AppActions.toggleEntryFullWidth,addTags: TaggingActions.addTags,removeTags: TaggingActions.removeTags,- editTagForEntry: TaggingActions.editTagForEntry,removeAllTags: TaggingActions.removeAllTags,+ editTagForEntry: TaggingActions.editTagForEntry,+ reflectUpdateSidecarMeta: AppActions.reflectUpdateSidecarMeta,}, dispatch);}diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.jsindex 127a4e91c..239d94d25 100644--- a/app/components/EntryProperties.js+++ b/app/components/EntryProperties.js@@ -19,8 +19,6 @@import React, { Component } from 'react';import marked from 'marked';-import { bindActionCreators } from 'redux';-import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';import Grid from '@material-ui/core/Grid';import FormControl from '@material-ui/core/FormControl';@@ -39,9 +37,7 @@ import { formatFileSize } from '../utils/misc';import { extractContainingDirectoryPath } from '../utils/paths';import AppConfig from '../config';import { Pro } from '../pro';-import PlatformIO from '../services/platform-io';import TagsSelect from './TagsSelect';-import TaggingActions from '../reducers/tagging-actions';const styles = theme => ({entryProperties: {@@ -141,14 +137,14 @@ marked.setOptions({xhtml: true});-function handleExternalLinks(event) { // TODO move to misc- event.preventDefault();- event.stopPropagation();- console.log(event.currentTarget.href);+// function handleExternalLinks(event) { // TODO move to misc+// event.preventDefault();+// event.stopPropagation();+// console.log(event.currentTarget.href);- // TODO evtl. use openFileNatively from app.js- PlatformIO.openUrl(event.currentTarget.href);-}+// // TODO evtl. use openFileNatively from app.js+// PlatformIO.openUrl(event.currentTarget.href);+// }type Props = {classes: Object,@@ -157,11 +153,11 @@ type Props = {settings: Object,shouldCopyFile?: boolean,editTagForEntry: () => void,- onEditTags: () => void,renameFile: () => void,renameDirectory: () => void,normalizeShouldCopyFile: () => void,showNotification: () => void,+ reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => void,addTags: () => void,removeTags: () => void,removeAllTags: () => void,@@ -215,10 +211,6 @@ class EntryProperties extends Component<Props, State> {this.loadEntryProperties(nextProps.entryPath);}- /* if (nextProps.entryPath && this.state.path !== nextProps.entryPath) {- this.setState({ isEditDescription: false }); // state is reset isEditDescription default value is false- } */-if (nextProps.shouldCopyFile) {this.setState({ isMoveCopyFilesDialogOpened: true });}@@ -328,12 +320,14 @@ class EntryProperties extends Component<Props, State> {return;}if (this.state.isEditDescription) {- Pro.MetaOperations.saveDescription(this.props.entryPath, this.state.description).then(() => {+ Pro.MetaOperations.saveDescription(this.props.entryPath, this.state.description).then((entryMeta) => {this.setState({isEditDescription: false});+ this.props.reflectUpdateSidecarMeta(this.props.entryPath, entryMeta);return true;}).catch((error) => {+ console.warn('Error saving description ' + error);this.setState({isEditDescription: false});@@ -408,21 +402,14 @@ class EntryProperties extends Component<Props, State> {return tag;});}-- /* this.setState({ //not needed addTags/removeTags/removeAllTags => reflectUpdateSidecarTags -> state is updated -> loadEntryProperties- tags: value- }); */};render() {const {classes,entryPath,- onEditTags,removeTags,editTagForEntry,- copyFiles,- moveFiles} = this.props;const {path,@@ -520,16 +507,7 @@ class EntryProperties extends Component<Props, State> {{i18n.t('core:fileTags')}</Typography></div>- <div className="grid-item">- {/* <Button- color="primary"- data-tid="ok"- className={classes.button}- onClick={onEditTags}- >- {i18n.t('core:addEntryTags')}- </Button> */}- </div>+ <div className="grid-item" /></div><Paper className={classes.tags}><TagDropContainer entryPath={path}>@@ -742,9 +720,4 @@ class EntryProperties extends Component<Props, State> {}}-function mapDispatchToProps(dispatch) {- return bindActionCreators({ addTags: TaggingActions.addTags, removeTags: TaggingActions.removeTags, removeAllTags: TaggingActions.removeAllTags }, dispatch);-}-export default withStyles(styles)(- connect(undefined, mapDispatchToProps)(EntryProperties)-);+export default withStyles(styles)(EntryProperties);diff --git a/app/reducers/app.js b/app/reducers/app.jsindex 3fe373c31..76c79c144 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -77,7 +77,8 @@ export const types = {REFLECT_DELETE_ENTRY: 'APP/REFLECT_DELETE_ENTRY',REFLECT_RENAME_ENTRY: 'APP/REFLECT_RENAME_ENTRY',REFLECT_CREATE_ENTRY: 'APP/REFLECT_CREATE_ENTRY',- REFLECT_UPDATE_SIDECARTAGS: 'APP/REFLECT_UPDATE_SIDECARTAGS'+ REFLECT_UPDATE_SIDECARTAGS: 'APP/REFLECT_UPDATE_SIDECARTAGS',+ REFLECT_UPDATE_SIDECARMETA: 'APP/REFLECT_UPDATE_SIDECARMETA'};export const NotificationTypes = {@@ -437,6 +438,53 @@ export default (state: Object = initialState, action: Object) => {}return state;}+ case types.REFLECT_UPDATE_SIDECARMETA: {+ let indexForUpdating = -1;+ let indexForUpdatingInOpenedFiles = -1;+ // Updating entries in the current directory+ state.currentDirectoryEntries.forEach((entry, index) => {+ if (entry.path === action.path) {+ indexForUpdating = index;+ }+ });+ state.openedFiles.forEach((entry, index) => {+ if (entry.path === action.path) {+ indexForUpdatingInOpenedFiles = index;+ }+ });+ let directoryEntries = state.currentDirectoryEntries;+ let openedFiles = state.openedFiles;+ if (indexForUpdating >= 0) {+ const updateEntry = {+ ...state.currentDirectoryEntries[indexForUpdating],+ description: action.entryMeta.description+ };+ directoryEntries = [+ ...state.currentDirectoryEntries.slice(0, indexForUpdating),+ updateEntry,+ ...state.currentDirectoryEntries.slice(indexForUpdating + 1)+ ];+ }+ if (indexForUpdatingInOpenedFiles >= 0) {+ const updateEntry = {+ ...state.openedFiles[indexForUpdatingInOpenedFiles],+ shouldReload: true,+ };+ openedFiles = [+ ...state.openedFiles.slice(0, indexForUpdatingInOpenedFiles),+ updateEntry,+ ...state.openedFiles.slice(indexForUpdatingInOpenedFiles + 1)+ ];+ }+ if (indexForUpdating >= 0 || indexForUpdatingInOpenedFiles >= 0) {+ return {+ ...state,+ currentDirectoryEntries: directoryEntries,+ openedFiles+ };+ }+ return state;+ }case types.CLOSE_ALL_FILES: {return {...state,@@ -1036,12 +1084,23 @@ export const actions = {path,tags}),+ reflectUpdateSidecarMetaInt: (path: string, entryMeta: Object) => ({+ type: types.REFLECT_UPDATE_SIDECARMETA,+ path,+ entryMeta+ }),reflectUpdateSidecarTags: (path: string, tags: Array<Tags>) => (dispatch: (actions: Object) => void) => {dispatch(actions.reflectUpdateSidecarTagsInt(path, tags));dispatch(LocationIndexActions.reflectUpdateSidecarTags(path, tags));},+ reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => (+ dispatch: (actions: Object) => void+ ) => {+ dispatch(actions.reflectUpdateSidecarMetaInt(path, entryMeta));+ dispatch(LocationIndexActions.reflectUpdateSidecarMeta(path, entryMeta));+ },deleteFile: (filePath: string) => (dispatch: (actions: Object) => void,getState: () => Objectdiff --git a/app/reducers/location-index.js b/app/reducers/location-index.jsindex 2fcc5d53c..7ca9d908c 100644--- a/app/reducers/location-index.js+++ b/app/reducers/location-index.js@@ -44,6 +44,7 @@ export const types = {REFLECT_CREATE_ENTRY: 'REFLECT_CREATE_ENTRY',REFLECT_RENAME_ENTRY: 'REFLECT_RENAME_ENTRY',REFLECT_UPDATE_SIDECARTAGS: 'REFLECT_UPDATE_SIDECARTAGS',+ REFLECT_UPDATE_SIDECARMETA: 'REFLECT_UPDATE_SIDECARMETA'};@@ -160,7 +161,6 @@ export default (state: Object = initialState, action: Object) => {indexForUpdatingInIndex = index;}});- let directoryIndex = state.currentDirectoryIndex;if (indexForUpdatingInIndex >= 0) {const updateEntry = {...state.currentDirectoryIndex[indexForUpdatingInIndex],@@ -169,16 +169,36 @@ export default (state: Object = initialState, action: Object) => {...action.tags]};- directoryIndex = [- ...state.currentDirectoryIndex.slice(0, indexForUpdatingInIndex),- updateEntry,- ...state.currentDirectoryIndex.slice(indexForUpdatingInIndex + 1)- ];+ return {+ ...state,+ currentDirectoryIndex: [+ ...state.currentDirectoryIndex.slice(0, indexForUpdatingInIndex),+ updateEntry,+ ...state.currentDirectoryIndex.slice(indexForUpdatingInIndex + 1)+ ]+ };}+ return state;+ }+ case types.REFLECT_UPDATE_SIDECARMETA: {+ let indexForUpdatingInIndex = -1;+ state.currentDirectoryIndex.forEach((entry, index) => {+ if (entry.path === action.path) {+ indexForUpdatingInIndex = index;+ }+ });if (indexForUpdatingInIndex >= 0) {+ const updateEntry = {+ ...state.currentDirectoryIndex[indexForUpdatingInIndex],+ description: action.entryMeta.description+ };return {...state,- currentDirectoryIndex: directoryIndex+ currentDirectoryIndex: [+ ...state.currentDirectoryIndex.slice(0, indexForUpdatingInIndex),+ updateEntry,+ ...state.currentDirectoryIndex.slice(indexForUpdatingInIndex + 1)+ ]};}return state;@@ -278,6 +298,11 @@ export const actions = {type: types.REFLECT_UPDATE_SIDECARTAGS,path,tags+ }),+ reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => ({+ type: types.REFLECT_UPDATE_SIDECARMETA,+ path,+ entryMeta})};