aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/newMenu/newFolder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/newMenu/newFolder.ts')
-rw-r--r--apps/files/src/newMenu/newFolder.ts52
1 files changed, 24 insertions, 28 deletions
diff --git a/apps/files/src/newMenu/newFolder.ts b/apps/files/src/newMenu/newFolder.ts
index 5d378cab438..f0f854d2801 100644
--- a/apps/files/src/newMenu/newFolder.ts
+++ b/apps/files/src/newMenu/newFolder.ts
@@ -1,23 +1,6 @@
/**
- * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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 <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Entry, Node } from '@nextcloud/files'
@@ -25,11 +8,11 @@ import { basename } from 'path'
import { emit } from '@nextcloud/event-bus'
import { getCurrentUser } from '@nextcloud/auth'
import { Permission, Folder } from '@nextcloud/files'
-import { showSuccess } from '@nextcloud/dialogs'
+import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
-import FolderPlusSvg from '@mdi/svg/svg/folder-plus.svg?raw'
+import FolderPlusSvg from '@mdi/svg/svg/folder-plus-outline.svg?raw'
import { newNodeName } from '../utils/newNodeDialog'
import logger from '../logger'
@@ -59,19 +42,26 @@ const createNewFolder = async (root: Folder, name: string): Promise<createFolder
export const entry = {
id: 'newFolder',
displayName: t('files', 'New folder'),
- enabled: (context: Folder) => (context.permissions & Permission.CREATE) !== 0,
- iconSvgInline: FolderPlusSvg,
+ enabled: (context: Folder) => Boolean(context.permissions & Permission.CREATE) && Boolean(context.permissions & Permission.READ),
+
+ // Make the svg icon color match the primary element color
+ iconSvgInline: FolderPlusSvg.replace(/viewBox/gi, 'style="color: var(--color-primary-element)" viewBox'),
order: 0,
+
async handler(context: Folder, content: Node[]) {
const name = await newNodeName(t('files', 'New folder'), content)
- if (name !== null) {
- const { fileid, source } = await createNewFolder(context, name)
+ if (name === null) {
+ return
+ }
+ try {
+ const { fileid, source } = await createNewFolder(context, name.trim())
+
// Create the folder in the store
const folder = new Folder({
source,
id: fileid,
mtime: new Date(),
- owner: getCurrentUser()?.uid || null,
+ owner: context.owner,
permissions: Permission.ALL,
root: context?.root || '/files/' + getCurrentUser()?.uid,
// Include mount-type from parent folder as this is inherited
@@ -82,14 +72,20 @@ export const entry = {
},
})
+ // Show success
+ emit('files:node:created', folder)
showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))
logger.debug('Created new folder', { folder, source })
- emit('files:node:created', folder)
+
+ // Navigate to the new folder
window.OCP.Files.Router.goToRoute(
null, // use default route
- { view: 'files', fileid: folder.fileid },
+ { view: 'files', fileid: String(fileid) },
{ dir: context.path },
)
+ } catch (error) {
+ logger.error('Creating new folder failed', { error })
+ showError('Creating new folder failed')
}
},
} as Entry