Skip to content

Commit

Permalink
fix: Always request current content when triggering a menu entry
Browse files Browse the repository at this point in the history
We need to make sure we work with an up-to-date version of the current content,
e.g. if a file was removed or added, so reload the current content on click.

The using app (esp. files) should have cached version so no requests are needed.
(for files this is already the case).

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Aug 1, 2024
1 parent d50a722 commit 4d7f9cb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 223 deletions.
27 changes: 15 additions & 12 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand All @@ -74,7 +74,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand All @@ -91,7 +91,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand Down Expand Up @@ -233,7 +233,6 @@ export default Vue.extend({
eta: null,
timeLeft: '',
currentContent: [] as Node[],
newFileMenuEntries: [] as Entry[],
uploadManager: getUploader(),
}
Expand Down Expand Up @@ -307,13 +306,6 @@ export default Vue.extend({
},
},
content: {
immediate: true,
async handler() {
this.currentContent = await this.getContent()
},
},
destination(destination) {
this.setDestination(destination)
},
Expand Down Expand Up @@ -350,6 +342,17 @@ export default Vue.extend({
},
methods: {
/**
* Handle clicking a new-menu entry
* @param entry The entry that was clicked
*/
async onClick(entry: Entry) {
entry.handler(
this.destination!,
await this.getContent().catch(() => []),
)
},
/**
* Trigger file picker
* @param uploadFolders Upload folders
Expand Down Expand Up @@ -408,7 +411,7 @@ export default Vue.extend({
async handleConflicts(nodes: Array<File|Directory>, path: string): Promise<Array<File|Directory>|false> {
try {
const content = path === '' ? this.currentContent : await this.getContent(path).catch(() => [])
const content = await this.getContent(path).catch(() => [])
const conflicts = getConflicts(nodes, content)
// First handle conflicts as this might already remove invalid files
Expand Down
Loading

0 comments on commit 4d7f9cb

Please sign in to comment.