Skip to content

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

TSN886 fix image loading issues (#1690)

Stanimird4ee99e18773
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 5e03f7ca3..d17ecc540 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -39,7 +39,7 @@ import i18n from '../services/i18n';
import {
getMaxSearchResults,
getDesktopMode,
- getKeyBindingObject,
+ // getKeyBindingObject,
getDefaultPerspective
} from '-/reducers/settings';
import {
@@ -47,7 +47,6 @@ import {
getDirectoryContent,
getSearchResultCount,
isReadOnlyMode,
- isLoading,
getCurrentLocationPath,
getCurrentDirectoryPerspective,
OpenedEntry,
@@ -70,9 +69,9 @@ import {
getSearchQuery
} from '-/reducers/location-index';
import Links from '-/links';
-import PlatformIO from '-/services/platform-facade';
import { PerspectiveIDs, AvailablePerspectives } from '-/perspectives';
import MainSearchField from '-/components/MainSearchField';
+import LoadingAnimation from '-/components/LoadingAnimation';
const GridPerspective = React.lazy(() =>
import(
@@ -223,7 +222,6 @@ interface Props {
loadParentDirectoryContent: () => void;
setSelectedEntries: (selectedEntries: Array<Object>) => void;
isReadOnlyMode: boolean;
- isLoading: boolean;
isDesktopMode: boolean;
showNotification: (content: string) => void;
toggleDrawer?: () => void;
@@ -243,7 +241,7 @@ interface Props {
setSearchQuery: (searchQuery: TS.SearchQuery) => void;
openCurrentDirectory: () => void;
openURLExternally?: (url: string, skipConfirmation: boolean) => void;
- keyBindings: Array<any>;
+ // keyBindings: Array<any>;
}
function FolderContainer(props: Props) {
@@ -309,8 +307,7 @@ function FolderContainer(props: Props) {
openDirectory,
reflectCreateEntry,
openFsEntry,
- isLoading,
- keyBindings,
+ // keyBindings,
defaultPerspective
} = props;
@@ -325,7 +322,7 @@ function FolderContainer(props: Props) {
const renderPerspective = () => {
if (showWelcomePanel) {
- return AppConfig.showWelcomePanel ? <WelcomePanelAsync /> : <></>;
+ return AppConfig.showWelcomePanel ? <WelcomePanelAsync /> : null;
}
if (currentPerspective === PerspectiveIDs.LIST) {
return (
@@ -678,40 +675,7 @@ function FolderContainer(props: Props) {
width: '100%'
}}
>
- {isLoading &&
- (PlatformIO.haveObjectStoreSupport() ||
- PlatformIO.haveWebDavSupport()) && (
- <div
- style={{
- position: 'absolute',
- zIndex: 1000,
- height: '100%',
- width: '100%',
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- borderRadius: 10,
- backdropFilter: 'grayscale(1)'
- // backdropFilter: 'blur(2px)',
- // backgroundColor: '#fafafa33' // red: '#eb585882' '#d9d9d980'
- }}
- >
- <div className="lds-ellipsis">
- <div
- style={{ backgroundColor: theme.palette.primary.main }}
- />
- <div
- style={{ backgroundColor: theme.palette.primary.main }}
- />
- <div
- style={{ backgroundColor: theme.palette.primary.main }}
- />
- <div
- style={{ backgroundColor: theme.palette.primary.main }}
- />
- </div>
- </div>
- )}
+ <LoadingAnimation />
{renderPerspective()}
{isRenameEntryDialogOpened && (
<RenameEntryDialog
@@ -759,8 +723,7 @@ function mapStateToProps(state) {
isReadOnlyMode: isReadOnlyMode(state),
progress: getProgress(state),
searchQuery: getSearchQuery(state),
- isLoading: isLoading(state),
- keyBindings: getKeyBindingObject(state),
+ // keyBindings: getKeyBindingObject(state),
defaultPerspective: getDefaultPerspective(state)
};
}
@@ -795,14 +758,14 @@ function mapActionCreatorsToProps(dispatch) {
const areEqual = (prevProp: Props, nextProp: Props) =>
// nextProp.rightPanelWidth === prevProp.rightPanelWidth &&
- nextProp.isLoading === prevProp.isLoading &&
nextProp.settings.currentTheme === prevProp.settings.currentTheme &&
nextProp.drawerOpened === prevProp.drawerOpened &&
nextProp.isDesktopMode === prevProp.isDesktopMode &&
nextProp.currentDirectoryPath === prevProp.currentDirectoryPath &&
nextProp.currentDirectoryPerspective ===
prevProp.currentDirectoryPerspective &&
- nextProp.currentLocationPath === prevProp.currentLocationPath &&
+ /* this props is set before currentDirectoryEntries is loaded and will reload FolderContainer
+ nextProp.currentLocationPath === prevProp.currentLocationPath && */
JSON.stringify(nextProp.directoryContent) ===
JSON.stringify(prevProp.directoryContent) &&
JSON.stringify(nextProp.openedFiles) ===
diff --git a/app/components/LoadingAnimation.tsx b/app/components/LoadingAnimation.tsx
new file mode 100644
index 000000000..9b682f927
--- /dev/null
+++ b/app/components/LoadingAnimation.tsx
@@ -0,0 +1,79 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React from 'react';
+import { connect } from 'react-redux';
+import { withStyles } from '@material-ui/core/styles';
+import PlatformIO from '-/services/platform-facade';
+import { isLoading } from '-/reducers/app';
+
+interface Props {
+ theme: any;
+ loading: boolean;
+}
+
+function LoadingAnimation(props: Props) {
+ const { theme, loading } = props;
+
+ if (
+ !loading ||
+ !(PlatformIO.haveObjectStoreSupport() && PlatformIO.haveWebDavSupport())
+ ) {
+ return null;
+ }
+
+ return (
+ <div
+ style={{
+ position: 'absolute',
+ zIndex: 1000,
+ height: '100%',
+ width: '100%',
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderRadius: 10,
+ backdropFilter: 'grayscale(1)'
+ // backdropFilter: 'blur(2px)',
+ // backgroundColor: '#fafafa33' // red: '#eb585882' '#d9d9d980'
+ }}
+ >
+ <div className="lds-ellipsis">
+ <div style={{ backgroundColor: theme.palette.primary.main }} />
+ <div style={{ backgroundColor: theme.palette.primary.main }} />
+ <div style={{ backgroundColor: theme.palette.primary.main }} />
+ <div style={{ backgroundColor: theme.palette.primary.main }} />
+ </div>
+ </div>
+ );
+}
+
+function mapStateToProps(state) {
+ return {
+ loading: isLoading(state)
+ };
+}
+
+const areEqual = (prevProp: Props, nextProp: Props) =>
+ nextProp.loading === prevProp.loading;
+
+export default connect(mapStateToProps)(
+ withStyles(undefined, { withTheme: true })(
+ React.memo(LoadingAnimation, areEqual)
+ )
+);
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 5bf70285c..07a09d192 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1019,12 +1019,28 @@ export const actions = {
dispatch(actions.setIsLoading(false));
}
},
+ updateCurrentDirectoryPerspective: (perspective: string) => (
+ dispatch: (action) => void,
+ getState: () => any
+ ) => {
+ const { currentDirectoryPerspective } = getState();
+ if (perspective) {
+ if (currentDirectoryPerspective !== perspective) {
+ dispatch(actions.setCurrentDirectoryPerspective(perspective));
+ }
+ } else if (currentDirectoryPerspective !== PerspectiveIDs.UNSPECIFIED) {
+ dispatch(
+ actions.setCurrentDirectoryPerspective(PerspectiveIDs.UNSPECIFIED)
+ );
+ }
+ },
loadDirectoryContentInt: (
directoryPath: string,
generateThumbnails: boolean,
fsEntryMeta?: TS.FileSystemEntryMeta
) => (dispatch: (action) => void, getState: () => any) => {
const { settings } = getState();
+
/* const { currentDirectoryPath } = getState().app;
if (currentDirectoryPath !== directoryPath) {
dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
@@ -1035,25 +1051,19 @@ export const actions = {
getState(),
getState().app.currentLocationId
);
- /* PlatformIO.enableWebdavSupport({ TODO use this to enable webdav support for location the same like objectstore
- username: 'webdav',
- password: '1234',
- port: 8080
- }); */
- /* const mode = PlatformIO.haveObjectStoreSupport()
- ? []
- : ['extractThumbPath', 'extractThumbURL']; */
+
PlatformIO.listDirectoryPromise(
directoryPath,
- [], // mode,
+ fsEntryMeta &&
+ fsEntryMeta.perspective &&
+ fsEntryMeta.perspective === PerspectiveIDs.GALLERY
+ ? ['extractThumbPath']
+ : [], // mode,
currentLocation ? currentLocation.ignorePatternPaths : []
)
.then(results => {
if (results !== undefined) {
// console.debug('app listDirectoryPromise resolved:' + results.length);
- dispatch(
- actions.setCurrentDirectoryPerspective(PerspectiveIDs.UNSPECIFIED)
- );
prepareDirectoryContent(
results,
directoryPath,
@@ -1064,11 +1074,21 @@ export const actions = {
generateThumbnails
);
}
+ dispatch(
+ actions.updateCurrentDirectoryPerspective(
+ fsEntryMeta ? fsEntryMeta.perspective : undefined
+ )
+ );
return true;
})
.catch(error => {
// console.timeEnd('listDirectoryPromise');
dispatch(actions.loadDirectoryFailure(directoryPath, error)); // Currently this is never called, due the promise always resolve
+ dispatch(
+ actions.updateCurrentDirectoryPerspective(
+ fsEntryMeta ? fsEntryMeta.perspective : undefined
+ )
+ );
});
},
loadDirectoryContent: (