Skip to content

Commit

Permalink
Refactor routeOptsHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Jun 27, 2024
1 parent a70f5e6 commit 1a29ef3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/web-pkg/src/components/AppTopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</oc-drop>
</template>
<span v-if="hasAutosave" class="oc-flex oc-flex-middle">
<oc-icon name="refresh" color="white" v-oc-tooltip="autoSaveTooltipText" />
<oc-icon v-oc-tooltip="autoSaveTooltipText" name="refresh" color="white" />
</span>
<template v-if="mainActions.length && resource">
<context-action-menu
Expand Down
29 changes: 10 additions & 19 deletions packages/web-pkg/src/components/Modals/FilePickerModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
useModals,
useRouter,
useThemeStore,
useConfigStore,
routeToContextQuery
useFileActions
} from '../../composables'
import { ApplicationInformation } from '../../apps'
import { RouteLocationRaw } from 'vue-router'
Expand All @@ -41,7 +40,7 @@ export default defineComponent({
const { removeModal } = useModals()
const { getMatchingSpace } = useGetMatchingSpace()
const themeStore = useThemeStore()
const configStore = useConfigStore()
const { getEditorRouteOpts } = useFileActions()
const parentFolderRoute = router.resolve(props.parentFolderLink)
const availableFileTypes = (props.app as ApplicationInformation).extensions.map((e) =>
Expand All @@ -67,22 +66,14 @@ export default defineComponent({
const space = getMatchingSpace(resource)
const remoteItemId = isShareSpaceResource(space) ? space.id : undefined
const editorRoute = router.resolve({
name: unref(router.currentRoute).name,
params: {
driveAliasAndItem: space.getDriveAliasAndItem(resource),
filePath: resource.path,
fileId: resource.fileId,
EDITOR_MODE_EDIT
},
query: {
...(remoteItemId && { shareId: remoteItemId }),
...(resource.fileId &&
configStore.options.routing.idBased && { fileId: resource.fileId }),
...routeToContextQuery(unref(router.currentRoute))
}
})
const routeOpts = getEditorRouteOpts(
unref(router.currentRoute).name,
space,
resource,
EDITOR_MODE_EDIT,
remoteItemId
)
const editorRoute = router.resolve(routeOpts)
const editorRouteUrl = new URL(editorRoute.href, window.location.origin)
removeModal(props.modal.id)
Expand Down
11 changes: 7 additions & 4 deletions packages/web-pkg/src/composables/actions/files/useFileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ApplicationFileExtension } from '../../../apps'
import { Resource, SpaceResource } from '@ownclouders/web-client'
import { storeToRefs } from 'pinia'
import { useEmbedMode } from '../../embedMode'
import { RouteRecordName } from 'vue-router'

export const EDITOR_MODE_EDIT = 'edit'
export const EDITOR_MODE_CREATE = 'create'
Expand Down Expand Up @@ -152,15 +153,15 @@ export const useFileActions = () => {
})
})

const routeOptsHelper = (
appFileExtension: ApplicationFileExtension,
const getEditorRouteOpts = (
routeName: RouteRecordName,
space: SpaceResource,
resource: Resource,
mode: string,
remoteItemId: string
) => {
return {
name: appFileExtension.routeName || appFileExtension.app,
name: routeName,
params: {
driveAliasAndItem: space.getDriveAliasAndItem(resource),
filePath: resource.path,
Expand All @@ -182,7 +183,8 @@ export const useFileActions = () => {
mode: string
) => {
const remoteItemId = isShareSpaceResource(space) ? space.id : undefined
const routeOpts = routeOptsHelper(appFileExtension, space, resource, mode, remoteItemId)
const routeName = appFileExtension.routeName || appFileExtension.app
const routeOpts = getEditorRouteOpts(routeName, space, resource, mode, remoteItemId)

if (configStore.options.openAppsInTab) {
const path = router.resolve(routeOpts).href
Expand Down Expand Up @@ -252,6 +254,7 @@ export const useFileActions = () => {
getDefaultAction,
getDefaultEditorAction,
getAllAvailableActions,
getEditorRouteOpts,
openEditor,
triggerAction,
triggerDefaultAction
Expand Down

0 comments on commit 1a29ef3

Please sign in to comment.