Skip to content

Commit

Permalink
fix: space loading task in trash and spaces overviews
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Mar 7, 2023
1 parent 2d36ab6 commit 59b580d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
24 changes: 16 additions & 8 deletions packages/web-app-files/src/views/spaces/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<create-space v-if="hasCreatePermission" />
</template>
</app-bar>
<app-loading-spinner v-if="loadResourcesTask.isRunning" />
<app-loading-spinner v-if="areResourcesLoading" />
<template v-else>
<no-content-message
v-if="!spaces.length"
Expand Down Expand Up @@ -129,19 +129,26 @@ export default defineComponent({
const { scrollToResourceFromRoute } = useScrollTo()
const loadResourcesTask = useTask(function* () {
const loadResourcesTask = useTask(function* (signal, reloadProjectSpaces: boolean) {
store.commit('Files/CLEAR_FILES_SEARCHED')
store.commit('Files/CLEAR_CURRENT_FILES_LIST')
yield store.dispatch('runtime/spaces/reloadProjectSpaces', {
graphClient: unref(graphClient)
})
if (reloadProjectSpaces) {
yield store.dispatch('runtime/spaces/reloadProjectSpaces', {
graphClient: unref(graphClient)
})
}
store.commit('Files/LOAD_FILES', { currentFolder: null, files: unref(spaces) })
})
const areResourcesLoading = computed(() => {
return loadResourcesTask.isRunning || !loadResourcesTask.last
})
const hasCreatePermission = computed(() => can('create-all', 'Space'))
const viewModes = computed(() => [ViewModeConstants.tilesView])
onMounted(() => {
store.commit('Files/LOAD_FILES', { currentFolder: null, files: unref(spaces) })
onMounted(async () => {
await loadResourcesTask.perform(false)
scrollToResourceFromRoute(unref(spaces) as Resource[])
})
Expand All @@ -150,6 +157,7 @@ export default defineComponent({
spaces,
graphClient,
loadResourcesTask,
areResourcesLoading,
accessToken,
selectedResourcesIds,
handleSort,
Expand All @@ -172,7 +180,7 @@ export default defineComponent({
return [
{
text: this.$gettext('Spaces'),
onClick: () => this.loadResourcesTask.perform()
onClick: () => this.loadResourcesTask.perform(true)
}
]
},
Expand Down
27 changes: 17 additions & 10 deletions packages/web-app-files/src/views/trash/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:has-file-extensions="false"
:has-pagination="false"
/>
<app-loading-spinner v-if="loadResourcesTask.isRunning" />
<app-loading-spinner v-if="areResourcesLoading" />
<template v-else>
<oc-text-input
id="spaces-filter"
Expand Down Expand Up @@ -92,15 +92,21 @@ export default defineComponent({
)
)
const loadResourcesTask = useTask(function* () {
const loadResourcesTask = useTask(function* (signal, reloadProjectSpaces: boolean) {
store.commit('Files/CLEAR_FILES_SEARCHED')
store.commit('Files/CLEAR_CURRENT_FILES_LIST')
yield store.dispatch('runtime/spaces/reloadProjectSpaces', {
graphClient: unref(graphClient)
})
if (reloadProjectSpaces) {
yield store.dispatch('runtime/spaces/reloadProjectSpaces', {
graphClient: unref(graphClient)
})
}
store.commit('Files/LOAD_FILES', { currentFolder: null, files: unref(spaces) })
})
const areResourcesLoading = computed(() => {
return loadResourcesTask.isRunning || !loadResourcesTask.last
})
const footerTextTotal = computed(() => {
return $gettext('%{spaceCount} trashes in total', {
spaceCount: unref(spaces).length.toString()
Expand All @@ -113,7 +119,7 @@ export default defineComponent({
})
const breadcrumbs = computed(() => [
{ text: $gettext('Deleted files'), onClick: () => loadResourcesTask.perform() }
{ text: $gettext('Deleted files'), onClick: () => loadResourcesTask.perform(true) }
])
const sort = (list: SpaceResource[], propName: string, desc: boolean) => {
Expand Down Expand Up @@ -177,14 +183,14 @@ export default defineComponent({
})
}
onMounted(() => {
onMounted(async () => {
if (unref(spaces).length === 1) {
return router.push(getTrashLink(unref(spaces).pop()))
}
nextTick(() => {
markInstance.value = new Mark(unref(tableRef)?.$el)
})
await loadResourcesTask.perform(false)
await nextTick()
markInstance.value = new Mark(unref(tableRef)?.$el)
})
watch(filterTerm, () => {
Expand Down Expand Up @@ -216,6 +222,7 @@ export default defineComponent({
getSpaceName,
getTrashLink,
loadResourcesTask,
areResourcesLoading,
isPersonalSpaceResource
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ describe('TrashOverview', () => {
describe('view states', () => {
it('shows the loading spinner during loading', async () => {
const { wrapper } = getWrapper()
wrapper.vm.loadResourcesTask.perform()
await nextTick()
expect(wrapper.find('oc-spinner-stub').exists()).toBeTruthy()
})
it('should render spaces list', async () => {
const { wrapper } = getWrapper()
await wrapper.vm.loadResourcesTask.last
expect(wrapper.html()).toMatchSnapshot()
})
})
describe('sorting', () => {
it('sorts by property name', async () => {
const { wrapper } = getWrapper()
await wrapper.vm.loadResourcesTask.last
let sortedSpaces = []

wrapper.vm.sortBy = 'name'
Expand Down

0 comments on commit 59b580d

Please sign in to comment.