Skip to content

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

Extract from MainPage separated Notification component PageNotification.tsx (#1452)

Stanimir92c3aa1036b0
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 6be609fc9..fa4be8a9d 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -23,10 +23,6 @@ import { withStyles } from '@material-ui/core/styles';
import { translate } from 'react-i18next';
import SplitPane from 'react-split-pane';
import SwipeableDrawer from '@material-ui/core/SwipeableDrawer';
-import Snackbar from '@material-ui/core/Snackbar';
-import Button from '@material-ui/core/Button';
-import IconButton from '@material-ui/core/IconButton';
-import CloseIcon from '@material-ui/icons/Close';
import { HotKeys } from 'react-hotkeys';
import { NativeTypes } from 'react-dnd-html5-backend';
import { Progress } from 'aws-sdk/clients/s3';
@@ -43,12 +39,10 @@ import {
getKeyBindingObject,
getLeftVerticalSplitSize,
getMainVerticalSplitSize,
- getLastPublishedVersion,
actions as SettingsActions
} from '../reducers/settings';
import {
actions as AppActions,
- getNotificationStatus,
isGeneratingThumbs,
isAboutDialogOpened,
isOnboardingDialogOpened,
@@ -56,7 +50,6 @@ import {
isLicenseDialogOpened,
isThirdPartyLibsDialogOpened,
isEntryInFullWidth,
- isUpdateAvailable,
getDirectoryPath,
isLocationManagerPanelOpened,
isTagLibraryPanelOpened,
@@ -77,17 +70,12 @@ import {
getSelectedEntries,
currentUser
} from '../reducers/app';
-import {
- actions as LocationIndexActions,
- isIndexing
-} from '../reducers/location-index';
import { buffer } from '-/utils/misc';
import TargetFileBox from '../components/TargetFileBox';
import AppConfig from '../config';
import buildDesktopMenu from '../services/electron-menus';
import buildTrayIconMenu from '../services/electron-tray-menu';
import i18n from '../services/i18n';
-import { Pro } from '../pro';
import LoadingLazy from '../components/LoadingLazy';
import withDnDContext from '-/containers/withDnDContext';
import { CustomDragLayer } from '-/components/CustomDragLayer';
@@ -97,7 +85,7 @@ import ProgressDialog from '-/components/dialogs/ProgressDialog';
import useEventListener from '-/utils/useEventListener';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { TS } from '-/tagspaces.namespace';
-import useTraceUpdate from '-/utils/useTraceUpdate';
+import PageNotification from '-/containers/PageNotification';
const initialSplitSize = 44;
const drawerWidth = 300;
@@ -144,15 +132,11 @@ interface Props {
setFirstRun: (isFirstRun: boolean) => void;
isDesktopMode: boolean;
openedFiles: Array<OpenedEntry>;
- isIndexing: boolean;
isGeneratingThumbs: boolean;
setGeneratingThumbnails: (isGenerating: boolean) => void;
isEntryInFullWidth: boolean;
classes: any;
theme: any;
- notificationStatus: any;
- lastPublishedVersion: string;
- isUpdateAvailable: boolean;
isReadOnlyMode: boolean;
isSettingsDialogOpened: boolean;
isCreateFileDialogOpened: boolean;
@@ -173,10 +157,7 @@ interface Props {
keyBindings: any;
toggleEditTagDialog: () => void;
setEntryFullWidth: (isFullWidth: boolean) => void;
- hideNotifications: () => void;
- cancelDirectoryIndexing: () => void;
loadParentDirectoryContent: () => void;
- setUpdateAvailable: (isUpdateAvailable: boolean) => void;
saveFile: () => void; // needed by electron-menus
setZoomResetApp: () => void; // needed by electron-menus
setZoomInApp: () => void; // needed by electron-menus
@@ -377,19 +358,12 @@ const MainPage = (props: Props) => {
return props.mainSplitSize;
};
- const isManagementPanelVisible = () => {
- if (
- props.isLocationManagerPanelOpened ||
- props.isTagLibraryPanelOpened ||
- props.isSearchPanelOpened ||
- props.isPerspectivesPanelOpened ||
- props.isHelpFeedbackPanelOpened
- ) {
- return true;
- }
- return false;
- // return window.ExtDefaultVerticalPanel !== 'none' && !props.isEntryInFullWidth;
- };
+ const isManagementPanelVisible = () =>
+ props.isLocationManagerPanelOpened ||
+ props.isTagLibraryPanelOpened ||
+ props.isSearchPanelOpened ||
+ props.isPerspectivesPanelOpened ||
+ props.isHelpFeedbackPanelOpened;
useEventListener('resize', () => {
if (!AppConfig.isCordova) {
@@ -444,27 +418,6 @@ const MainPage = (props: Props) => {
// setDrawerOpened(true);
};
- const skipRelease = () => {
- props.setUpdateAvailable(false);
- };
-
- const getLatestVersion = () => {
- if (Pro) {
- props.showNotification(
- i18n.t('core:getLatestVersionPro'),
- 'default',
- false
- );
- } else {
- props.openURLExternally(AppConfig.links.downloadURL, true);
- }
- props.setUpdateAvailable(false);
- };
-
- const openChangelogPage = () => {
- props.openURLExternally(AppConfig.links.changelogURL, true);
- };
-
const handleFileDrop = (item, monitor) => {
if (props.isReadOnlyMode) {
props.showNotification(
@@ -668,90 +621,7 @@ const MainPage = (props: Props) => {
confirmDialogContentTID="confirmDeleteDialogContent"
/>
)}
- <Snackbar
- data-tid={props.notificationStatus.tid}
- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
- open={props.notificationStatus.visible}
- onClose={props.hideNotifications}
- autoHideDuration={props.notificationStatus.autohide ? 3000 : undefined}
- message={props.notificationStatus.text}
- action={[
- <IconButton
- data-tid={'close' + props.notificationStatus.tid}
- key="close"
- aria-label={i18n.t('core:closeButton')}
- color="inherit"
- onClick={props.hideNotifications}
- >
- <CloseIcon />
- </IconButton>
- ]}
- />
- {/* <Snackbar
- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
- open={props.isGeneratingThumbs}
- autoHideDuration={undefined}
- message={i18n.t('core:loadingOrGeneratingThumbnails')}
- action={[
- <IconButton
- key="closeButton"
- aria-label={i18n.t('core:closeButton')}
- color="inherit"
- onClick={() => props.setGeneratingThumbnails(false)}
- >
- <CloseIcon />
- </IconButton>
- ]}
- /> */}
- <Snackbar
- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
- open={props.isIndexing}
- autoHideDuration={undefined}
- message="Indexing"
- action={[
- <Button
- key="cancelIndexButton"
- color="secondary"
- size="small"
- onClick={props.cancelDirectoryIndexing}
- data-tid="cancelDirectoryIndexing"
- >
- {i18n.t('core:cancelIndexing')}
- </Button>
- ]}
- />
- <Snackbar
- anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
- open={props.isUpdateAvailable}
- autoHideDuration={undefined}
- message={'Version ' + props.lastPublishedVersion + ' available.'}
- action={[
- <Button
- key="laterButton"
- color="secondary"
- size="small"
- onClick={skipRelease}
- >
- {i18n.t('core:later')}
- </Button>,
- <Button
- key="changelogButton"
- color="secondary"
- size="small"
- onClick={openChangelogPage}
- >
- {i18n.t('core:releaseNotes')}
- </Button>,
- <Button
- key="latestVersionButton"
- color="primary"
- size="small"
- onClick={getLatestVersion}
- >
- {i18n.t('core:getItNow')}
- </Button>
- ]}
- />
+ <PageNotification />
{props.isDesktopMode || (AppConfig.isAmplify && !props.user) ? (
<TargetFileBox
// @ts-ignore
@@ -861,7 +731,6 @@ function mapStateToProps(state) {
isUploadProgressDialogOpened: isUploadDialogOpened(state),
isOpenLinkDialogOpened: isOpenLinkDialogOpened(state),
isProgressDialogOpened: isProgressOpened(state),
- isIndexing: isIndexing(state),
isReadOnlyMode: isReadOnlyMode(state),
isGeneratingThumbs: isGeneratingThumbs(state),
// isFileOpened: isFileOpened(state),
@@ -871,9 +740,6 @@ function mapStateToProps(state) {
keyBindings: getKeyBindingObject(state),
leftSplitSize: getLeftVerticalSplitSize(state),
mainSplitSize: getMainVerticalSplitSize(state),
- isUpdateAvailable: isUpdateAvailable(state),
- lastPublishedVersion: getLastPublishedVersion(state),
- notificationStatus: getNotificationStatus(state),
isLocationManagerPanelOpened: isLocationManagerPanelOpened(state),
isTagLibraryPanelOpened: isTagLibraryPanelOpened(state),
isSearchPanelOpened: isSearchPanelOpened(state),
@@ -897,9 +763,7 @@ function mapDispatchToProps(dispatch) {
toggleProgressDialog: AppActions.toggleProgressDialog,
resetProgress: AppActions.resetProgress,
toggleEditTagDialog: AppActions.toggleEditTagDialog,
- hideNotifications: AppActions.hideNotifications,
onUploadProgress: AppActions.onUploadProgress,
- cancelDirectoryIndexing: LocationIndexActions.cancelDirectoryIndexing,
saveFile: AppActions.saveFile,
setZoomResetApp: SettingsActions.setZoomResetApp,
setZoomInApp: SettingsActions.setZoomInApp,
@@ -919,7 +783,6 @@ function mapDispatchToProps(dispatch) {
openFsEntry: AppActions.openFsEntry,
openURLExternally: AppActions.openURLExternally,
setEntryFullWidth: AppActions.setEntryFullWidth,
- setUpdateAvailable: AppActions.setUpdateAvailable,
openNextFile: AppActions.openNextFile,
openPrevFile: AppActions.openPrevFile,
toggleShowUnixHiddenEntries: SettingsActions.toggleShowUnixHiddenEntries,
@@ -955,7 +818,6 @@ const areEqual = (prevProp, nextProp) =>
nextProp.isEditTagDialogOpened === prevProp.isEditTagDialogOpened &&
nextProp.isEntryInFullWidth === prevProp.isEntryInFullWidth &&
nextProp.isHelpFeedbackPanelOpened === prevProp.isHelpFeedbackPanelOpened &&
- nextProp.isIndexing === prevProp.isIndexing &&
nextProp.isKeysDialogOpened === prevProp.isKeysDialogOpened &&
nextProp.isLicenseDialogOpened === prevProp.isLicenseDialogOpened &&
nextProp.isLocationManagerPanelOpened ===
@@ -970,13 +832,10 @@ const areEqual = (prevProp, nextProp) =>
nextProp.isTagLibraryPanelOpened === prevProp.isTagLibraryPanelOpened &&
nextProp.isThirdPartyLibsDialogOpened ===
prevProp.isThirdPartyLibsDialogOpened &&
- nextProp.isUpdateAvailable === prevProp.isUpdateAvailable &&
nextProp.isUploadProgressDialogOpened ===
prevProp.isUploadProgressDialogOpened &&
nextProp.leftSplitSize === prevProp.leftSplitSize &&
nextProp.mainSplitSize === prevProp.mainSplitSize &&
- JSON.stringify(nextProp.notificationStatus) ===
- JSON.stringify(prevProp.notificationStatus) &&
JSON.stringify(nextProp.selectedEntries) ===
JSON.stringify(prevProp.selectedEntries) &&
JSON.stringify(nextProp.openedFiles) === JSON.stringify(prevProp.openedFiles);
diff --git a/app/containers/PageNotification.tsx b/app/containers/PageNotification.tsx
new file mode 100644
index 000000000..c888f60f2
--- /dev/null
+++ b/app/containers/PageNotification.tsx
@@ -0,0 +1,199 @@
+/**
+ * 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 { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import Snackbar from '@material-ui/core/Snackbar';
+import Button from '@material-ui/core/Button';
+import IconButton from '@material-ui/core/IconButton';
+import CloseIcon from '@material-ui/icons/Close';
+import { getLastPublishedVersion } from '-/reducers/settings';
+import {
+ actions as AppActions,
+ getNotificationStatus,
+ isUpdateAvailable
+} from '../reducers/app';
+import {
+ actions as LocationIndexActions,
+ isIndexing
+} from '../reducers/location-index';
+import AppConfig from '../config';
+import i18n from '../services/i18n';
+import { Pro } from '../pro';
+
+interface Props {
+ notificationStatus: any;
+ isIndexing: boolean;
+ showNotification: (
+ text: string,
+ notificationType?: string,
+ autohide?: boolean
+ ) => void;
+ hideNotifications: () => void;
+ cancelDirectoryIndexing: () => void;
+ isUpdateAvailable: boolean;
+ lastPublishedVersion: string;
+ setUpdateAvailable: (isUpdateAvailable: boolean) => void;
+ openURLExternally: (url: string, skipConfirm: boolean) => void;
+}
+
+const PageNotification = (props: Props) => {
+ const skipRelease = () => {
+ props.setUpdateAvailable(false);
+ };
+
+ const openChangelogPage = () => {
+ props.openURLExternally(AppConfig.links.changelogURL, true);
+ };
+
+ const getLatestVersion = () => {
+ if (Pro) {
+ props.showNotification(
+ i18n.t('core:getLatestVersionPro'),
+ 'default',
+ false
+ );
+ } else {
+ props.openURLExternally(AppConfig.links.downloadURL, true);
+ }
+ props.setUpdateAvailable(false);
+ };
+
+ return (
+ <>
+ <Snackbar
+ data-tid={props.notificationStatus.tid}
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
+ open={props.notificationStatus.visible}
+ onClose={props.hideNotifications}
+ autoHideDuration={props.notificationStatus.autohide ? 3000 : undefined}
+ message={props.notificationStatus.text}
+ action={[
+ <IconButton
+ data-tid={'close' + props.notificationStatus.tid}
+ key="close"
+ aria-label={i18n.t('core:closeButton')}
+ color="inherit"
+ onClick={props.hideNotifications}
+ >
+ <CloseIcon />
+ </IconButton>
+ ]}
+ />
+ {/* <Snackbar
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
+ open={props.isGeneratingThumbs}
+ autoHideDuration={undefined}
+ message={i18n.t('core:loadingOrGeneratingThumbnails')}
+ action={[
+ <IconButton
+ key="closeButton"
+ aria-label={i18n.t('core:closeButton')}
+ color="inherit"
+ onClick={() => props.setGeneratingThumbnails(false)}
+ >
+ <CloseIcon />
+ </IconButton>
+ ]}
+ /> */}
+ <Snackbar
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
+ open={props.isIndexing}
+ autoHideDuration={undefined}
+ message="Indexing"
+ action={[
+ <Button
+ key="cancelIndexButton"
+ color="secondary"
+ size="small"
+ onClick={props.cancelDirectoryIndexing}
+ data-tid="cancelDirectoryIndexing"
+ >
+ {i18n.t('core:cancelIndexing')}
+ </Button>
+ ]}
+ />
+ <Snackbar
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
+ open={props.isUpdateAvailable}
+ autoHideDuration={undefined}
+ message={'Version ' + props.lastPublishedVersion + ' available.'}
+ action={[
+ <Button
+ key="laterButton"
+ color="secondary"
+ size="small"
+ onClick={skipRelease}
+ >
+ {i18n.t('core:later')}
+ </Button>,
+ <Button
+ key="changelogButton"
+ color="secondary"
+ size="small"
+ onClick={openChangelogPage}
+ >
+ {i18n.t('core:releaseNotes')}
+ </Button>,
+ <Button
+ key="latestVersionButton"
+ color="primary"
+ size="small"
+ onClick={getLatestVersion}
+ >
+ {i18n.t('core:getItNow')}
+ </Button>
+ ]}
+ />
+ </>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ notificationStatus: getNotificationStatus(state),
+ isIndexing: isIndexing(state),
+ isUpdateAvailable: isUpdateAvailable(state),
+ lastPublishedVersion: getLastPublishedVersion(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ showNotification: AppActions.showNotification,
+ hideNotifications: AppActions.hideNotifications,
+ cancelDirectoryIndexing: LocationIndexActions.cancelDirectoryIndexing,
+ setUpdateAvailable: AppActions.setUpdateAvailable,
+ openURLExternally: AppActions.openURLExternally
+ },
+ dispatch
+ );
+}
+
+const areEqual = (prevProp, nextProp) =>
+ JSON.stringify(nextProp.notificationStatus) ===
+ JSON.stringify(prevProp.notificationStatus) &&
+ nextProp.isIndexing === prevProp.isIndexing &&
+ nextProp.isUpdateAvailable === prevProp.isUpdateAvailable;
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(React.memo(PageNotification, areEqual));