Skip to content

Commit

Permalink
fix: context sensitive preview loading
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Nov 26, 2024
1 parent cee8128 commit 41c3591
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Ref, ref, unref, MaybeRef } from 'vue'
import { dirname } from 'path'
import { ClientService } from '../../services'
import { ClientService, folderService } from '../../services'
import { useAppFileHandling } from './useAppFileHandling'
import { buildIncomingShareResource, Resource } from '@ownclouders/web-client'
import { Resource } from '@ownclouders/web-client'
import { FileContext } from './types'
import { RouteLocationNormalizedLoaded } from 'vue-router'
import { useFileRouteReplace } from '../router/useFileRouteReplace'
import { DavProperty } from '@ownclouders/web-client/webdav'
import { useAuthService } from '../authContext/useAuthService'
import { isMountPointSpaceResource } from '@ownclouders/web-client'
import { useResourcesStore, useSharesStore, useSpacesStore } from '../piniaStores'
import { useResourcesStore, useSpacesStore } from '../piniaStores'
import { storeToRefs } from 'pinia'
import { useRouteQuery } from '../router'

interface AppFolderHandlingOptions {
currentRoute: Ref<RouteLocationNormalizedLoaded>
Expand All @@ -29,12 +30,12 @@ export function useAppFolderHandling({
clientService
}: AppFolderHandlingOptions): AppFolderHandlingResult {
const isFolderLoading = ref(false)
const { webdav, graphAuthenticated } = clientService
const { webdav } = clientService
const { replaceInvalidFileRoute } = useFileRouteReplace()
const { getFileInfo } = useAppFileHandling({ clientService })
const authService = useAuthService()
const spacesStore = useSpacesStore()
const sharesStore = useSharesStore()
const currentRouteQuery = useRouteQuery('contextRouteParams')

const resourcesStore = useResourcesStore()
const { activeResources } = storeToRefs(resourcesStore)
Expand All @@ -45,17 +46,11 @@ export function useAppFolderHandling({
try {
context = unref(context)

if (context.routeName === 'files-shares-with-me') {
// FIXME: this is a somewhat hacky solution to load the shared with me files.
// ideally we should check if there is a current folder and if not, use the
// folder loader to load files. unfortunately, it currently lives in the files app.
const driveItems = await graphAuthenticated.driveItems.listSharedWithMe()

const resources = driveItems.map((driveItem) =>
buildIncomingShareResource({ driveItem, graphRoles: sharesStore.graphRoles })
)

resourcesStore.initResourceList({ currentFolder: null, resources })
if (!(unref(currentRouteQuery) as any).driveAliasAndItem) {
// when there is no driveAliasAndItem, we are in a file list without space.
// use the folder loader in this case to load the resources.
const loaderTask = folderService.getTask()
await loaderTask.perform()
isFolderLoading.value = false
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FolderLoader, FolderLoaderTask, TaskContext } from '../folderService'
import { unref } from 'vue'
import { Router } from 'vue-router'
import { useTask } from 'vue-concurrency'
import { isLocationSharesActive } from '../../../router'
Expand All @@ -10,7 +11,11 @@ export class FolderLoaderSharedWithOthers implements FolderLoader {
}

public isActive(router: Router): boolean {
return isLocationSharesActive(router, 'files-shares-with-others')
const currentRoute = unref(router.currentRoute)
return (
isLocationSharesActive(router, 'files-shares-with-others') ||
currentRoute?.query?.contextRouteName === 'files-shares-with-others'
)
}

public getTask(context: TaskContext): FolderLoaderTask {
Expand Down

0 comments on commit 41c3591

Please sign in to comment.