TagSpaces is an offline, open source, document manager with tagging support
feat: add dialog for recording audio (#1998)
Stanimir259350b7f517
diff --git a/app/components/dialogs/NewAudioDialog.tsx b/app/components/dialogs/NewAudioDialog.tsxnew file mode 100644index 000000000..0cfb5debe--- /dev/null+++ b/app/components/dialogs/NewAudioDialog.tsx@@ -0,0 +1,78 @@+/**+ * 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 DialogContent from '@mui/material/DialogContent';+import DialogTitle from '@mui/material/DialogTitle';+import Dialog from '@mui/material/Dialog';+import Paper from '@mui/material/Paper';+import DraggablePaper from '-/components/DraggablePaper';+import DialogCloseButton from '-/components/dialogs/DialogCloseButton';+import { useTheme } from '@mui/material/styles';+import useMediaQuery from '@mui/material/useMediaQuery';+import TargetPath from '-/components/dialogs/components/TargetPath';+import { TargetPathContextProvider } from '-/components/dialogs/hooks/TargetPathContextProvider';+import { useTranslation } from 'react-i18next';+import { Pro } from '-/pro';++interface Props {+ open: boolean;+ onClose: () => void;+}++const CreateAudio = Pro && Pro.UI ? Pro.UI.CreateAudio : false;++function NewAudioDialog(props: Props) {+ const { open, onClose } = props;+ const { t } = useTranslation();++ const theme = useTheme();+ const fullScreen = useMediaQuery(theme.breakpoints.down('md'));+ return (+ <TargetPathContextProvider>+ <Dialog+ open={open}+ onClose={onClose}+ fullScreen={fullScreen}+ keepMounted+ aria-labelledby="draggable-dialog-title"+ PaperComponent={fullScreen ? Paper : DraggablePaper}+ scroll="paper"+ >+ <DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">+ {t('core:createAudio')}+ <DialogCloseButton testId="closeCreateDialogTID" onClose={onClose} />+ </DialogTitle>+ <DialogContent+ style={{+ minWidth: 200,+ minHeight: 200,+ marginBottom: 20,+ overflow: 'overlay'+ }}+ data-tid="keyboardShortCutsDialog"+ >+ <CreateAudio onClose={onClose} />+ <TargetPath />+ </DialogContent>+ </Dialog>+ </TargetPathContextProvider>+ );+}++export default NewAudioDialog;diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex caa93a4c4..9653e1511 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -224,6 +224,10 @@ function DirectoryMenu(props: Props) {toggleNewFileDialog();}+ function createNewAudio() {+ dispatch(AppActions.toggleNewAudioDialog());+ }+function showInFileManager() {PlatformIO.openDirectory(directoryPath);}@@ -409,6 +413,7 @@ Do you want to continue?`)showDeleteDirectoryDialog,showInFileManager,createNewFile,+ createNewAudio,toggleCreateDirectoryDialog,addExistingFile,setFolderThumbnail,diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex 1e86af751..67820b9d8 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -65,7 +65,8 @@ import {currentUser,isLocationDialogOpened,isProTeaserVisible,- isTruncatedConfirmDialogOpened+ isTruncatedConfirmDialogOpened,+ isNewAudioDialogOpened} from '../reducers/app';import TargetFileBox from '../components/TargetFileBox';import LoadingLazy from '../components/LoadingLazy';@@ -92,6 +93,7 @@ import { useIOActionsContext } from '-/hooks/useIOActionsContext';import { extractDirectoryName } from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';import { useNotificationContext } from '-/hooks/useNotificationContext';+import NewAudioDialog from '-/components/dialogs/NewAudioDialog';const drawerWidth = 320;const body = document.getElementsByTagName('body')[0];@@ -139,6 +141,7 @@ interface Props {isSettingsDialogOpened: boolean;isNewEntryDialogOpened: boolean;isNewFileDialogOpened: boolean;+ isNewAudioDialogOpened: boolean;isCreateDirectoryOpened: any;toggleCreateDirectoryDialog: () => void;isAboutDialogOpened: boolean;@@ -164,6 +167,7 @@ interface Props {setZoomOutApp: () => void; // needed by electron-menustoggleNewEntryDialog: () => void; // needed by electron-menustoggleNewFileDialog: () => void; // needed by electron-menus+ toggleNewAudioDialog: () => void; // needed by electron-menusshowCreateDirectoryDialog: () => void; // needed by electron-menustoggleSettingsDialog: () => void; // needed by electron-menustoggleKeysDialog: () => void; // needed by electron-menus@@ -500,6 +504,7 @@ function MainPage(props: Props) {toggleCreateDirectoryDialog,toggleNewEntryDialog,toggleNewFileDialog,+ toggleNewAudioDialog,toggleUploadDialog,toggleProgressDialog,toggleEditTagDialog,@@ -688,6 +693,12 @@ function MainPage(props: Props) {onClose={toggleNewFileDialog}/>)}+ {props.isNewAudioDialogOpened && (+ <NewAudioDialog+ open={props.isNewAudioDialogOpened}+ onClose={toggleNewAudioDialog}+ />+ )}<SettingsDialogopen={props.isSettingsDialogOpened}onClose={toggleSettingsDialog}@@ -810,6 +821,7 @@ function mapStateToProps(state) {isCreateDirectoryOpened: isCreateDirectoryOpened(state),isNewEntryDialogOpened: isNewEntryDialogOpened(state),isNewFileDialogOpened: isNewFileDialogOpened(state),+ isNewAudioDialogOpened: isNewAudioDialogOpened(state),isSettingsDialogOpened: isSettingsDialogOpened(state),isAboutDialogOpened: isAboutDialogOpened(state),isLocationDialogOpened: isLocationDialogOpened(state),@@ -853,6 +865,7 @@ function mapDispatchToProps(dispatch) {setZoomOutApp: SettingsActions.setZoomOutApp,toggleNewEntryDialog: AppActions.toggleNewEntryDialog,toggleNewFileDialog: AppActions.toggleNewFileDialog,+ toggleNewAudioDialog: AppActions.toggleNewAudioDialog,showCreateDirectoryDialog: AppActions.showCreateDirectoryDialog,toggleSettingsDialog: AppActions.toggleSettingsDialog,toggleKeysDialog: AppActions.toggleKeysDialog,@@ -889,6 +902,7 @@ const areEqual = (prevProp, nextProp) =>JSON.stringify(prevProp.isCreateDirectoryOpened) &&nextProp.isNewEntryDialogOpened === prevProp.isNewEntryDialogOpened &&nextProp.isNewFileDialogOpened === prevProp.isNewFileDialogOpened &&+ nextProp.isNewAudioDialogOpened === prevProp.isNewAudioDialogOpened &&nextProp.isDeleteMultipleEntriesDialogOpened ===prevProp.isDeleteMultipleEntriesDialogOpened &&nextProp.isDesktopMode === prevProp.isDesktopMode &&diff --git a/app/perspectives/common/DirectoryMenuItems.tsx b/app/perspectives/common/DirectoryMenuItems.tsxindex 47a3eade0..6038239cb 100644--- a/app/perspectives/common/DirectoryMenuItems.tsx+++ b/app/perspectives/common/DirectoryMenuItems.tsx@@ -1,5 +1,6 @@import MenuItem from '@mui/material/MenuItem';import ListItemIcon from '@mui/material/ListItemIcon';+import AudioFileIcon from '@mui/icons-material/AudioFile';import OpenFolderIcon from '@mui/icons-material/SubdirectoryArrowLeft';import MoveCopy from '@mui/icons-material/FileCopy';import ListItemText from '@mui/material/ListItemText';@@ -41,6 +42,7 @@ export function getDirectoryMenuItems(showDeleteDirectoryDialog?: () => void,showInFileManager?: () => void,createNewFile?: () => void,+ createNewAudio?: () => void,showCreateDirectoryDialog?: () => void,addExistingFile?: () => void,setFolderThumbnail?: () => void,@@ -210,6 +212,23 @@ export function getDirectoryMenuItems(</MenuItem>);}+ if (Pro && createNewAudio) {+ menuItems.push(+ <MenuItem+ key="createNewAudio"+ data-tid="createNewAudioTID"+ onClick={() => {+ onClose();+ createNewAudio();+ }}+ >+ <ListItemIcon>+ <AudioFileIcon />+ </ListItemIcon>+ <ListItemText primary={t('core:newAudioFile')} />+ </MenuItem>+ );+ }if (showCreateDirectoryDialog) {menuItems.push(<MenuItemdiff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 1f7a26511..00200aab3 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -84,6 +84,7 @@ export const types = {TOGGLE_CREATE_DIRECTORY_DIALOG: 'APP/TOGGLE_CREATE_DIRECTORY_DIALOG',TOGGLE_NEW_ENTRY_DIALOG: 'APP/TOGGLE_NEW_ENTRY_DIALOG',TOGGLE_NEW_FILE_DIALOG: 'APP/TOGGLE_NEW_FILE_DIALOG',+ TOGGLE_NEW_AUDIO_DIALOG: 'APP/TOGGLE_NEW_AUDIO_DIALOG',TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG:'APP/TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG',TOGGLE_IMPORT_KANBAN_DIALOG: 'APP/TOGGLE_IMPORT_KANBAN_DIALOG',@@ -195,6 +196,7 @@ export const initialState = {keysDialogOpened: false,isNewEntryDialogOpened: false,isNewFileDialogOpened: false,+ isNewAudioDialogOpened: false,licenseDialogOpened: false,thirdPartyLibsDialogOpened: false,settingsDialogOpened: false,@@ -353,6 +355,12 @@ export default (state: any = initialState, action: any) => {isNewFileDialogOpened: !state.isNewFileDialogOpened};}+ case types.TOGGLE_NEW_AUDIO_DIALOG: {+ return {+ ...state,+ isNewAudioDialogOpened: !state.isNewAudioDialogOpened+ };+ }case types.TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG: {return {...state,@@ -926,6 +934,7 @@ export const actions = {}),toggleNewEntryDialog: () => ({ type: types.TOGGLE_NEW_ENTRY_DIALOG }),toggleNewFileDialog: () => ({ type: types.TOGGLE_NEW_FILE_DIALOG }),+ toggleNewAudioDialog: () => ({ type: types.TOGGLE_NEW_AUDIO_DIALOG }),toggleDeleteMultipleEntriesDialog: () => ({type: types.TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG}),@@ -1123,6 +1132,8 @@ export const isNewEntryDialogOpened = (state: any) =>state.app.isNewEntryDialogOpened;export const isNewFileDialogOpened = (state: any) =>state.app.isNewFileDialogOpened;+export const isNewAudioDialogOpened = (state: any) =>+ state.app.isNewAudioDialogOpened;export const isDeleteMultipleEntriesDialogOpened = (state: any) =>state.app.deleteMultipleEntriesDialogOpened;export const isImportKanBanDialogOpened = (state: any) =>diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex fbbc0696a..5f2bd5552 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -43,28 +43,16 @@ import {extractDirectoryName,extractFileName,normalizePath,- getThumbFileLocationForFile,getThumbFileLocationForDirectory,getBgndFileLocationForDirectory,- cleanFrontDirSeparator,- generateSharingLink,- cleanRootPath+ cleanFrontDirSeparator} from '@tagspaces/tagspaces-common/paths';import AppConfig from '-/AppConfig';import PlatformIO from './platform-facade';import versionMeta from '../version.json';-import { OpenedEntry, actions as AppActions } from '-/reducers/app';-import { getLocation } from '-/reducers/locations';+import { OpenedEntry } from '-/reducers/app';import { TS } from '-/tagspaces.namespace';-import {- getThumbnailURLPromise,- supportedContainers,- supportedImgs,- supportedText,- supportedVideos,- supportedMisc,- generateImageThumbnail-} from '-/services/thumbsgenerator';+import { generateImageThumbnail } from '-/services/thumbsgenerator';import { base64ToArrayBuffer } from '-/utils/dom';import { Pro } from '-/pro';import { supportedFileTypes } from '-/extension-config';