Skip to content

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

fix replace usage of OpenedEntries with OpenedEntry

sytolkc0e447c01203
diff --git a/src/renderer/components/EditDescription.tsx b/src/renderer/components/EditDescription.tsx
index b50258d3c..5ef895b1a 100644
--- a/src/renderer/components/EditDescription.tsx
+++ b/src/renderer/components/EditDescription.tsx
@@ -28,11 +28,10 @@ const EditDescriptionRoot = styled('div')(({ theme }) => ({
function EditDescription() {
const { t } = useTranslation();
const theme = useTheme();
- const { openedEntries } = useOpenedEntryContext();
+ const { openedEntry } = useOpenedEntryContext();
const { currentDirectoryPath } = useDirectoryContentContext();
const { description, setDescription } = useDescriptionContext();
- const openedFile: OpenedEntry = openedEntries[0];
const fileDescriptionRef = useRef<MilkdownRef>(null);
const [editMode, setEditMode] = useState<boolean>(false);
const descriptionFocus = useRef<boolean>(false);
@@ -67,7 +66,7 @@ function EditDescription() {
const noDescription = !description || description.length < 1;
return (
<EditDescriptionRoot>
- {!openedFile.editMode && (
+ {!openedEntry.editMode && (
<EditDescriptionButtons
buttonsRef={descriptionButtonsRef}
editMode={editMode}
@@ -77,7 +76,7 @@ function EditDescription() {
<div
data-tid="descriptionTID"
onDoubleClick={() => {
- if (!editMode && !openedFile.editMode) {
+ if (!editMode && !openedEntry.editMode) {
setEditMode(true);
}
}}
@@ -99,7 +98,7 @@ function EditDescription() {
}}
>
{t(
- openedFile.editMode
+ openedEntry.editMode
? 'core:editDisabled'
: 'core:addMarkdownDescription',
)}
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 518e45872..0a50946f0 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -82,7 +82,7 @@ function EntryContainer() {
const { t } = useTranslation();
// const dispatch: AppDispatch = useDispatch();
const {
- openedEntries,
+ openedEntry,
closeAllFiles,
updateOpenedFile,
reloadOpenedFile,
@@ -107,8 +107,6 @@ function EntryContainer() {
// const [percent, setPercent] = React.useState<number | undefined>(undefined);
// const percent = useRef<number | undefined>(undefined);
const timer = useRef<NodeJS.Timeout>(null);
- const openedFile = openedEntries[0];
- //const openedFilePath = useRef(openedFile.path);
const openedPanelStyle: React.CSSProperties = {
display: 'flex',
@@ -206,7 +204,7 @@ function EntryContainer() {
}, []);
const toggleFullScreen = useCallback(() => {
- if (openedFile.isFile) {
+ if (openedEntry.isFile) {
if (isFullscreen) {
fscreen.exitFullscreen();
} else {
@@ -217,7 +215,7 @@ function EntryContainer() {
/*useEffect(() => {
// description is saved as Preview
- if (isPropertiesPanelVisible && openedFile.description) {
+ if (isPropertiesPanelVisible && openedEntry.description) {
reloadOpenedFile();
}
}, [isPropertiesPanelVisible]);*/
@@ -238,10 +236,10 @@ function EntryContainer() {
});
useEffect(() => {
- if (openedFile.isAutoSaveEnabled) {
+ if (openedEntry && openedEntry.isAutoSaveEnabled) {
if (fileChanged.current) {
timer.current = setInterval(() => {
- if (openedFile.isAutoSaveEnabled && fileChanged.current) {
+ if (openedEntry.isAutoSaveEnabled && fileChanged.current) {
startSavingFile();
console.debug('autosave');
}
@@ -257,7 +255,7 @@ function EntryContainer() {
clearInterval(timer.current);
}
};
- }, [openedFile.isAutoSaveEnabled, fileChanged.current]);
+ }, [openedEntry, fileChanged.current]);
// editor is not loaded in this time - change theme after loadDefaultTextContent
/*useEffect(() => {
@@ -274,27 +272,28 @@ function EntryContainer() {
}, [settings.currentTheme]);*/
/* useEffect(() => {
- // if (openedFiles.length > 0) {
+ // if (openedEntrys.length > 0) {
if (
!firstRender &&
- // openedFile.editMode &&
- // openedFile.changed &&
+ // openedEntry.editMode &&
+ // openedEntry.changed &&
fileChanged.current
- // openedFile.shouldReload === false
+ // openedEntry.shouldReload === false
) {
setSaveBeforeReloadConfirmDialogOpened(true);
}
- }, [openedFilePath.current, readOnlyMode]);*/
+ }, [openedEntryPath.current, readOnlyMode]);*/
// always open for dirs
- /*const isPropPanelVisible = openedFile.isFile
+ /*const isPropPanelVisible = openedEntry.isFile
? isPropertiesPanelVisible
: true;*/
const editingSupported: boolean =
!readOnlyMode &&
- openedFile.editingExtensionId !== undefined &&
- openedFile.editingExtensionId.length > 3;
+ openedEntry &&
+ openedEntry.editingExtensionId !== undefined &&
+ openedEntry.editingExtensionId.length > 3;
const handleMessage = (data: any) => {
let message;
@@ -322,11 +321,11 @@ function EntryContainer() {
// // openLink(data.link);
// break;
case 'loadDefaultTextContent':
- if (!openedFile || !openedFile.path) {
- // || openedFile.changed) {
+ if (!openedEntry || !openedEntry.path) {
+ // || openedEntry.changed) {
break;
}
- textFilePath = openedFile.path;
+ textFilePath = openedEntry.path;
// TODO setTheme in milkdown v6 editor only
if (
@@ -343,7 +342,7 @@ function EntryContainer() {
// if (!this.state.currentEntry.isFile) {
// textFilePath += '/index.html';
// }
- switchLocationTypeByID(openedFile.locationId).then(
+ switchLocationTypeByID(openedEntry.locationId).then(
(currentLocationId) => {
PlatformIO.loadTextFilePromise(
textFilePath,
@@ -380,7 +379,7 @@ function EntryContainer() {
fileViewer.current.contentWindow.setContent(
content,
fileDirectory,
- !openedFile.editMode,
+ !openedEntry.editMode,
theme.palette.mode,
);
}
@@ -410,46 +409,46 @@ function EntryContainer() {
};
/*const reloadOpenedFile = () => {
- if (openedFile) {
- const metaFilePath = openedFile.isFile
+ if (openedEntry) {
+ const metaFilePath = openedEntry.isFile
? getMetaFileLocationForFile(
- openedFile.path,
+ openedEntry.path,
PlatformIO.getDirSeparator()
)
: getMetaFileLocationForDir(
- openedFile.path,
+ openedEntry.path,
PlatformIO.getDirSeparator()
);
try {
loadJSONFile(metaFilePath)
.then(fsEntryMeta => {
- updateOpenedFile(openedFile.path, {
+ updateOpenedFile(openedEntry.path, {
...fsEntryMeta,
editMode: false,
- shouldReload: !openedFile.shouldReload
+ shouldReload: !openedEntry.shouldReload
});
})
.catch(() =>
- updateOpenedFile(openedFile.path, {
- ...openedFile,
+ updateOpenedFile(openedEntry.path, {
+ ...openedEntry,
editMode: false,
- shouldReload: !openedFile.shouldReload
+ shouldReload: !openedEntry.shouldReload
})
);
} catch (e) {
- updateOpenedFile(openedFile.path, {
- ...openedFile,
+ updateOpenedFile(openedEntry.path, {
+ ...openedEntry,
editMode: false,
- shouldReload: !openedFile.shouldReload
+ shouldReload: !openedEntry.shouldReload
});
}
}
};*/
const reloadDocument = () => {
- if (openedFile) {
- if (openedFile.editMode && fileChanged.current) {
- // openedFile.changed) {
+ if (openedEntry) {
+ if (openedEntry.editMode && fileChanged.current) {
+ // openedEntry.changed) {
setSaveBeforeReloadConfirmDialogOpened(true);
} else {
reloadOpenedFile();
@@ -462,8 +461,8 @@ function EntryContainer() {
event.preventDefault(); // Let's stop this event.
event.stopPropagation();
}
- if (openedFile && fileChanged.current && openedFile.editMode) {
- // openedFile.changed
+ if (openedEntry && fileChanged.current && openedEntry.editMode) {
+ // openedEntry.changed
setSaveBeforeCloseConfirmDialogOpened(true);
} else {
closeFile();
@@ -476,7 +475,7 @@ function EntryContainer() {
};
const startSavingFile = () => {
- if (openedFile.editMode) {
+ if (openedEntry.editMode) {
savingFile();
} else {
saveDescription();
@@ -515,10 +514,10 @@ function EntryContainer() {
};
const override = (): Promise<boolean> => {
- return switchLocationTypeByID(openedFile.locationId).then(() =>
- PlatformIO.getPropertiesPromise(openedFile.path).then(
+ return switchLocationTypeByID(openedEntry.locationId).then(() =>
+ PlatformIO.getPropertiesPromise(openedEntry.path).then(
(entryProp: TS.FileSystemEntry) =>
- save({ ...openedFile, lmdt: entryProp.lmdt }).then(() =>
+ save({ ...openedEntry, lmdt: entryProp.lmdt }).then(() =>
switchCurrentLocationType(),
),
),
@@ -526,25 +525,25 @@ function EntryContainer() {
};
const saveAs = (newFilePath: string): Promise<boolean> => {
- return switchLocationTypeByID(openedFile.locationId).then(() =>
- copyFilePromise(openedFile.path, newFilePath).then(() =>
+ return switchLocationTypeByID(openedEntry.locationId).then(() =>
+ copyFilePromise(openedEntry.path, newFilePath).then(() =>
PlatformIO.getPropertiesPromise(newFilePath).then(
(entryProp: TS.FileSystemEntry) =>
save({
- ...openedFile,
+ ...openedEntry,
path: entryProp.path,
lmdt: entryProp.lmdt,
}).then(() => {
- const openedFileDir = extractContainingDirectoryPath(
+ const openedEntryDir = extractContainingDirectoryPath(
entryProp.path,
);
- if (currentDirectoryPath === openedFileDir) {
- openDirectory(openedFileDir);
+ if (currentDirectoryPath === openedEntryDir) {
+ openDirectory(openedEntryDir);
/*
- updateOpenedFile(openedFile.path, {
- ...openedFile,
+ updateOpenedFile(openedEntry.path, {
+ ...openedEntry,
editMode: false,
- shouldReload: !openedFile.shouldReload
+ shouldReload: !openedEntry.shouldReload
});*/
}
return switchCurrentLocationType();
@@ -555,8 +554,8 @@ function EntryContainer() {
};
const saveFile = (): Promise<boolean> => {
- return switchLocationTypeByID(openedFile.locationId).then(() =>
- save(openedFile).then(() => switchCurrentLocationType()),
+ return switchLocationTypeByID(openedEntry.locationId).then(() =>
+ save(openedEntry).then(() => switchCurrentLocationType()),
);
};
@@ -613,10 +612,10 @@ function EntryContainer() {
}
const editOpenedFile = () => {
- switchLocationTypeByID(openedFile.locationId).then(() => {
- updateOpenedFile(openedFile.path, {
+ switchLocationTypeByID(openedEntry.locationId).then(() => {
+ updateOpenedFile(openedEntry.path, {
id: '',
- ...openedFile,
+ ...openedEntry,
editMode: true,
shouldReload: undefined,
}).then(() => switchCurrentLocationType());
@@ -654,30 +653,31 @@ function EntryContainer() {
};
const openNextFileAction = () => {
window.dispatchEvent(new Event('next-file'));
- //openNextFile(openedFile.path);
+ //openNextFile(openedEntry.path);
};
const openPrevFileAction = () => {
window.dispatchEvent(new Event('previous-file'));
- //openPrevFile(openedFile.path);
+ //openPrevFile(openedEntry.path);
};
- const fileExtension = extractFileExtension(
- openedFile.path,
- PlatformIO.getDirSeparator(),
- );
+ const fileExtension =
+ openedEntry &&
+ extractFileExtension(openedEntry.path, PlatformIO.getDirSeparator());
const isEditable =
- openedFile.isFile && AppConfig.editableFiles.includes(fileExtension);
+ openedEntry &&
+ openedEntry.isFile &&
+ AppConfig.editableFiles.includes(fileExtension);
const toggleAutoSave = (event: React.ChangeEvent<HTMLInputElement>) => {
const autoSave = event.target.checked;
if (Pro && Pro.MetaOperations) {
- switchLocationTypeByID(openedFile.locationId).then(
+ switchLocationTypeByID(openedEntry.locationId).then(
(currentLocationId) => {
- Pro.MetaOperations.saveFsEntryMeta(openedFile.path, {
+ Pro.MetaOperations.saveFsEntryMeta(openedEntry.path, {
autoSave,
}).then((entryMeta) => {
- updateOpenedFile(openedFile.path, entryMeta).then(() =>
+ updateOpenedFile(openedEntry.path, entryMeta).then(() =>
switchCurrentLocationType(),
);
});
@@ -709,8 +709,8 @@ function EntryContainer() {
<Switch
data-tid="autoSaveTID"
checked={
- openedFile.isAutoSaveEnabled !== undefined &&
- openedFile.isAutoSaveEnabled
+ openedEntry.isAutoSaveEnabled !== undefined &&
+ openedEntry.isAutoSaveEnabled
}
onChange={toggleAutoSave}
name="autoSave"
@@ -730,7 +730,7 @@ function EntryContainer() {
let editFile = null;
if (editingSupported) {
- if (openedFile.editMode) {
+ if (openedEntry.editMode) {
editFile = (
<ButtonGroup>
<Tooltip title={t('core:cancelEditing')}>
@@ -792,7 +792,6 @@ function EntryContainer() {
<EntryContainerTabs
isEditable={isEditable}
isPanelOpened={isPanelOpened}
- openedFile={openedFile}
openPanel={openPanel}
toggleProperties={toggleProperties}
marginRight={marginRight}
@@ -830,7 +829,7 @@ function EntryContainer() {
);
};
- if (openedFile.path === undefined) {
+ if (!openedEntry || openedEntry.path === undefined) {
return <div>{t('core:noEntrySelected')}</div>;
}
@@ -896,12 +895,12 @@ function EntryContainer() {
desktopMode={desktopMode}
/>
<EntryContainerNav
- isFile={openedFile.isFile}
+ isFile={openedEntry.isFile}
startClosingEntry={startClosingEntry}
/>
</Box>
{tabs()}
- {openedFile.isFile && isPanelOpened && (
+ {openedEntry.isFile && isPanelOpened && (
<Tooltip title={t('core:togglePreviewSize')}>
<div
style={{
@@ -924,10 +923,9 @@ function EntryContainer() {
</Tooltip>
)}
</div>
- {openedFile.isFile && (
+ {openedEntry.isFile && (
<FileView
key="FileViewID"
- openedFile={openedFile}
isFullscreen={isFullscreen}
fileViewer={fileViewer}
fileViewerContainer={fileViewerContainer}
@@ -972,9 +970,9 @@ function EntryContainer() {
startSavingFile();
} else {
setSaveBeforeReloadConfirmDialogOpened(false);
- updateOpenedFile(openedFile.path, {
+ updateOpenedFile(openedEntry.path, {
id: '',
- ...openedFile,
+ ...openedEntry,
editMode: false,
// changed: false,
shouldReload: true,
@@ -992,14 +990,13 @@ function EntryContainer() {
open={isEditTagsModalOpened}
onClose={() => setEditTagsModalOpened(false)}
selected={
- openedFile ? [toFsEntry(openedFile.path, openedFile.isFile)] : []
+ openedEntry ? [toFsEntry(openedEntry.path, openedEntry.isFile)] : []
}
/>
)}
<ResolveConflictDialog
open={isConflictDialogOpen}
onClose={() => setConflictDialogOpen(false)}
- file={openedFile}
saveAs={saveAs}
override={override}
/>
diff --git a/src/renderer/components/EntryContainerMenu.tsx b/src/renderer/components/EntryContainerMenu.tsx
index ae6585d77..6a2f8e071 100644
--- a/src/renderer/components/EntryContainerMenu.tsx
+++ b/src/renderer/components/EntryContainerMenu.tsx
@@ -45,7 +45,6 @@ import { useIOActionsContext } from '-/hooks/useIOActionsContext';
interface Props {
anchorEl: null | HTMLElement;
handleClose: () => void;
- openedEntry: OpenedEntry;
startClosingEntry: (event) => void;
toggleFullScreen: () => void;
reloadDocument: () => void;
@@ -55,11 +54,11 @@ function EntryContainerMenu(props: Props) {
const {
anchorEl,
handleClose,
- openedEntry,
toggleFullScreen,
reloadDocument,
startClosingEntry,
} = props;
+ const { openedEntry } = useOpenedEntryContext();
const { t } = useTranslation();
// const theme = useTheme();
const {
diff --git a/src/renderer/components/EntryContainerTabs.tsx b/src/renderer/components/EntryContainerTabs.tsx
index 5418ca870..a6b6e4d6a 100644
--- a/src/renderer/components/EntryContainerTabs.tsx
+++ b/src/renderer/components/EntryContainerTabs.tsx
@@ -38,6 +38,7 @@ import {
} from '-/components/CommonIcons';
import EditDescription from '-/components/EditDescription';
import { useTranslation } from 'react-i18next';
+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
interface StyledTabsProps {
children?: React.ReactNode;
@@ -91,7 +92,6 @@ function a11yProps(index: number) {
}
interface EntryContainerTabsProps {
- openedFile: OpenedEntry;
openPanel: () => void;
toggleProperties: () => void;
isEditable: boolean;
@@ -107,7 +107,6 @@ interface TabPanelProps {
function EntryContainerTabs(props: EntryContainerTabsProps) {
const {
- openedFile,
openPanel,
toggleProperties,
marginRight,
@@ -116,6 +115,7 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
} = props;
const { t } = useTranslation();
+ const { openedEntry } = useOpenedEntryContext();
const theme = useTheme();
const tabIndex = useSelector(getEntryContainerTab);
const tileServer = useSelector(getMapTileServer);
@@ -154,7 +154,7 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
};
const handleTabClick = (event: React.SyntheticEvent) => {
if (
- openedFile.isFile &&
+ openedEntry.isFile &&
tabIndex === parseInt(event.currentTarget.id.split('-')[1], 10)
) {
// when selected tab is clicked...
@@ -166,7 +166,7 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
// directories must be always opened
const selectedTabIndex =
- !openedFile.isFile && tabIndex === undefined ? 0 : tabIndex;
+ !openedEntry.isFile && tabIndex === undefined ? 0 : tabIndex;
return (
<div
@@ -177,7 +177,7 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
flexDirection: 'column',
overflow: 'hidden',
borderBottom:
- openedFile.isFile && !isPanelOpened
+ openedEntry.isFile && !isPanelOpened
? '1px solid ' + theme.palette.divider
: 'none',
}}
@@ -214,7 +214,7 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
</StyledTabs>
</Box>
<TsTabPanel value={selectedTabIndex} index={0}>
- <EntryProperties key={openedFile.path} tileServer={tileServer} />
+ <EntryProperties key={openedEntry.path} tileServer={tileServer} />
</TsTabPanel>
<TsTabPanel value={selectedTabIndex} index={1}>
<EditDescription />
diff --git a/src/renderer/components/EntryContainerTitle.tsx b/src/renderer/components/EntryContainerTitle.tsx
index cfe93c70b..7e4f8b15c 100644
--- a/src/renderer/components/EntryContainerTitle.tsx
+++ b/src/renderer/components/EntryContainerTitle.tsx
@@ -73,23 +73,22 @@ function EntryContainerTitle(props: Props) {
} = props;
const { t } = useTranslation();
const theme = useTheme();
- const { openedEntries, sharingLink, sharingParentFolderLink } =
+ const { openedEntry, sharingLink, sharingParentFolderLink } =
useOpenedEntryContext();
const { showNotification } = useNotificationContext();
- const openedFile = openedEntries[0];
const locations = useSelector(getLocations);
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const haveBookmark =
- Pro && Pro.bookmarks && Pro.bookmarks.haveBookmark(openedFile.path);
+ Pro && Pro.bookmarks && Pro.bookmarks.haveBookmark(openedEntry.path);
const bookmarkClick = () => {
if (Pro) {
if (haveBookmark) {
- Pro.bookmarks.delBookmark(openedFile.path);
+ Pro.bookmarks.delBookmark(openedEntry.path);
} else {
- Pro.bookmarks.setBookmark(openedFile.path, sharingLink);
+ Pro.bookmarks.setBookmark(openedEntry.path, sharingLink);
}
forceUpdate();
} else {
@@ -101,28 +100,31 @@ function EntryContainerTitle(props: Props) {
}
};
- let fileTitle: string = openedFile.path
+ let fileTitle: string = openedEntry.path
? extractTitle(
- openedFile.path,
- !openedFile.isFile,
+ openedEntry.path,
+ !openedEntry.isFile,
PlatformIO.getDirSeparator(),
)
: '';
let fileName: string;
- if (openedFile.path) {
- if (openedFile.isFile) {
- fileName = extractFileName(openedFile.path, PlatformIO.getDirSeparator());
+ if (openedEntry.path) {
+ if (openedEntry.isFile) {
+ fileName = extractFileName(
+ openedEntry.path,
+ PlatformIO.getDirSeparator(),
+ );
} else {
fileName = extractDirectoryName(
- openedFile.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
);
}
}
if (!fileName) {
const currentLocation = locations.find(
- (location) => location.uuid === openedFile.locationId,
+ (location) => location.uuid === openedEntry.locationId,
);
if (currentLocation) {
fileName = currentLocation.name;
@@ -135,7 +137,7 @@ function EntryContainerTitle(props: Props) {
paddingLeft: 5,
display: 'flex',
alignItems: 'center',
- marginRight: openedFile.isFile ? 100 : 0,
+ marginRight: openedEntry.isFile ? 100 : 0,
flexDirection: 'row',
flex: '1 1',
overflowX: 'auto',
@@ -146,7 +148,7 @@ function EntryContainerTitle(props: Props) {
WebkitAppRegion: 'drag',
}}
>
- {openedFile.isFile ? (
+ {openedEntry.isFile ? (
<>
{isFileChanged ? (
<Tooltip title={t('core:fileChanged')}>
@@ -173,7 +175,7 @@ function EntryContainerTitle(props: Props) {
setAnchorEl(event.currentTarget);
}}
style={{
- backgroundColor: openedFile.color,
+ backgroundColor: openedEntry.color,
display: 'flex',
alignItems: 'center',
textTransform: 'uppercase',
@@ -185,7 +187,7 @@ function EntryContainerTitle(props: Props) {
{
//'.' +
extractFileExtension(
- openedFile.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
)
}
@@ -216,7 +218,7 @@ function EntryContainerTitle(props: Props) {
<MoreMenuIcon style={{ fontSize: 20 }} />
</FileBadge>
)}
- <Tooltip title={openedFile.isFile && fileName}>
+ <Tooltip title={openedEntry.isFile && fileName}>
<Box
data-tid={'OpenedTID' + dataTidFormat(fileName)}
style={{
@@ -258,12 +260,11 @@ function EntryContainerTitle(props: Props) {
)}
</IconButton>
</ProTooltip>
- <TagsPreview tags={openedFile.tags} />
+ <TagsPreview tags={openedEntry.tags} />
<EntryContainerMenu
anchorEl={anchorEl}
startClosingEntry={startClosingEntry}
handleClose={() => setAnchorEl(null)}
- openedEntry={openedFile}
reloadDocument={reloadDocument}
toggleFullScreen={toggleFullScreen}
/>
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsx
index d149f140f..2d61a0d41 100644
--- a/src/renderer/components/EntryProperties.tsx
+++ b/src/renderer/components/EntryProperties.tsx
@@ -200,7 +200,7 @@ const defaultBackgrounds = [
function EntryProperties(props: Props) {
const { t } = useTranslation();
const theme = useTheme();
- const { currentEntry, dirProps, updateOpenedFile, sharingLink } =
+ const { openedEntry, dirProps, updateOpenedFile, sharingLink } =
useOpenedEntryContext();
const { renameDirectory, renameFile } = useFsActionsContext();
const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();
@@ -225,15 +225,12 @@ function EntryProperties(props: Props) {
const lastBackgroundImageChange = useSelector(getLastBackgroundImageChange);
const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
- const entryName = currentEntry
- ? currentEntry.isFile
- ? extractFileName(currentEntry.path, PlatformIO.getDirSeparator())
- : extractDirectoryName(currentEntry.path, PlatformIO.getDirSeparator())
+ const entryName = openedEntry
+ ? openedEntry.isFile
+ ? extractFileName(openedEntry.path, PlatformIO.getDirSeparator())
+ : extractDirectoryName(openedEntry.path, PlatformIO.getDirSeparator())
: '';
- /*const currentEntry = useRef<OpenedEntry>(
- enhanceOpenedEntry(openedEntry, props.tagDelimiter),
- );*/
const [editName, setEditName] = useState<string>(undefined);
const [isMoveCopyFilesDialogOpened, setMoveCopyFilesDialogOpened] =
useState<boolean>(false);
@@ -275,22 +272,22 @@ function EntryProperties(props: Props) {
const renameEntry = () => {
if (editName !== undefined) {
const path = extractContainingDirectoryPath(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
);
const nextPath = path + PlatformIO.getDirSeparator() + editName;
- switchLocationTypeByID(currentEntry.locationId).then(
+ switchLocationTypeByID(openedEntry.locationId).then(
(currentLocationId) => {
- if (currentEntry.isFile) {
- renameFile(currentEntry.path, nextPath)
+ if (openedEntry.isFile) {
+ renameFile(openedEntry.path, nextPath)
.then(() => switchCurrentLocationType())
.catch(() => {
switchCurrentLocationType();
fileNameRef.current.value = entryName;
});
} else {
- renameDirectory(currentEntry.path, editName)
+ renameDirectory(openedEntry.path, editName)
.then((newDirPath) => switchCurrentLocationType())
.catch(() => {
switchCurrentLocationType();
@@ -322,7 +319,7 @@ function EntryProperties(props: Props) {
const toggleMoveCopyFilesDialog = () => {
/*props.setSelectedEntries([
- { name: '', isFile: true, tags: [], ...currentEntry.current }
+ { name: '', isFile: true, tags: [], ...openedEntry.current }
]);*/
setMoveCopyFilesDialogOpened(!isMoveCopyFilesDialogOpened);
};
@@ -332,7 +329,7 @@ function EntryProperties(props: Props) {
showNotification(t('core:thisFunctionalityIsAvailableInPro'));
return true;
}
- if (!currentEntry.editMode && editName === undefined) {
+ if (!openedEntry.editMode && editName === undefined) {
setFileThumbChooseDialogOpened(!isFileThumbChooseDialogOpened);
}
};
@@ -342,21 +339,21 @@ function EntryProperties(props: Props) {
showNotification(t('core:thisFunctionalityIsAvailableInPro'));
return true;
}
- if (!currentEntry.editMode && editName === undefined) {
+ if (!openedEntry.editMode && editName === undefined) {
setBgndImgChooseDialogOpened(!isBgndImgChooseDialogOpened);
}
};
const setThumb = (filePath, thumbFilePath) => {
if (filePath !== undefined) {
- return switchLocationTypeByID(currentEntry.locationId).then(
+ return switchLocationTypeByID(openedEntry.locationId).then(
(currentLocationId) => {
if (
PlatformIO.haveObjectStoreSupport() ||
PlatformIO.haveWebDavSupport()
) {
updateThumbnailUrl(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getURLforPath(thumbFilePath),
);
return true;
@@ -364,7 +361,7 @@ function EntryProperties(props: Props) {
/*return replaceThumbnailURLPromise(filePath, thumbFilePath)
.then(objUrl => {*/
updateThumbnailUrl(
- currentEntry.path,
+ openedEntry.path,
thumbFilePath,
// objUrl.tmbPath
/*(props.lastThumbnailImageChange
@@ -376,9 +373,9 @@ function EntryProperties(props: Props) {
);
} else {
// reset Thumbnail
- return getThumbnailURLPromise(currentEntry.path)
+ return getThumbnailURLPromise(openedEntry.path)
.then((objUrl) => {
- updateThumbnailUrl(currentEntry.path, objUrl.tmbPath);
+ updateThumbnailUrl(openedEntry.path, objUrl.tmbPath);
return true;
})
.catch((err) => {
@@ -408,38 +405,36 @@ function EntryProperties(props: Props) {
// eslint-disable-next-line no-param-reassign
color = 'transparent';
}
- currentEntry.color = color;
- switchLocationTypeByID(currentEntry.locationId).then(
- (currentLocationId) => {
- Pro.MetaOperations.saveFsEntryMeta(currentEntry.path, { color })
- .then((entryMeta) => {
- if (currentEntry.path === currentDirectoryPath) {
- setDirectoryMeta(entryMeta);
- }
- // for KanBan
- dispatch(
- AppActions.setLastBackgroundColorChange(
- currentEntry.path,
- new Date().getTime(),
- ),
- );
- // todo handle LastBackgroundColorChange and skip updateOpenedFile
- updateOpenedFile(currentEntry.path, entryMeta).then(() =>
- switchCurrentLocationType(),
- );
+ openedEntry.color = color;
+ switchLocationTypeByID(openedEntry.locationId).then((currentLocationId) => {
+ Pro.MetaOperations.saveFsEntryMeta(openedEntry.path, { color })
+ .then((entryMeta) => {
+ if (openedEntry.path === currentDirectoryPath) {
+ setDirectoryMeta(entryMeta);
+ }
+ // for KanBan
+ dispatch(
+ AppActions.setLastBackgroundColorChange(
+ openedEntry.path,
+ new Date().getTime(),
+ ),
+ );
+ // todo handle LastBackgroundColorChange and skip updateOpenedFile
+ updateOpenedFile(openedEntry.path, entryMeta).then(() =>
+ switchCurrentLocationType(),
+ );
- /* } else {
- setCurrentEntry({ ...currentEntry, color });
+ /* } else {
+ setCurrentEntry({ ...openedEntry, color });
} */
- return true;
- })
- .catch((error) => {
- switchCurrentLocationType();
- console.warn('Error saving color for folder ' + error);
- showNotification(t('Error saving color for folder'));
- });
- },
- );
+ return true;
+ })
+ .catch((error) => {
+ switchCurrentLocationType();
+ console.warn('Error saving color for folder ' + error);
+ showNotification(t('Error saving color for folder'));
+ });
+ });
};
const handleFileNameChange = (event: ChangeEvent<HTMLInputElement>) => {
@@ -449,7 +444,7 @@ function EntryProperties(props: Props) {
if (name === 'name') {
const initValid = disableConfirmButton.current;
let noValid;
- if (currentEntry.isFile) {
+ if (openedEntry.isFile) {
noValid = fileNameValidation(value);
} else {
noValid = dirNameValidation(value);
@@ -473,51 +468,51 @@ function EntryProperties(props: Props) {
const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {
const metaFilePath = getMetaFileLocationForFile(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
);
// tmp fix; saving meta sidecar file is not ignored by watcher
ignoreByWatcher(metaFilePath);
- switchLocationTypeByID(currentEntry.locationId)
+ switchLocationTypeByID(openedEntry.locationId)
.then((currentLocationId) => {
if (action === 'remove-value') {
if (!value) {
// no tags left in the select element
- return removeAllTags([currentEntry.path]).then(() =>
- updateOpenedFile(currentEntry.path, {
+ return removeAllTags([openedEntry.path]).then(() =>
+ updateOpenedFile(openedEntry.path, {
id: '',
tags: [],
}),
);
} else {
- return removeTags([currentEntry.path], value);
+ return removeTags([openedEntry.path], value);
}
} else if (action === 'clear') {
- return removeAllTags([currentEntry.path]);
+ return removeAllTags([openedEntry.path]);
}
// create-option or select-option
const tags =
- currentEntry.tags === undefined
+ openedEntry.tags === undefined
? value
: value.filter(
(tag) =>
- !currentEntry.tags.some((obj) => obj.title === tag.title),
+ !openedEntry.tags.some((obj) => obj.title === tag.title),
);
- return addTags([currentEntry.path], tags);
+ return addTags([openedEntry.path], tags);
})
.then(() => {
switchCurrentLocationType().then(() => deignoreByWatcher(metaFilePath));
});
};
- if (!currentEntry || !currentEntry.path || currentEntry.path === '') {
+ if (!openedEntry || !openedEntry.path || openedEntry.path === '') {
return <div />;
}
function getBgndUrl() {
- if (currentEntry && !currentEntry.isFile) {
+ if (openedEntry && !openedEntry.isFile) {
const bgndPath = getBgndFileLocationForDirectory(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
);
if (bgndPath !== undefined) {
@@ -541,18 +536,18 @@ function EntryProperties(props: Props) {
}
function getThumbPath() {
- if (!currentEntry) {
+ if (!openedEntry) {
return undefined;
}
- if (currentEntry.isFile) {
+ if (openedEntry.isFile) {
return getThumbFileLocationForFile(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
false,
);
}
return getThumbFileLocationForDirectory(
- currentEntry.path,
+ openedEntry.path,
PlatformIO.getDirSeparator(),
);
}
@@ -579,8 +574,8 @@ function EntryProperties(props: Props) {
return undefined;
}
- const ldtm = currentEntry.lmdt
- ? new Date(currentEntry.lmdt)
+ const ldtm = openedEntry.lmdt
+ ? new Date(openedEntry.lmdt)
.toISOString()
.substring(0, 19)
.split('T')
@@ -589,10 +584,10 @@ function EntryProperties(props: Props) {
const changePerspective = (event: any) => {
const perspective = event.target.value;
- setDirectoryPerspective(perspective, currentEntry.path, false)
+ setDirectoryPerspective(perspective, openedEntry.path, false)
.then((entryMeta: TS.FileSystemEntryMeta) => {
- // currentEntry = {...currentEntry, perspective: perspective}
- return updateOpenedFile(currentEntry.path, entryMeta);
+ // openedEntry = {...openedEntry, perspective: perspective}
+ return updateOpenedFile(openedEntry.path, entryMeta);
// return true;
})
.catch((error) => {
@@ -602,8 +597,8 @@ function EntryProperties(props: Props) {
};
let perspectiveDefault;
- if (currentEntry.perspective) {
- perspectiveDefault = currentEntry.perspective; // props.perspective;
+ if (openedEntry.perspective) {
+ perspectiveDefault = openedEntry.perspective; // props.perspective;
} else {
perspectiveDefault = 'unspecified'; // perspectives.DEFAULT;
}
@@ -635,11 +630,11 @@ function EntryProperties(props: Props) {
}
}
- const geoLocation: any = getGeoLocation(currentEntry.tags);
+ const geoLocation: any = getGeoLocation(openedEntry.tags);
- const isCloudLocation = currentEntry.url && currentEntry.url.length > 5;
+ const isCloudLocation = openedEntry.url && openedEntry.url.length > 5;
- const showLinkForDownloading = isCloudLocation && currentEntry.isFile;
+ const showLinkForDownloading = isCloudLocation && openedEntry.isFile;
return (
<Root>
@@ -648,13 +643,13 @@ function EntryProperties(props: Props) {
<TextField
error={fileNameError.current}
label={
- currentEntry.isFile ? t('core:fileName') : t('core:folderName')
+ openedEntry.isFile ? t('core:fileName') : t('core:folderName')
}
InputProps={{
readOnly: editName === undefined,
endAdornment: (
<InputAdornment position="end">
- {!readOnlyMode && !currentEntry.editMode && (
+ {!readOnlyMode && !openedEntry.editMode && (
<div style={{ textAlign: 'right' }}>
{editName !== undefined ? (
<div>
@@ -691,10 +686,10 @@ function EntryProperties(props: Props) {
name="name"
fullWidth={true}
data-tid="fileNameProperties"
- defaultValue={entryName} // currentEntry.current.name}
+ defaultValue={entryName} // openedEntry.current.name}
inputRef={fileNameRef}
onClick={() => {
- if (!currentEntry.editMode && editName === undefined) {
+ if (!openedEntry.editMode && editName === undefined) {
activateEditNameField();
}
}}
@@ -709,26 +704,26 @@ function EntryProperties(props: Props) {
<FormHelperText>
{t(
'core:' +
- (currentEntry.isFile ? 'fileNameHelp' : 'directoryNameHelp'),
+ (openedEntry.isFile ? 'fileNameHelp' : 'directoryNameHelp'),
)}
</FormHelperText>
)}
</Grid>
<Grid item xs={12} style={{ marginTop: 10 }}>
- <TagDropContainer entryPath={currentEntry.path}>
+ <TagDropContainer entryPath={openedEntry.path}>
<TagsSelect
label={t('core:fileTags')}
dataTid="PropertiesTagsSelectTID"
placeholderText={t('core:dropHere')}
/*isReadOnlyMode={
isReadOnlyMode ||
- currentEntry.current.editMode ||
+ openedEntry.current.editMode ||
editName !== undefined
}*/
- tags={currentEntry.tags}
+ tags={openedEntry.tags}
tagMode="default"
handleChange={handleChange}
- selectedEntryPath={currentEntry.path}
+ selectedEntryPath={openedEntry.path}
/>
</TagDropContainer>
</Grid>
@@ -847,7 +842,7 @@ function EntryProperties(props: Props) {
title={
!PlatformIO.haveObjectStoreSupport() &&
dirProps &&
- !currentEntry.isFile &&
+ !openedEntry.isFile &&
dirProps.dirsCount +
' ' +
t('core:directories') +
@@ -861,8 +856,8 @@ function EntryProperties(props: Props) {
margin="dense"
fullWidth={true}
value={
- currentEntry.size
- ? formatBytes(currentEntry.size)
+ openedEntry.size
+ ? formatBytes(openedEntry.size)
: t(
PlatformIO.haveObjectStoreSupport()
? 'core:notAvailable'
@@ -883,11 +878,11 @@ function EntryProperties(props: Props) {
<TextField
margin="dense"
name="path"
- title={currentEntry.url || currentEntry.path}
+ title={openedEntry.url || openedEntry.path}
fullWidth={true}
label={t('core:filePath')}
data-tid="filePathProperties"
- value={currentEntry.path || ''}
+ value={openedEntry.path || ''}
InputProps={{
readOnly: true,
startAdornment: (
@@ -906,7 +901,7 @@ function EntryProperties(props: Props) {
endAdornment: (
<InputAdornment position="end">
{!readOnlyMode &&
- !currentEntry.editMode &&
+ !openedEntry.editMode &&
editName === undefined && (
<Button
data-tid="moveCopyEntryTID"
@@ -1017,7 +1012,7 @@ function EntryProperties(props: Props) {
)}
</Grid>
- {!currentEntry.isFile && (
+ {!openedEntry.isFile && (
<Grid item xs={12} style={{ marginTop: 10 }}>
<PerspectiveSelector
onChange={changePerspective}
@@ -1028,7 +1023,7 @@ function EntryProperties(props: Props) {
</Grid>
)}
- {!currentEntry.isFile && (
+ {!openedEntry.isFile && (
<Grid item xs={12} style={{ marginTop: 5 }}>
<TextField
margin="dense"
@@ -1054,7 +1049,7 @@ function EntryProperties(props: Props) {
fullWidth
style={{
width: 100,
- background: currentEntry.color,
+ background: openedEntry.color,
}}
onClick={toggleBackgroundColorPicker}
>
@@ -1081,7 +1076,7 @@ function EntryProperties(props: Props) {
</IconButton>
</ProTooltip>
))}
- {currentEntry.color && (
+ {openedEntry.color && (
<>
<ProTooltip tooltip={t('clearFolderColor')}>
<span>
@@ -1108,7 +1103,7 @@ function EntryProperties(props: Props) {
</Grid>
)}
<Grid container item xs={12} spacing={1}>
- <Grid item xs={currentEntry.isFile ? 12 : 6}>
+ <Grid item xs={openedEntry.isFile ? 12 : 6}>
<ThumbnailTextField
margin="dense"
label={t('core:thumbnail')}
@@ -1123,7 +1118,7 @@ function EntryProperties(props: Props) {
style={{ alignItems: 'center' }}
>
{!readOnlyMode &&
- !currentEntry.editMode &&
+ !openedEntry.editMode &&
editName === undefined && (
<ProTooltip tooltip={t('changeThumbnail')}>
<Button fullWidth onClick={toggleThumbFilesDialog}>
@@ -1165,7 +1160,7 @@ function EntryProperties(props: Props) {
}}
/>
</Grid>
- {!currentEntry.isFile && (
+ {!openedEntry.isFile && (
<Grid item xs={6}>
<ThumbnailTextField
margin="dense"
@@ -1181,7 +1176,7 @@ function EntryProperties(props: Props) {
style={{ alignItems: 'center' }}
>
{!readOnlyMode &&
- !currentEntry.editMode &&
+ !openedEntry.editMode &&
editName === undefined && (
<ProTooltip tooltip={t('changeBackgroundImage')}>
<Button fullWidth onClick={toggleBgndImgDialog}>
@@ -1254,8 +1249,8 @@ function EntryProperties(props: Props) {
onClose={toggleMoveCopyFilesDialog}
entries={[
{
- ...currentEntry,
- isFile: currentEntry.isFile,
+ ...openedEntry,
+ isFile: openedEntry.isFile,
name: entryName,
tags: [],
},
@@ -1266,7 +1261,7 @@ function EntryProperties(props: Props) {
<ThumbnailChooserDialog
open={isFileThumbChooseDialogOpened}
onClose={toggleThumbFilesDialog}
- selectedFile={currentEntry.path}
+ selectedFile={openedEntry.path}
thumbPath={getThumbPath()}
setThumb={setThumb}
/>
@@ -1275,24 +1270,24 @@ function EntryProperties(props: Props) {
<LinkGeneratorDialog
open={showSharingLinkDialog}
onClose={() => setShowSharingLinkDialog(false)}
- path={currentEntry.path}
- locationId={currentEntry.locationId}
+ path={openedEntry.path}
+ locationId={openedEntry.locationId}
/>
)}
{BgndImgChooserDialog && (
<BgndImgChooserDialog
open={isBgndImgChooseDialogOpened}
onClose={toggleBgndImgDialog}
- currentDirectoryPath={currentEntry.path}
+ currentDirectoryPath={openedEntry.path}
/>
)}
{CustomBackgroundDialog && (
<CustomBackgroundDialog
- color={currentEntry.color}
+ color={openedEntry.color}
open={displayColorPicker}
setColor={handleChangeColor}
onClose={toggleBackgroundColorPicker}
- currentDirectoryPath={currentEntry.path}
+ currentDirectoryPath={openedEntry.path}
/*presetColors={[
'transparent',
'#FFFFFF44',
diff --git a/src/renderer/components/FileView.tsx b/src/renderer/components/FileView.tsx
index 0f2c7e653..de20f0b41 100644
--- a/src/renderer/components/FileView.tsx
+++ b/src/renderer/components/FileView.tsx
@@ -19,13 +19,12 @@
import React, { MutableRefObject } from 'react';
import { rgbToHex, useTheme } from '@mui/material/styles';
import CloseIcon from '@mui/icons-material/Close';
-import { OpenedEntry } from '-/reducers/app';
import useEventListener from '-/utils/useEventListener';
import { useTranslation } from 'react-i18next';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
interface Props {
- openedFile: OpenedEntry;
isFullscreen?: boolean;
fileViewer: MutableRefObject<HTMLIFrameElement>;
fileViewerContainer: MutableRefObject<HTMLDivElement>;
@@ -37,15 +36,15 @@ interface Props {
function FileView(props: Props) {
const { i18n } = useTranslation();
const theme = useTheme();
+ const { openedEntry } = useOpenedEntryContext();
const {
- openedFile,
fileViewer,
isFullscreen,
fileViewerContainer,
toggleFullScreen,
height,
eventID,
- } = props; // .openedFiles[0];
+ } = props;
const { searchQuery } = useDirectoryContentContext();
@@ -64,7 +63,7 @@ function FileView(props: Props) {
let fileOpenerURL: string;
- if (openedFile.path) {
+ if (openedEntry.path) {
// if (fileTitle.length > maxCharactersTitleLength) {
// fileTitle = fileTitle.substr(0, maxCharactersTitleLength) + '...';
// }
@@ -101,29 +100,33 @@ function FileView(props: Props) {
extTextColor +
extBgndColor;
- if (openedFile.editMode && openedFile.editingExtensionPath) {
+ if (openedEntry.editMode && openedEntry.editingExtensionPath) {
fileOpenerURL =
- openedFile.editingExtensionPath +
+ openedEntry.editingExtensionPath +
'/index.html?file=' +
- encodeURIComponent(openedFile.url ? openedFile.url : openedFile.path) +
+ encodeURIComponent(
+ openedEntry.url ? openedEntry.url : openedEntry.path,
+ ) +
locale +
theming +
extQuery +
event +
'&edit=true' +
- (openedFile.shouldReload === true ? '&t=' + new Date().getTime() : '');
+ (openedEntry.shouldReload === true ? '&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 =
- openedFile.viewingExtensionPath +
+ openedEntry.viewingExtensionPath +
'/index.html?file=' +
- encodeURIComponent(openedFile.url ? openedFile.url : openedFile.path) +
+ encodeURIComponent(
+ openedEntry.url ? openedEntry.url : openedEntry.path,
+ ) +
locale +
theming +
extQuery +
event +
- (openedFile.shouldReload === true ? '&t=' + new Date().getTime() : '');
+ (openedEntry.shouldReload === true ? '&t=' + new Date().getTime() : '');
}
} else {
fileOpenerURL = 'about:blank';
@@ -158,7 +161,7 @@ function FileView(props: Props) {
<span>ESC</span>
</div>
)}
- {openedFile.isFile && (
+ {openedEntry.isFile && (
<iframe
ref={fileViewer}
style={{
@@ -177,12 +180,12 @@ function FileView(props: Props) {
);
}
-const areEqual = (prevProp, nextProp) =>
+/*const areEqual = (prevProp, nextProp) =>
nextProp.openedFile.path === prevProp.openedFile.path &&
nextProp.openedFile.url === prevProp.openedFile.url &&
nextProp.openedFile.editMode === prevProp.openedFile.editMode &&
nextProp.openedFile.shouldReload === prevProp.openedFile.shouldReload &&
nextProp.isFullscreen === prevProp.isFullscreen &&
- nextProp.height === prevProp.height;
+ nextProp.height === prevProp.height;*/
-export default React.memo(FileView, areEqual);
+export default FileView;
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index 786d277bc..6d92e055f 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -46,7 +46,6 @@ import { PerspectiveIDs, AvailablePerspectives } from '-/perspectives';
// import LoadingAnimation from '-/components/LoadingAnimation';
import SearchBox from '-/components/SearchBox';
import { useTranslation } from 'react-i18next';
-import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import RenderPerspective from '-/components/RenderPerspective';
import { adjustKeyBinding } from '-/components/dialogs/KeyboardDialog';
@@ -66,7 +65,6 @@ function FolderContainer(props: Props) {
const { t } = useTranslation();
const dispatch: AppDispatch = useDispatch();
const theme = useTheme();
- const { openedEntries } = useOpenedEntryContext();
const {
setSearchQuery,
currentDirectoryEntries,
@@ -189,8 +187,6 @@ function FolderContainer(props: Props) {
: '';
// keyBindings['openSearch'].toUpperCase()
- const isEntryOpened = openedEntries.length > 0;
-
return (
<div
style={{
diff --git a/src/renderer/components/Revisions.tsx b/src/renderer/components/Revisions.tsx
index cb21b3f59..db5889b89 100644
--- a/src/renderer/components/Revisions.tsx
+++ b/src/renderer/components/Revisions.tsx
@@ -55,7 +55,7 @@ function Revisions() {
// const dispatch: AppDispatch = useDispatch();
const { switchLocationTypeByID, switchCurrentLocationType } =
useCurrentLocationContext();
- const { openedEntries, updateOpenedFile } = useOpenedEntryContext();
+ const { openedEntry, updateOpenedFile } = useOpenedEntryContext();
const { copyFilePromiseOverwrite } = usePlatformFacadeContext();
const [rows, setRows] = useState<Array<TS.FileSystemEntry>>([]);
const [page, setPage] = useState<number>(0);
@@ -68,11 +68,10 @@ function Revisions() {
useEffect(() => {
// if no history item path - not loadHistoryItems for items in metaFolder
- const openedFile = openedEntries[0];
- if (openedFile && openedFile.path.indexOf(AppConfig.metaFolder) === -1) {
- loadHistoryItems(openedFile);
+ if (openedEntry && openedEntry.path.indexOf(AppConfig.metaFolder) === -1) {
+ loadHistoryItems(openedEntry);
}
- }, [openedEntries]);
+ }, [openedEntry]);
function loadHistoryItems(openedFile: OpenedEntry) {
if (Pro) {
@@ -116,7 +115,7 @@ function Revisions() {
function deleteRevision(path) {
PlatformIO.deleteFilePromise(path, true).then(() =>
- loadHistoryItems(openedEntries[0]),
+ loadHistoryItems(openedEntry),
);
}
@@ -125,26 +124,26 @@ function Revisions() {
const promises = rows.map((row) =>
PlatformIO.deleteFilePromise(row.path, true),
);
- Promise.all(promises).then(() => loadHistoryItems(openedEntries[0]));
+ Promise.all(promises).then(() => loadHistoryItems(openedEntry));
}
}
function restoreRevision(revisionPath) {
- const openedFile = openedEntries[0];
const targetPath = getBackupFileLocation(
- openedFile.path,
- openedFile.uuid,
+ openedEntry.path,
+ openedEntry.uuid,
PlatformIO.getDirSeparator(),
);
- return copyFilePromiseOverwrite(openedFile.path, targetPath).then(() =>
- copyFilePromiseOverwrite(revisionPath, openedFile.path).then(() =>
- updateOpenedFile(openedFile.path, {
+ return copyFilePromiseOverwrite(openedEntry.path, targetPath).then(() =>
+ copyFilePromiseOverwrite(revisionPath, openedEntry.path).then(() => {
+ const fsMeta = {
id: '',
- ...openedFile,
+ ...openedEntry,
editMode: false,
- shouldReload: !openedFile.shouldReload,
- }),
- ),
+ shouldReload: !openedEntry.shouldReload,
+ };
+ updateOpenedFile(openedEntry.path, fsMeta);
+ }),
);
}
function titleFormat(lmdt) {
@@ -221,7 +220,7 @@ function Revisions() {
<TableBody>
{paginatedRows.map((row) => (
<TableRow
- data-tid={openedEntries[0].uuid}
+ data-tid={openedEntry.uuid}
key={row.path}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
diff --git a/src/renderer/components/dialogs/FilePreviewDialog.tsx b/src/renderer/components/dialogs/FilePreviewDialog.tsx
index a64403471..c663d8172 100644
--- a/src/renderer/components/dialogs/FilePreviewDialog.tsx
+++ b/src/renderer/components/dialogs/FilePreviewDialog.tsx
@@ -46,7 +46,7 @@ function FilePreviewDialog(props: Props) {
//const dispatch: AppDispatch = useDispatch();
const { switchLocationTypeByID, switchCurrentLocationType } =
useCurrentLocationContext();
- const { openedEntries } = useOpenedEntryContext();
+ const { openedEntry } = useOpenedEntryContext();
// const supportedFileTypes = useSelector(getSupportedFileTypes);
const currentTheme = useSelector(getCurrentTheme);
const fileViewer: MutableRefObject<HTMLIFrameElement> =
@@ -55,7 +55,6 @@ function FilePreviewDialog(props: Props) {
useRef<HTMLDivElement>(null);
const eventID = useRef<string>(getUuid());
- const openedEntry: OpenedEntry = openedEntries[0];
const openedFile: OpenedEntry =
fsEntry && openedEntry
? {
@@ -193,7 +192,6 @@ function FilePreviewDialog(props: Props) {
<p>{fsEntry.path}</p>
<FileView
key="FileViewPreviewID"
- openedFile={openedFile}
fileViewer={fileViewer}
fileViewerContainer={fileViewerContainer}
height={'90%'}
diff --git a/src/renderer/components/dialogs/ResolveConflictDialog.tsx b/src/renderer/components/dialogs/ResolveConflictDialog.tsx
index 543df31ed..0b6e17ed5 100644
--- a/src/renderer/components/dialogs/ResolveConflictDialog.tsx
+++ b/src/renderer/components/dialogs/ResolveConflictDialog.tsx
@@ -35,11 +35,11 @@ import {
import PlatformFacade from '-/services/platform-facade';
import AppConfig from '-/AppConfig';
import { useTranslation } from 'react-i18next';
+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
interface Props {
open: boolean;
onClose: () => void;
- file: OpenedEntry;
saveAs: (newFilePath: string) => Promise<boolean>;
override: () => Promise<boolean>;
}
@@ -47,6 +47,7 @@ interface Props {
function ResolveConflictDialog(props: Props) {
const { open, onClose } = props;
const { t } = useTranslation();
+ const { openedEntry } = useOpenedEntryContext();
const copyFileName = React.useRef<string>(getFileName());
const [isSaveAs, setSaveAs] = React.useState<boolean>(false);
@@ -54,8 +55,8 @@ function ResolveConflictDialog(props: Props) {
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
function getFileName() {
- const fileName = extractFileName(props.file.path);
- const ext = extractFileExtension(props.file.path);
+ const fileName = extractFileName(openedEntry.path);
+ const ext = extractFileExtension(openedEntry.path);
return fileName.slice(0, -(ext.length + 1)) + '-copy.' + ext;
}
@@ -116,7 +117,7 @@ function ResolveConflictDialog(props: Props) {
onClick={() => {
props
.saveAs(
- extractContainingDirectoryPath(props.file.path) +
+ extractContainingDirectoryPath(openedEntry.path) +
PlatformFacade.getDirSeparator() +
copyFileName.current,
)
diff --git a/src/renderer/containers/MainPage.tsx b/src/renderer/containers/MainPage.tsx
index 418b59147..31af83df0 100644
--- a/src/renderer/containers/MainPage.tsx
+++ b/src/renderer/containers/MainPage.tsx
@@ -326,7 +326,7 @@ function MainPage(props: Props) {
const { selectedEntries } = useSelectedEntriesContext();
const {
openLink,
- openedEntries,
+ openedEntry,
isEntryInFullWidth,
goForward,
goBack,
@@ -398,7 +398,7 @@ function MainPage(props: Props) {
useEffect(() => {
updateDimensions();
- }, [openedEntries]);
+ }, [openedEntry]);
useEventListener('resize', () => {
if (!AppConfig.isCordova) {
@@ -419,7 +419,7 @@ function MainPage(props: Props) {
// console.log('Width: ' + width + ' Height: ' + height);
setDimensions({ width: w, height: h });
- if (openedEntries.length > 0 && !isEntryInFullWidth) {
+ if (openedEntry && !isEntryInFullWidth) {
const isFillWidth = h > w;
if (isFillWidth !== isEntryInFullWidth) {
setEntryInFullWidth(isFillWidth);
@@ -484,8 +484,6 @@ function MainPage(props: Props) {
const { FILE } = NativeTypes;
- const isFileOpened = openedEntries.length > 0;
-
const setPercent = (p: number | undefined) => {
percent.current = p;
if (p !== undefined) {
@@ -504,7 +502,7 @@ function MainPage(props: Props) {
let minSecondarySize = '250px';
let renderSplitter;
- if (!isFileOpened) {
+ if (!openedEntry) {
percent.current = undefined;
initialPrimarySize = '100%';
minSecondarySize = '0%';
@@ -539,7 +537,7 @@ function MainPage(props: Props) {
setMoveCopyDialogOpened(props.selectedEntries)
}*/
/>
- {isFileOpened && (
+ {openedEntry && (
<DescriptionContextProvider>
<EntryContainer key="EntryContainerID" />
</DescriptionContextProvider>
@@ -734,7 +732,7 @@ function MainPage(props: Props) {
.react-split .split-container {
--react-split-splitter: ${
- openedEntries.length < 1 || isEntryInFullWidth ? '0' : '3px'
+ !openedEntry || isEntryInFullWidth ? '0' : '3px'
} !important;
}
.react-split .secondary .full-content {
diff --git a/src/renderer/hooks/DescriptionContextProvider.tsx b/src/renderer/hooks/DescriptionContextProvider.tsx
index f14c1d299..3c2dfb724 100644
--- a/src/renderer/hooks/DescriptionContextProvider.tsx
+++ b/src/renderer/hooks/DescriptionContextProvider.tsx
@@ -63,7 +63,7 @@ export const DescriptionContextProvider = ({
const { t } = useTranslation();
const { setSelectedEntries } = useSelectedEntriesContext();
const {
- openedEntries,
+ openedEntry,
addToEntryContainer,
updateOpenedFile,
reloadOpenedFile,
@@ -72,30 +72,30 @@ export const DescriptionContextProvider = ({
useCurrentLocationContext();
const { updateCurrentDirEntry } = useDirectoryContentContext();
const { showNotification } = useNotificationContext();
- const openedFile = useRef<OpenedEntry>(openedEntries[0]);
+ const openedFile = useRef<OpenedEntry>(openedEntry);
const isChanged = useRef<boolean>(false);
const [isSaveDescriptionConfirmOpened, saveDescriptionConfirmOpened] =
useState<boolean>(false);
useEffect(() => {
- if (openedEntries && openedEntries.length > 0) {
+ if (openedEntry) {
if (
openedFile.current !== undefined &&
isChanged.current &&
- openedFile.current.path !== openedEntries[0].path &&
- openedFile.current.description !== openedEntries[0].description
+ openedFile.current.path !== openedEntry.path &&
+ openedFile.current.description !== openedEntry.description
) {
// handle not saved changes
addToEntryContainer({ ...openedFile.current, editMode: false });
setSelectedEntries([]);
saveDescriptionConfirmOpened(true);
} else {
- openedFile.current = openedEntries[0];
+ openedFile.current = openedEntry;
}
} else {
openedFile.current = undefined;
}
- }, [openedEntries]);
+ }, [openedEntry]);
const saveDescription = () => {
if (readOnlyMode) {
@@ -165,7 +165,7 @@ export const DescriptionContextProvider = ({
const context = useMemo(() => {
return {
- description: openedFile.current.description,
+ description: openedFile.current?.description,
isSaveDescriptionConfirmOpened,
setSaveDescriptionConfirmOpened,
setDescription,
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 3099a271f..bb7a404bf 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -28,18 +28,14 @@ import { useDispatch, useSelector } from 'react-redux';
import {
actions as AppActions,
AppDispatch,
- getEditedEntryPaths,
OpenedEntry,
} from '-/reducers/app';
import { Pro } from '-/pro';
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
import {
- enhanceOpenedEntry,
findExtensionsForEntry,
getAllPropertiesPromise,
- getNextFile,
- getPrevFile,
getRelativeEntryPath,
loadJSONFile,
openURLExternally,
@@ -49,7 +45,6 @@ import {
actions as SettingsActions,
getNewHTMLFileContent,
getSupportedFileTypes,
- getTagDelimiter,
} from '-/reducers/settings';
import { getLocations } from '-/reducers/locations';
import { clearURLParam, getURLParameter, updateHistory } from '-/utils/dom';
@@ -79,8 +74,8 @@ import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
type OpenedEntryContextData = {
- openedEntries: OpenedEntry[];
- currentEntry: OpenedEntry;
+ //openedEntries: OpenedEntry[];
+ openedEntry: OpenedEntry;
dirProps: TS.DirProp;
isEntryInFullWidth: boolean;
sharingLink: string;
@@ -118,8 +113,8 @@ type OpenedEntryContextData = {
};
export const OpenedEntryContext = createContext<OpenedEntryContextData>({
- openedEntries: [],
- currentEntry: undefined,
+ //openedEntries: [],
+ openedEntry: undefined,
dirProps: undefined,
isEntryInFullWidth: false,
sharingLink: undefined,
@@ -180,8 +175,8 @@ export const OpenedEntryContextProvider = ({
);
const newHTMLFileContent = useSelector(getNewHTMLFileContent);
//const initOpenLink = useSelector(getOpenLink);
- const editedEntryPaths = useSelector(getEditedEntryPaths);
- const tagDelimiter = useSelector(getTagDelimiter);
+ //const editedEntryPaths = useSelector(getEditedEntryPaths);
+ //const tagDelimiter = useSelector(getTagDelimiter);
/* const checkForUpdates = useSelector(getCheckForUpdateOnStartup);
const firstRun = useSelector(isFirstRun);
const enableGlobalKeyboardShortcuts = useSelector(isGlobalKeyBindingEnabled);*/
@@ -1034,7 +1029,7 @@ export const OpenedEntryContextProvider = ({
function reflectRenameOpenedEntry(entryPath, newEntryPath, reload = false) {
//if (openedEntries && openedEntries.length > 0) {
- if (currentEntry.current.path === entryPath) {
+ if (currentEntry.current && currentEntry.current.path === entryPath) {
//if (openedEntries.some((entry) => entry.path === entryPath)) {
if (currentLocation) {
updateHistory(
@@ -1092,8 +1087,8 @@ export const OpenedEntryContextProvider = ({
const context = useMemo(() => {
return {
- openedEntries,
- currentEntry: currentEntry.current,
+ //openedEntries,
+ openedEntry: currentEntry.current,
dirProps: dirProps.current,
isEntryInFullWidth: isEntryInFullWidth.current,
sharingLink: sharingLink.current,
@@ -1118,7 +1113,7 @@ export const OpenedEntryContextProvider = ({
reflectDeleteFile,
};
}, [
- openedEntries,
+ //openedEntries,
currentEntry.current,
isEntryInFullWidth.current,
dirProps.current,
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index 4a1a3c34c..fcba8c9e2 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -96,12 +96,8 @@ export const TaggingActionsContextProvider = ({
children,
}: TaggingActionsContextProviderProps) => {
const { t } = useTranslation();
- const {
- openedEntries,
- updateOpenedFile,
- reflectSidecarTagsUpdate,
- reflectRenameOpenedEntry,
- } = useOpenedEntryContext();
+ const { openedEntry, reflectSidecarTagsUpdate, reflectRenameOpenedEntry } =
+ useOpenedEntryContext();
const { updateCurrentDirEntry, reflectRenameEntries } =
useDirectoryContentContext();
const { persistTagsInSidecarFile } = useCurrentLocationContext();
@@ -865,7 +861,7 @@ export const TaggingActionsContextProvider = ({
collectTagsFromLocation,
};
}, [
- openedEntries,
+ openedEntry,
persistTagsInSidecarFile,
addTagsToLibrary,
reflectUpdateSidecarTags,