Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix EntryContainer reload

stanimir30fd1b8f6a92
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index c16bb8062..f80311b77 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -40,7 +40,6 @@ import DeleteIcon from '@material-ui/icons/Delete';
import ShareIcon from '@material-ui/icons/Share';
import { withStyles } from '@material-ui/core/styles';
import RefreshIcon from '@material-ui/icons/Refresh';
-import memoize from 'memoize-one';
import EntryProperties from '-/components/EntryProperties';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import AppConfig from '-/config';
@@ -52,7 +51,6 @@ import {
extractContainingDirectoryPath,
extractTitle,
extractFileExtension,
- extractTagsAsObjects,
baseName,
extractFileName,
extractDirectoryName
@@ -66,7 +64,6 @@ import TaggingActions from '-/reducers/tagging-actions';
import {
OpenedEntry,
NotificationTypes,
- getOpenedFiles,
isReadOnlyMode,
getDirectoryContent,
actions as AppActions
@@ -203,11 +200,11 @@ interface Props {
}
const EntryContainer = (props: Props) => {
- const entry = props.openedFiles.length > 0 ? props.openedFiles[0] : undefined;
- if (!entry) {
+ if (props.openedFiles.length === 0) {
return null;
}
- const [currentEntry, setCurrentEntry] = useState<OpenedEntry>(entry);
+ const openedFile = props.openedFiles[0];
+ const [currentEntry, setCurrentEntry] = useState<OpenedEntry>(openedFile);
const [isPropertiesPanelVisible, setPropertiesPanelVisible] = useState<
boolean
@@ -261,7 +258,6 @@ const EntryContainer = (props: Props) => {
useEffect(() => {
if (props.openedFiles.length > 0) {
- const openedFile = props.openedFiles[0];
// / setPropertiesPanelVisible
if (!openedFile.isFile) {
// always open for dirs
@@ -287,25 +283,9 @@ const EntryContainer = (props: Props) => {
...openedFile,
tags
}); */
- } else {
- setCurrentEntry(null);
}
}, [props.openedFiles, props.isReadOnlyMode, props.settings]);
- useEffect(() => {
- if (props.openedFiles && props.openedFiles.length > 0) {
- setCurrentEntry(props.openedFiles[0]);
- } else {
- setCurrentEntry(undefined);
- }
- }, [props.openedFiles]);
-
- useEffect(() => {
- if (currentEntry === null) {
- props.closeAllFiles();
- }
- }, [currentEntry]);
-
useEffect(() => {
if (props.settings.entryPropertiesSplitSize === defaultSplitSize) {
props.setEntryPropertiesSplitSize(openedSplitSize);
@@ -315,7 +295,7 @@ const EntryContainer = (props: Props) => {
// isPropertiesEditMode = false; // TODO rethink this! why exist?
// let isChanged = false;
- let shouldReload = false;
+ // let shouldReload = false;
// logEventsFromExtensions = event => {
// console.log('Ext. Logging >>> ', event.message);
@@ -347,9 +327,9 @@ const EntryContainer = (props: Props) => {
editFile();
break;
case 'playbackEnded':
- nextFilePath = props.getNextFile(currentEntry.path);
+ nextFilePath = props.getNextFile(openedFile.path);
nextFile = props.directoryContent.filter(
- (entry: any) => entry.path === nextFilePath
+ (dirEntry: any) => dirEntry.path === nextFilePath
);
props.openFile(nextFilePath);
props.setLastSelectedEntry(nextFilePath);
@@ -373,10 +353,10 @@ const EntryContainer = (props: Props) => {
props.openFileNatively(data.link);
break;
case 'loadDefaultTextContent':
- if (!currentEntry || !currentEntry.path) {
+ if (!openedFile || !openedFile.path) {
break;
}
- textFilePath = currentEntry.path;
+ textFilePath = openedFile.path;
// TODO make loading index.html for folders configurable
// if (!this.state.currentEntry.isFile) {
// textFilePath += '/index.html';
@@ -428,11 +408,9 @@ const EntryContainer = (props: Props) => {
break;
case 'contentChangedInEditor': {
if (currentEntry.editMode && !currentEntry.changed) {
- // !isChanged) {
- // isChanged = true;
- // dummy state change to rerender for DOT before file name (only first time)
+ // dummy state change to render DOT before file name (only first time)
setCurrentEntry({
- ...currentEntry,
+ ...openedFile,
changed: true
});
}
@@ -451,10 +429,11 @@ const EntryContainer = (props: Props) => {
if (currentEntry.changed) {
setSaveBeforeReloadConfirmDialogOpened(true);
} else {
- shouldReload = true;
+ // shouldReload = true;
setCurrentEntry({
- ...currentEntry,
- editMode: false
+ ...openedFile,
+ editMode: false,
+ shouldReload: true
});
}
}
@@ -487,8 +466,7 @@ const EntryContainer = (props: Props) => {
};
const closeFile = () => {
- // isChanged = false;
- setCurrentEntry(null);
+ props.closeAllFiles();
setEditingSupported(false);
};
@@ -512,13 +490,14 @@ const EntryContainer = (props: Props) => {
};
const saveFile = (textContent: string) => {
- PlatformIO.saveTextFilePromise(currentEntry.path, textContent, true)
+ PlatformIO.saveTextFilePromise(openedFile.path, textContent, true)
.then(result => {
// isChanged = false;
setCurrentEntry({
- ...currentEntry,
+ ...openedFile,
editMode: false,
- changed: false
+ changed: false,
+ shouldReload: false
});
props.showNotification(
i18n.t('core:fileSavedSuccessfully'),
@@ -531,12 +510,12 @@ const EntryContainer = (props: Props) => {
i18n.t('core:errorSavingFile'),
NotificationTypes.error
);
- console.log('Error saving file ' + currentEntry.path + ' - ' + error);
+ console.log('Error saving file ' + openedFile.path + ' - ' + error);
});
};
const editFile = () => {
- setCurrentEntry({ ...currentEntry, editMode: true });
+ setCurrentEntry({ ...openedFile, editMode: true });
};
const shareFile = (filePath: string) => {
@@ -620,10 +599,10 @@ const EntryContainer = (props: Props) => {
};
const openNextFile = () => {
- if (currentEntry && currentEntry.path) {
- const nextFilePath = props.getNextFile(currentEntry.path);
+ if (openedFile.path) {
+ const nextFilePath = props.getNextFile(openedFile.path);
const nextFile = props.directoryContent.filter(
- (entry: FileSystemEntry) => entry.path === nextFilePath
+ (dirEntry: FileSystemEntry) => dirEntry.path === nextFilePath
);
props.openFile(nextFilePath);
props.setLastSelectedEntry(nextFilePath);
@@ -632,10 +611,10 @@ const EntryContainer = (props: Props) => {
};
const openPrevFile = () => {
- if (currentEntry && currentEntry.path) {
- const prevFilePath = props.getPrevFile(currentEntry.path);
+ if (openedFile.path) {
+ const prevFilePath = props.getPrevFile(openedFile.path);
const prevFile = props.directoryContent.filter(
- (entry: FileSystemEntry) => entry.path === prevFilePath
+ (dirEntry: FileSystemEntry) => dirEntry.path === prevFilePath
);
props.openFile(prevFilePath);
props.setLastSelectedEntry(prevFilePath);
@@ -644,8 +623,8 @@ const EntryContainer = (props: Props) => {
};
const openNatively = () => {
- if (currentEntry) {
- props.openFileNatively(currentEntry.path);
+ if (openedFile.path) {
+ props.openFileNatively(openedFile.path);
}
};
@@ -708,7 +687,7 @@ const EntryContainer = (props: Props) => {
title={i18n.t('core:shareFile')}
aria-label={i18n.t('core:shareFile')}
data-tid="shareFile"
- onClick={() => shareFile(`file:///${currentEntry.path}`)}
+ onClick={() => shareFile(`file:///${openedFile.path}`)}
>
<ShareIcon />
</IconButton>
@@ -727,7 +706,7 @@ const EntryContainer = (props: Props) => {
aria-label={i18n.t('core:downloadFile')}
onClick={() => {
const entryName = `${baseName(
- currentEntry.path,
+ openedFile.path,
PlatformIO.getDirSeparator()
)}`;
const fileName = extractFileName(
@@ -736,8 +715,8 @@ const EntryContainer = (props: Props) => {
);
if (AppConfig.isCordova) {
- if (currentEntry.url) {
- downloadCordova(currentEntry.url, entryName);
+ if (openedFile.url) {
+ downloadCordova(openedFile.url, entryName);
} else {
console.log('Can only download HTTP/HTTPS URIs');
props.showNotification(
@@ -757,19 +736,19 @@ const EntryContainer = (props: Props) => {
const { port } = location;
const link = `${protocol}//${hostname}${
port !== '' ? `:${port}` : ''
- }/${currentEntry.path}`;
+ }/${openedFile.path}`;
downloadLink.setAttribute('href', link);
} else {
downloadLink.setAttribute(
'href',
- `file:///${currentEntry.path}`
+ `file:///${openedFile.path}`
);
}
- if (currentEntry.url) {
+ if (openedFile.url) {
// mostly the s3 case
downloadLink.setAttribute('target', '_blank');
- downloadLink.setAttribute('href', currentEntry.url);
+ downloadLink.setAttribute('href', openedFile.url);
}
downloadLink.setAttribute('download', fileName); // works only for same origin
@@ -913,10 +892,10 @@ const EntryContainer = (props: Props) => {
let fileOpenerURL: string;
let fileTitle: string = '';
- if (currentEntry && currentEntry.path) {
+ if (openedFile.path) {
fileTitle = extractTitle(
- currentEntry.path,
- !currentEntry.isFile,
+ openedFile.path,
+ !openedFile.isFile,
PlatformIO.getDirSeparator()
);
// if (fileTitle.length > maxCharactersTitleLength) {
@@ -927,25 +906,21 @@ const EntryContainer = (props: Props) => {
fileOpenerURL =
currentEntry.editingExtensionPath +
'/index.html?file=' +
- encodeURIComponent(
- currentEntry.url ? currentEntry.url : currentEntry.path
- ) +
+ encodeURIComponent(openedFile.url ? openedFile.url : openedFile.path) +
'&locale=' +
i18n.language +
'&edit=true' +
- (shouldReload ? '&t=' + new Date().getTime() : '');
+ (currentEntry.shouldReload ? '&t=' + new Date().getTime() : '');
// } else if (!currentEntry.isFile) { // TODO needed for loading folder's default html
// fileOpenerURL = 'node_modules/@tagspaces/html-viewer/index.html?locale=' + i18n.language;
} else {
fileOpenerURL =
- currentEntry.viewingExtensionPath +
+ openedFile.viewingExtensionPath +
'/index.html?file=' +
- encodeURIComponent(
- currentEntry.url ? currentEntry.url : currentEntry.path
- ) +
+ encodeURIComponent(openedFile.url ? openedFile.url : openedFile.path) +
'&locale=' +
i18n.language +
- (shouldReload ? '&t=' + new Date().getTime() : '');
+ (currentEntry.shouldReload ? '&t=' + new Date().getTime() : '');
}
// this.shouldReload = false;
@@ -968,7 +943,7 @@ const EntryContainer = (props: Props) => {
function getSplitPanelSize() {
if (isPropertiesPanelVisible) {
- return currentEntry && currentEntry.isFile
+ return openedFile.isFile
? props.settings.entryPropertiesSplitSize
: '100%';
}
@@ -1026,12 +1001,13 @@ const EntryContainer = (props: Props) => {
startSavingFile();
} else {
// isChanged = false;
- shouldReload = true;
+ // shouldReload = true;
setSaveBeforeReloadConfirmDialogOpened(false);
setCurrentEntry({
- ...currentEntry,
+ ...openedFile,
editMode: false,
- changed: false
+ changed: false,
+ shouldReload: true
});
}
}}
@@ -1045,25 +1021,25 @@ const EntryContainer = (props: Props) => {
setDeleteEntryModalOpened(false);
}}
title={
- currentEntry && currentEntry.isFile
+ openedFile.isFile
? i18n.t('core:deleteConfirmationTitle')
: i18n.t('core:deleteDirectory')
}
content={
- currentEntry && currentEntry.isFile
+ openedFile.isFile
? i18n.t('core:doYouWantToDeleteFile')
: i18n.t('core:deleteDirectoryContentConfirm', {
- dirPath: currentEntry
+ dirPath: openedFile.path
? extractDirectoryName(
- currentEntry.path,
+ openedFile.path,
PlatformIO.getDirSeparator()
)
: ''
})
}
confirmCallback={result => {
- if (result && currentEntry) {
- props.deleteFile(currentEntry.path);
+ if (result) {
+ props.deleteFile(openedFile.path);
}
}}
cancelDialogTID="cancelSaveBeforeCloseDialog"
@@ -1076,7 +1052,7 @@ const EntryContainer = (props: Props) => {
addTags={props.addTags}
removeTags={props.removeTags}
removeAllTags={props.removeAllTags}
- selectedEntries={currentEntry ? [currentEntry] : []}
+ selectedEntries={openedFile ? [openedFile] : []}
/>
{/* <a href="#" id="downloadFile">
</a> */}
@@ -1088,14 +1064,10 @@ const EntryContainer = (props: Props) => {
// maxSize={fullSplitSize}
// defaultSize={this.state.entryPropertiesSplitSize}
size={getSplitPanelSize()}
- minSize={
- currentEntry && currentEntry.isFile ? defaultSplitSize : '100%'
- }
- maxSize={currentEntry && currentEntry.isFile ? fullSplitSize : '100%'}
+ minSize={openedFile.isFile ? defaultSplitSize : '100%'}
+ maxSize={openedFile.isFile ? fullSplitSize : '100%'}
defaultSize={
- currentEntry && currentEntry.isFile
- ? props.settings.entryPropertiesSplitSize
- : '100%'
+ openedFile.isFile ? props.settings.entryPropertiesSplitSize : '100%'
}
onChange={size => {
const propertiesPanelVisible = size > defaultSplitSize;
@@ -1105,25 +1077,25 @@ const EntryContainer = (props: Props) => {
bufferedSplitResize(() => props.setEntryPropertiesSplitSize(size));
}}
>
- {currentEntry ? (
+ {openedFile.path ? (
<div className={classes.panel}>
<div className={classes.toolbar}>
<div className={classes.flexLeft}>
- {currentEntry.isFile ? (
+ {openedFile.isFile ? (
<Button
onClick={togglePanel}
- title={currentEntry.url || currentEntry.path}
+ title={openedFile.url || openedFile.path}
aria-label={i18n.t('core:toggleEntryProperties')}
className={classes.entryNameButton}
>
<div
className={classes.fileBadge}
title={i18n.t('core:toggleEntryProperties')}
- style={{ backgroundColor: currentEntry.color }}
+ style={{ backgroundColor: openedFile.color }}
>
{'.' +
extractFileExtension(
- currentEntry.path,
+ openedFile.path,
PlatformIO.getDirSeparator()
)}
</div>
@@ -1135,7 +1107,7 @@ const EntryContainer = (props: Props) => {
) : (
<Button
onClick={togglePanel}
- title={currentEntry.url || currentEntry.path}
+ title={openedFile.url || openedFile.path}
aria-label={i18n.t('core:toggleEntryProperties')}
className={classes.entryNameButton}
>
@@ -1219,14 +1191,14 @@ const EntryContainer = (props: Props) => {
)}
</div>
<div className={classes.entryProperties}>
- {currentEntry.isFile
+ {openedFile.isFile
? renderFileToolbar(classes)
: renderFolderToolbar()}
<EntryProperties
key={uuidv1()}
// resetState={this.resetState}
// setPropertiesEditMode={this.setPropertiesEditMode}
- entryPath={currentEntry.path}
+ entryPath={openedFile.path}
// entryURL={currentEntry.url}
// openedEntry={openEntry}
// shouldReload={reload}
@@ -1272,7 +1244,6 @@ const EntryContainer = (props: Props) => {
function mapStateToProps(state) {
return {
- openedFiles: getOpenedFiles(state),
settings: state.settings,
isReadOnlyMode: isReadOnlyMode(state),
directoryContent: getDirectoryContent(state),
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 26c06fc19..0bbdda08f 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -55,7 +55,6 @@ import {
isKeysDialogOpened,
isLicenseDialogOpened,
isThirdPartyLibsDialogOpened,
- isFileOpened,
isEntryInFullWidth,
isUpdateAvailable,
getDirectoryPath,
@@ -71,13 +70,15 @@ import {
isCreateFileDialogOpened,
isSettingsDialogOpened,
isReadOnlyMode,
- isProgressOpened
+ isProgressOpened,
+ getOpenedFiles,
+ OpenedEntry
} from '../reducers/app';
import {
actions as LocationIndexActions,
isIndexing
} from '../reducers/location-index';
-import { buffer } from '../utils/misc';
+import { buffer } from '-/utils/misc';
import TargetFileBox from '../components/TargetFileBox';
import AppConfig from '../config';
import buildDesktopMenu from '../services/electron-menus';
@@ -135,7 +136,7 @@ interface Props {
isFirstRun: boolean;
setFirstRun: (isFirstRun: boolean) => void;
isDesktopMode: boolean;
- isFileOpened: boolean;
+ openedFiles: Array<OpenedEntry>;
isIndexing: boolean;
isGeneratingThumbs: boolean;
setGeneratingThumbnails: (isGenerating: boolean) => void;
@@ -336,8 +337,9 @@ class MainPage extends Component<Props, State> {
};
componentWillReceiveProps(nextProps: Props) {
- const isEntryOpenedChanged =
- nextProps.isFileOpened !== this.props.isFileOpened;
+ const isFileOpened = this.props.openedFiles.length > 0;
+ const isFileOpenedNext = nextProps.openedFiles.length > 0;
+ const isEntryOpenedChanged = isFileOpenedNext !== isFileOpened;
const isEntryOpenedFullWidthChanged =
nextProps.isEntryInFullWidth !== this.props.isEntryInFullWidth;
const width =
@@ -348,7 +350,7 @@ class MainPage extends Component<Props, State> {
window.innerHeight ||
document.documentElement.clientHeight ||
body.clientHeight;
- if (nextProps.isFileOpened) {
+ if (isFileOpenedNext) {
if (height > width) {
this.setState({
mainSplitSize: '0%'
@@ -370,7 +372,7 @@ class MainPage extends Component<Props, State> {
});
}
}
- if (!nextProps.isFileOpened && isEntryOpenedChanged) {
+ if (!isFileOpenedNext && isEntryOpenedChanged) {
this.setState({
mainSplitSize: '100%'
});
@@ -418,7 +420,7 @@ class MainPage extends Component<Props, State> {
// console.log('Width: ' + width + ' Height: ' + height);
this.setState({ width, height });
- if (this.props.isFileOpened) {
+ if (this.props.openedFiles.length > 0) {
this.props.setEntryFullWidth(height > width);
}
@@ -463,11 +465,11 @@ class MainPage extends Component<Props, State> {
});
};
- toggleDrawer = () => {
+ /* toggleDrawer = () => {
this.setState({
isDrawerOpened: !this.state.isDrawerOpened
});
- };
+ }; */
skipRelease = () => {
this.props.setUpdateAvailable(false);
@@ -880,7 +882,7 @@ class MainPage extends Component<Props, State> {
windowHeight={this.state.height}
windowWidth={this.state.width}
/>
- <EntryContainer />
+ <EntryContainer openedFiles={this.props.openedFiles} />
</SplitPane>
</SplitPane>
</TargetFileBox>
@@ -919,7 +921,7 @@ class MainPage extends Component<Props, State> {
windowWidth={this.state.width}
showDrawer={this.showDrawer}
/>
- <EntryContainer />
+ <EntryContainer openedFiles={this.props.openedFiles} />
</SplitPane>
</React.Fragment>
)}
@@ -945,7 +947,8 @@ function mapStateToProps(state) {
isIndexing: isIndexing(state),
isReadOnlyMode: isReadOnlyMode(state),
isGeneratingThumbs: isGeneratingThumbs(state),
- isFileOpened: isFileOpened(state),
+ // isFileOpened: isFileOpened(state),
+ openedFiles: getOpenedFiles(state),
isEntryInFullWidth: isEntryInFullWidth(state),
isDesktopMode: getDesktopMode(state),
keyBindings: getKeyBindingObject(state),
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index fb527c384..8c00bc859 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1721,7 +1721,7 @@ export const isOnline = (state: any) => state.app.isOnline;
export const getLastSelectedEntry = (state: any) => state.app.lastSelectedEntry;
export const getSelectedTag = (state: any) => state.app.tag;
export const getSelectedEntries = (state: any) => state.app.selectedEntries;
-export const isFileOpened = (state: any) => state.app.openedFiles.length > 0;
+// export const isFileOpened = (state: any) => state.app.openedFiles.length > 0;
export const isGeneratingThumbs = (state: any) => state.app.isGeneratingThumbs;
// export const isFileDragged = (state: any) => state.app.isFileDragged;
export const isReadOnlyMode = (state: any) => state.app.isReadOnlyMode;