Skip to content

Commit

Permalink
Feature/7600 - scroll to newly created folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwengerter committed Jun 1, 2023
1 parent 237abab commit 7d92c0b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/feature-scroll-to-created-folder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Scroll to newly created folder

After creating a new folder that gets sorted into the currently displayed resources but outside of the current viewport, we now scroll to the new folder.

https://github.com/owncloud/web/issues/7600
https://github.com/owncloud/web/pulls/8145
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default defineComponent({
resetSelectionCursor()
store.dispatch('Files/resetFileSelection')
store.commit('Files/ADD_FILE_SELECTION', { id: nextId })
scrollToResource({ id: nextId } as any)
scrollToResource(nextId)
}
const handleCtrlClickAction = (resource) => {
store.dispatch('Files/toggleFileSelection', { id: resource.id })
Expand All @@ -148,7 +148,7 @@ export default defineComponent({
// select
store.commit('Files/ADD_FILE_SELECTION', { id: nextResourceId })
}
scrollToResource({ id: nextResourceId } as any)
scrollToResource(nextResourceId)
selectionCursor.value = unref(selectionCursor) - 1
}
const handleShiftDownAction = () => {
Expand All @@ -164,7 +164,7 @@ export default defineComponent({
// select
store.commit('Files/ADD_FILE_SELECTION', { id: nextResourceId })
}
scrollToResource({ id: nextResourceId } as any)
scrollToResource(nextResourceId)
selectionCursor.value = unref(selectionCursor) + 1
}
const handleShiftClickAction = ({ resource, skipTargetSelection }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { join } from 'path'
import { WebDAV } from 'web-client/src/webdav'
import { isLocationSpacesActive } from 'web-app-files/src/router'
import { getIndicators } from 'web-app-files/src/helpers/statusIndicators'
import { useScrollTo } from '../../scrollTo/useScrollTo'

export const useFileActionsCreateNewFolder = ({
store,
Expand All @@ -17,6 +18,7 @@ export const useFileActionsCreateNewFolder = ({
store = store || useStore()
const router = useRouter()
const { $gettext } = useGettext()
const { scrollToResource } = useScrollTo()

const clientService = useClientService()
const currentFolder = computed((): Resource => store.getters['Files/currentFolder'])
Expand Down Expand Up @@ -66,12 +68,14 @@ export const useFileActionsCreateNewFolder = ({
resource.indicators = getIndicators({ resource, ancestorMetaData: unref(ancestorMetaData) })
}

store.commit('Files/UPSERT_RESOURCE', resource)
await store.commit('Files/UPSERT_RESOURCE', resource)
store.dispatch('hideModal')

store.dispatch('showMessage', {
title: $gettext('"%{folderName}" was created successfully', { folderName })
})

scrollToResource(resource.id)
} catch (error) {
console.error(error)
store.dispatch('showMessage', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useRouteQuery } from 'web-pkg/src/composables'
import { SideBarEventTopics } from 'web-pkg/src/composables/sideBar'

export interface ScrollToResult {
scrollToResource(resource: Resource): void
scrollToResource(resourceId: string | number): void
scrollToResourceFromRoute(resources: Resource[]): void
}

Expand All @@ -21,9 +21,9 @@ export const useScrollTo = (): ScrollToResult => {
return queryItemAsString(unref(detailsQuery))
})

const scrollToResource = (resource) => {
const scrollToResource = (resourceId) => {
const resourceElement = document.querySelectorAll(
`[data-item-id='${resource.id}']`
`[data-item-id='${resourceId}']`
)[0] as HTMLElement

if (!resourceElement) {
Expand All @@ -32,7 +32,7 @@ export const useScrollTo = (): ScrollToResult => {

// bottom reached
if (resourceElement.getBoundingClientRect().bottom > window.innerHeight) {
resourceElement.scrollIntoView(false)
resourceElement.scrollIntoView({ behavior: 'smooth', block: 'center' })
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('useScrollTo', () => {
getComposableWrapper(
() => {
const { scrollToResource } = useScrollTo()
scrollToResource(mockDeep<Resource>())
scrollToResource('mockResourceId')
expect(htmlPageObject.scrollIntoView).not.toHaveBeenCalled()
},
{ mocks: defaultComponentMocks(), store: defaultStoreMockOptions }
Expand All @@ -39,7 +39,7 @@ describe('useScrollTo', () => {
getComposableWrapper(
() => {
const { scrollToResource } = useScrollTo()
scrollToResource(mockDeep<Resource>())
scrollToResource('mockResourceId')
expect(htmlPageObject.scrollIntoView).toHaveBeenCalled()
},
{ mocks: defaultComponentMocks(), store: defaultStoreMockOptions }
Expand All @@ -56,7 +56,7 @@ describe('useScrollTo', () => {
getComposableWrapper(
() => {
const { scrollToResource } = useScrollTo()
scrollToResource(mockDeep<Resource>())
scrollToResource('mockResourceId')
expect(htmlPageObject.scrollBy).toHaveBeenCalled()
},
{ mocks: defaultComponentMocks(), store: defaultStoreMockOptions }
Expand Down

0 comments on commit 7d92c0b

Please sign in to comment.