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 5c9eca3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/components/ConflictPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import Vue from 'vue'
import ArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import Close from 'vue-material-design-icons/Close.vue'
import type { ConflictResolutionResult } from '../index.ts'
import { n, t } from '../utils/l10n.ts'
import logger from '../utils/logger.ts'
import NodesPicker from './NodesPicker.vue'
Expand All @@ -105,11 +106,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 +230,7 @@ export default Vue.extend({
this.$emit('submit', {
selected: [],
renamed: [],
})
} as ConflictResolutionResult)
},
onSubmit() {
Expand Down Expand Up @@ -250,7 +258,7 @@ export default Vue.extend({
if (toRename.length > 0) {
toRename.forEach(file => {
const name = (file instanceof File) ? file.name : file.basename
const newName = this.getUniqueName(name, directoryContent)
const newName = this.getUniqueName(name, this.content)
if (file instanceof File) {
file = new File([file], newName, { type: file.type, lastModified: file.lastModified })
renamed.push(file)
Expand All @@ -273,7 +281,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, 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 5c9eca3

Please sign in to comment.