Skip to content

Commit

Permalink
fix: avoid side-effect imports
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv authored and susnux committed Sep 21, 2023
1 parent a1a1b99 commit a5a8655
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 228 deletions.
1 change: 1 addition & 0 deletions apps/comments/lib/Listener/LoadAdditionalScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ public function handle(Event $event): void {
// TODO: make sure to only include the sidebar script when
// we properly split it between files list and sidebar
Util::addScript(Application::APP_ID, 'comments');
Util::addInitScript(Application::APP_ID, 'init');
}
}
1 change: 0 additions & 1 deletion apps/comments/src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
import './app.js'
import './templates.js'
import './activitytabviewplugin.js'
import './actions/inlineUnreadCommentsAction.ts'

window.OCA.Comments = OCA.Comments
25 changes: 25 additions & 0 deletions apps/comments/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @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/>.
*
*/
import { registerFileAction } from '@nextcloud/files'
import { action } from './actions/inlineUnreadCommentsAction'

registerFileAction(action)
1 change: 1 addition & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
}

// Load the files we need
\OCP\Util::addInitScript('files', 'init');
\OCP\Util::addStyle('files', 'merged');
\OCP\Util::addScript('files', 'merged-index', 'files');
\OCP\Util::addScript('files', 'main');
Expand Down
4 changes: 1 addition & 3 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, Node, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'
Expand Down Expand Up @@ -62,5 +62,3 @@ export const action = new FileAction({

order: 100,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/downloadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { generateUrl } from '@nextcloud/router'
import { registerFileAction, FileAction, Permission, Node, FileType, View } from '@nextcloud/files'
import { FileAction, Permission, Node, FileType, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw'

Expand Down Expand Up @@ -86,5 +86,3 @@ export const action = new FileAction({

order: 30,
})

registerFileAction(action)
6 changes: 1 addition & 5 deletions apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { encodePath } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { registerFileAction, FileAction, Permission, type Node } from '@nextcloud/files'
import { FileAction, Permission, type Node } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
Expand Down Expand Up @@ -66,7 +66,3 @@ export const action = new FileAction({

order: 25,
})

if (!/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
registerFileAction(action)
}
4 changes: 1 addition & 3 deletions apps/files/src/actions/favoriteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { Permission, type Node, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, type Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import Vue from 'vue'
Expand Down Expand Up @@ -101,5 +101,3 @@ export const action = new FileAction({

order: -50,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { join } from 'path'
import { Permission, Node, FileType, View, registerFileAction, FileAction, DefaultType } from '@nextcloud/files'
import { Permission, Node, FileType, View, FileAction, DefaultType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderSvg from '@mdi/svg/svg/folder.svg?raw'

Expand Down Expand Up @@ -66,5 +66,3 @@ export const action = new FileAction({
default: DefaultType.HIDDEN,
order: -100,
})

registerFileAction(action)
6 changes: 1 addition & 5 deletions apps/files/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
*
*/
import { translate as t } from '@nextcloud/l10n'
import { FileType, type Node } from '@nextcloud/files'

import { registerFileAction, FileAction, DefaultType } from '@nextcloud/files'
import { type Node, FileType, FileAction, DefaultType } from '@nextcloud/files'

/**
* TODO: Move away from a redirect and handle
Expand Down Expand Up @@ -53,5 +51,3 @@ export const action = new FileAction({
order: -1000,
default: DefaultType.HIDDEN,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, type Node, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, type Node, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'

Expand All @@ -45,5 +45,3 @@ export const action = new FileAction({

order: 10,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, type Node, View, registerFileAction, FileAction, FileType } from '@nextcloud/files'
import { Permission, type Node, View, FileAction, FileType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'

Expand Down Expand Up @@ -73,5 +73,3 @@ export const action = new FileAction({

order: -50,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/viewInFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Node, FileType, Permission, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Node, FileType, Permission, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw'

Expand Down Expand Up @@ -64,5 +64,3 @@ export const action = new FileAction({

order: 80,
})

registerFileAction(action)
59 changes: 59 additions & 0 deletions apps/files/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @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/>.
*
*/
import { action as deleteAction } from './actions/deleteAction'
import { action as downloadAction } from './actions/downloadAction'
import { action as editLocallyAction } from './actions/editLocallyAction'
import { action as favoriteAction } from './actions/favoriteAction'
import { action as openFolderAction } from './actions/openFolderAction'
import { action as openInFilesAction } from './actions/openInFilesAction'
import { action as renameAction } from './actions/renameAction'
import { action as sidebarAction } from './actions/sidebarAction'
import { action as viewInFolderAction } from './actions/viewInFolderAction'
import { entry as newFolderEntry } from './newMenu/newFolder'

import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
import registerFilesView from './views/files'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import { addNewFileMenuEntry, registerFileAction } from '@nextcloud/files'

// Register file actions
registerFileAction(deleteAction)
registerFileAction(downloadAction)
registerFileAction(editLocallyAction)
registerFileAction(favoriteAction)
registerFileAction(openFolderAction)
registerFileAction(openInFilesAction)
registerFileAction(renameAction)
registerFileAction(sidebarAction)
registerFileAction(viewInFolderAction)

// Register new menu entry
addNewFileMenuEntry(newFolderEntry)

// Register files views
registerFavoritesView()
registerFilesView()
registerRecentView()

// Register preview service worker
registerPreviewServiceWorker()
23 changes: 0 additions & 23 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import './templates.js'
import './legacy/filelistSearch.js'

import './actions/deleteAction'
import './actions/downloadAction'
import './actions/editLocallyAction'
import './actions/favoriteAction'
import './actions/openFolderAction'
import './actions/openInFilesAction.js'
import './actions/renameAction'
import './actions/sidebarAction'
import './actions/viewInFolderAction'
import './newMenu/newFolder'

import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'
import { getNavigation } from '@nextcloud/files'
import { getRequestToken } from '@nextcloud/auth'

import FilesListView from './views/FilesList.vue'
import NavigationView from './views/Navigation.vue'
import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
import registerFilesView from './views/files'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import router from './router/router'
import RouterService from './services/RouterService'
import SettingsModel from './models/Setting.js'
Expand Down Expand Up @@ -80,11 +65,3 @@ const FilesList = new ListView({
pinia,
})
FilesList.$mount('#app-content-vue')

// Init legacy and new files views
registerFavoritesView()
registerFilesView()
registerRecentView()

// Register preview service worker
registerPreviewServiceWorker()
4 changes: 1 addition & 3 deletions apps/files/src/newMenu/newFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getUniqueName = (name: string, names: string[]): string => {
return newName
}

const entry = {
export const entry = {
id: 'newFolder',
displayName: t('files', 'New folder'),
if: (context: Folder) => (context.permissions & Permission.CREATE) !== 0,
Expand Down Expand Up @@ -92,5 +92,3 @@ const entry = {
emit('files:node:rename', folder)
},
} as Entry

addNewFileMenuEntry(entry)
Loading

0 comments on commit a5a8655

Please sign in to comment.