Skip to content

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

Removing current location crashes the app (#2252)

Stanimir66f9c6648790
diff --git a/src/renderer/components/dialogs/FileUploadDialog.tsx b/src/renderer/components/dialogs/FileUploadDialog.tsx
index 1f9dec7f2..02d9905fa 100644
--- a/src/renderer/components/dialogs/FileUploadDialog.tsx
+++ b/src/renderer/components/dialogs/FileUploadDialog.tsx
@@ -93,7 +93,7 @@ function FileUploadDialog(props: Props) {
const stopAll = () => {
if (progress) {
- if (currentLocation.haveObjectStoreSupport()) {
+ if (currentLocation?.haveObjectStoreSupport()) {
const progresses = progress.map((fileProgress) => {
fileProgress.abort();
return { ...fileProgress, state: 'finished' };
diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
index d01590a09..c86c640a9 100644
--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
@@ -79,6 +79,7 @@ function MoveCopyFilesDialog(props: Props) {
if (
selectedDirs.length > 0 &&
AppConfig.isElectron &&
+ currentLocation &&
!currentLocation.haveObjectStoreSupport() &&
!currentLocation.haveWebDavSupport()
) {
diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsx
index 66d9e9ac5..1190d8879 100644
--- a/src/renderer/components/menus/FileMenu.tsx
+++ b/src/renderer/components/menus/FileMenu.tsx
@@ -131,7 +131,7 @@ function FileMenu(props: Props) {
const currentLocation = findLocation();
useEffect(() => {
- if (currentLocation.haveObjectStoreSupport()) {
+ if (currentLocation?.haveObjectStoreSupport()) {
currentLocation
.generateURLforPath(selectedFilePath, 86400)
.then((url) => {
diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsx
index 8c2583a67..5c1d9a794 100644
--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx
+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx
@@ -51,7 +51,7 @@ type CurrentLocationContextData = {
skipInitialDirList: boolean;
persistTagsInSidecarFile: boolean;
getLocationPath: (location: CommonLocation) => Promise<string>;
- findLocation: (locationID?: string) => CommonLocation;
+ findLocation: (locationID?: string) => CommonLocation | undefined;
getDirSeparator: (locationID?: string) => string;
findLocalLocation: () => CommonLocation;
changeLocation: (location: CommonLocation, skipInitDirList?: boolean) => void;
@@ -254,7 +254,9 @@ export const CurrentLocationContextProvider = ({
return Promise.resolve(locationPath);
}
- function findLocation(locationID: string = undefined): CommonLocation {
+ function findLocation(
+ locationID: string = undefined,
+ ): CommonLocation | undefined {
if (!locationID) {
return allLocations.current.find(
(l) => l.uuid === currentLocationId.current,
diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsx
index fd5a3576e..f92a95116 100644
--- a/src/renderer/hooks/FSWatcherContextProvider.tsx
+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx
@@ -93,6 +93,7 @@ export const FSWatcherContextProvider = ({
function watchFolder(locationPath, depth) {
if (
Pro &&
+ currentLocation &&
!currentLocation.haveObjectStoreSupport() &&
!currentLocation.haveWebDavSupport()
) {
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 31f7b1a9c..9c313db26 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -322,16 +322,18 @@ export const OpenedEntryContextProvider = ({
}
function getOpenedDirProps(): Promise<TS.DirProp> {
- if (
- currentEntry.current &&
- !currentEntry.current.isFile &&
- !currentLocation.haveObjectStoreSupport() &&
- !currentLocation.haveWebDavSupport()
- ) {
- return getDirProperties(currentEntry.current.path).catch((ex) => {
- console.debug('getDirProperties:', ex.message);
- return Promise.resolve(undefined);
- });
+ if (currentEntry.current && !currentEntry.current.isFile) {
+ const location = findLocation(currentEntry.current.locationID);
+ if (
+ location &&
+ !location.haveObjectStoreSupport() &&
+ !location.haveWebDavSupport()
+ ) {
+ return getDirProperties(currentEntry.current.path).catch((ex) => {
+ console.debug('getDirProperties:', ex.message);
+ return Promise.resolve(undefined);
+ });
+ }
}
return Promise.resolve(undefined);
}
diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsx
index 8a55e5f99..5724f6dc6 100644
--- a/src/renderer/perspectives/common/CellView.tsx
+++ b/src/renderer/perspectives/common/CellView.tsx
@@ -309,6 +309,7 @@ function CellView(props: Props) {
<div>
{nativeDragModeEnabled &&
AppConfig.isElectron &&
+ currentLocation &&
!currentLocation.haveObjectStoreSupport() && (
<div
style={{
diff --git a/src/renderer/perspectives/grid/components/MainToolbar.tsx b/src/renderer/perspectives/grid/components/MainToolbar.tsx
index 00e8f75c2..23be2487c 100644
--- a/src/renderer/perspectives/grid/components/MainToolbar.tsx
+++ b/src/renderer/perspectives/grid/components/MainToolbar.tsx
@@ -106,7 +106,7 @@ function MainToolbar(props: Props) {
? entry.path.substr(1)
: entry.path;
currentLocation
- .generateURLforPath(cleanedPath, 900)
+ ?.generateURLforPath(cleanedPath, 900)
.then((url) => fetch(url))
.then((res) => res.blob()) // Gets the response and returns it as a blob
.then((blob) => {
@@ -267,7 +267,7 @@ function MainToolbar(props: Props) {
<ZoomComponent preview={false} />
<Divider flexItem orientation="vertical" sx={{ mx: 0.5, my: 1 }} />
</Box>
- {AppConfig.isElectron && !currentLocation.haveObjectStoreSupport() && (
+ {AppConfig.isElectron && !currentLocation?.haveObjectStoreSupport() && (
<TsIconButton
tooltip={t('core:dragMode')}
data-tid={prefixDataTID + 'PerspectiveDragNative'}