Skip to content

Commit

Permalink
fix: name conflict generation
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 31, 2023
1 parent 884cbda commit 13c2057
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
21 changes: 15 additions & 6 deletions lib/components/ConflictPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@
</template>

<script lang="ts">
import type { ConflictResolutionResult } from '../index.ts'
import { basename, extname } from 'path'
import { Node } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import Vue from 'vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import Vue from 'vue'
import ArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import Close from 'vue-material-design-icons/Close.vue'
import { n, t } from '../utils/l10n.ts'
import logger from '../utils/logger.ts'
import NodesPicker from './NodesPicker.vue'
import { basename, extname } from 'path'
export default Vue.extend({
name: 'ConflictPicker',
Expand All @@ -105,11 +107,18 @@ export default Vue.extend({
default: '',
},
/** All the existing files in the current directory */
content: {
type: Array as () => Node[],
required: true,
},
/** Existing files to be replaced */
conflicts: {
type: Array as () => Node[],
required: true,
},
/** New files being moved/uploaded */
files: {
type: Array as () => (Node|File)[],
Expand Down Expand Up @@ -222,7 +231,7 @@ export default Vue.extend({
this.$emit('submit', {
selected: [],
renamed: [],
})
} as ConflictResolutionResult)
},
onSubmit() {
Expand All @@ -237,7 +246,7 @@ export default Vue.extend({
}
const selectedOldNames = this.oldSelected.map((node: Node) => node.basename) as string[]
const directoryContent = this.conflicts.map((node: Node) => node.basename) as string[]
const directoryContent = this.content.map((node: Node) => node.basename) as string[]
// Files that got selected twice (new and old) gets renamed
const renamed = [] as (File|Node)[]
Expand Down Expand Up @@ -273,7 +282,7 @@ export default Vue.extend({
this.$emit('submit', {
selected,
renamed,
})
} as ConflictResolutionResult)
},
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default Vue.extend({
try {
// Let the user choose what to do with the conflicting files
const { selected, renamed } = await openConflictPicker(this.destination.dirname, compareFiles, conflicts)
const { selected, renamed } = await openConflictPicker(this.destination.dirname, compareFiles, conflicts, this.content)
files = [...uploads, ...selected, ...renamed]
} catch (error) {
// User cancelled
Expand Down
10 changes: 6 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export { Upload, Status as UploadStatus } from './upload'
let _uploader: Uploader | null = null

export type ConflictResolutionResult = {
selected: File[],
renamed: File[],
selected: (File|Node)[],
renamed: (File|Node)[],
}
/**
* Get an Uploader instance
Expand Down Expand Up @@ -46,17 +46,19 @@ export function upload(destinationPath: string, file: File): Uploader {
* Open the conflict resolver
* @param {string} dirname the directory name
* @param {(File|Node)[]} files the incoming files
* @param {Node[]} conflicts the existing files
* @param {Node[]} conflicts the conflicting files that already exists in the directory
* @param {Node[]} content all the existing files in the directory
* @return {Promise<ConflictResolutionResult>} the selected and renamed files
*/
export async function openConflictPicker(dirname: string, files: (File|Node)[], conflicts: Node[]): Promise<ConflictResolutionResult> {
export async function openConflictPicker(dirname: string, files: (File|Node)[], conflicts: Node[], content: Node[]): Promise<ConflictResolutionResult> {
const { default: ConflictPicker } = await import('./components/ConflictPicker.vue')
return new Promise((resolve, reject) => {
const picker = new ConflictPicker({
propsData: {
dirname,
files,
conflicts,
content,
},
})

Expand Down

0 comments on commit 13c2057

Please sign in to comment.