-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WiP] Selecting multiple files for deleting on left menu #368
Changes from all commits
044516e
f2c30d7
af2f975
2b23a80
d0cabb9
f0a32f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,22 @@ import InputDialog from '../../Parts/Dialogs/Input' | |
import { useStore } from '../store' | ||
|
||
export default function MoveFolderDialog() { | ||
const path = useStore((state) => state.path) | ||
const paths = useStore((state) => state.paths) | ||
const moveFolder = useStore((state) => state.moveFolder) | ||
const updateState = useStore((state) => state.updateState) | ||
if (!path) return null | ||
if (!paths || paths.length > 1) return null | ||
return ( | ||
<InputDialog | ||
open={true} | ||
value={path} | ||
value={paths[0]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with moving files. This might need to be adjusted for multiSelection |
||
title="Move Folder" | ||
label="Move" | ||
Icon={CopyAllIcon} | ||
placholder="Enter a path" | ||
description={`You are moving "${path}". Enter destination:`} | ||
description={`You are moving "${paths[0]}". Enter destination:`} | ||
onCancel={() => updateState({ dialog: undefined })} | ||
onConfirm={async (toPath) => { | ||
await moveFolder(path, toPath) | ||
await moveFolder(paths[0], toPath) | ||
updateState({ dialog: undefined }) | ||
}} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import * as helpers from '../../helpers' | |
import * as types from '../../types' | ||
|
||
export interface State { | ||
path?: string | ||
paths?: string[] | ||
client: Client | ||
config?: types.IConfig | ||
record?: types.IRecord | ||
|
@@ -46,10 +46,10 @@ export interface State { | |
createFile: (path: string, prompt?: string) => Promise<void> | ||
adjustFile: (name?: string, type?: string) => Promise<void> | ||
copyFile: (path: string, toPath: string) => Promise<void> | ||
deleteFile: (path: string) => Promise<void> | ||
deleteFile: (paths: string[]) => Promise<void> | ||
moveFile: (path: string, toPath: string) => Promise<void> | ||
locateFile: (path: string) => Promise<void> | ||
selectFile: (path?: string) => Promise<void> | ||
selectFile: (paths?: string[]) => Promise<void> | ||
openFile: (path: string) => Promise<void> | ||
closeFile: () => void | ||
|
||
|
@@ -111,7 +111,7 @@ export function makeStore(props: ApplicationProps) { | |
const { loadFiles, selectFile } = get() | ||
await loadFiles() | ||
set({ fileEvent: { type: 'create', paths } }) | ||
if (paths.length === 1) selectFile(paths[0]) | ||
if (paths.length === 1) selectFile(paths) | ||
await delay(500) | ||
set({ fileEvent: undefined }) | ||
}, | ||
|
@@ -126,7 +126,7 @@ export function makeStore(props: ApplicationProps) { | |
onFilePatch: async (path) => { | ||
const { selectFile } = get() | ||
set({ fileEvent: { type: 'update', paths: [path] } }) | ||
selectFile(path) | ||
selectFile([path]) | ||
await delay(500) | ||
set({ fileEvent: undefined }) | ||
}, | ||
|
@@ -194,43 +194,52 @@ export function makeStore(props: ApplicationProps) { | |
} | ||
}, | ||
adjustFile: async (name, type) => { | ||
const { path, client, closeFile, loadFiles, selectFile } = get() | ||
if (!path) return | ||
await client.filePatch({ path, name, type }) | ||
set({ path: undefined }) | ||
const { paths, client, closeFile, loadFiles, selectFile } = get() | ||
// only adjust file if one file is selected from menu | ||
if (!paths || paths.length !== 1) return | ||
await client.filePatch({ path: paths[0], name, type }) | ||
set({ paths: undefined }) | ||
closeFile() | ||
await loadFiles() | ||
await selectFile(path) | ||
await selectFile(paths) | ||
}, | ||
copyFile: async (path, toPath) => { | ||
copyFile: async (paths, toPath) => { | ||
const { client, onFileCreate } = get() | ||
const result = await client.fileCopy({ path, toPath, deduplicate: true }) | ||
onFileCreate([result.path]) | ||
for (const path of paths) { | ||
const result = await client.fileCopy({ path, toPath, deduplicate: true }) | ||
onFileCreate([result.path]) | ||
} | ||
}, | ||
deleteFile: async (path) => { | ||
deleteFile: async (paths) => { | ||
const { client, onFileDelete } = get() | ||
await client.fileDelete({ path }) | ||
onFileDelete(path) | ||
for (const path of paths) { | ||
await client.fileDelete({ path }) | ||
onFileDelete(path) | ||
} | ||
}, | ||
moveFile: async (path, toPath) => { | ||
const { client, onFileCreate } = get() | ||
const result = await client.fileMove({ path, toPath, deduplicate: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how this works. haven't tested it yet |
||
onFileCreate([result.path]) | ||
}, | ||
locateFile: async (path) => { | ||
set({ path }) | ||
set({ paths: [path] }) | ||
set({ fileEvent: { type: 'locate', paths: [path] } }) | ||
await delay(500) | ||
set({ fileEvent: undefined }) | ||
}, | ||
selectFile: async (newPath) => { | ||
const { path, record, openFile } = get() | ||
if (path === newPath) return | ||
set({ path: newPath }) | ||
if (!newPath) return | ||
if (record?.path === newPath) return | ||
selectFile: async (newPaths) => { | ||
const { paths, record, openFile } = get() | ||
if (paths === newPaths) return | ||
set({ paths: newPaths }) | ||
if (!newPaths) return | ||
if (record?.path === newPaths[0]) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what this is doing. using only the first path just in case. Is it for the history? Do we need to modify the record to add all the selected paths? |
||
if (selectors.isFolder(get())) return | ||
await openFile(newPath) | ||
console.log('paths', paths) | ||
console.log('newPaths', newPaths) | ||
// if more than one file is selected, display the only the first one | ||
if (!paths || paths[paths.length - 1] !== newPaths[0]) | ||
await openFile(newPaths[newPaths.length - 1]) | ||
}, | ||
openFile: async (path) => { | ||
const { client, loadFiles, fileEvent } = get() | ||
|
@@ -356,15 +365,14 @@ export function makeStore(props: ApplicationProps) { | |
|
||
export const selectors = { | ||
isFolder: (state: State) => { | ||
return !!state.files.find( | ||
(file) => file.path === state.path && file.type === 'folder' | ||
) | ||
const path = state.paths ? state.paths[0] : null | ||
return !!state.files.find((file) => file.path === path && file.type === 'folder') | ||
}, | ||
folderPath: (state: State) => { | ||
if (!state.path) return undefined | ||
if (!state.paths) return undefined | ||
const isFolder = selectors.isFolder(state) | ||
if (isFolder) return state.path | ||
return helpers.getFolderPath(state.path) | ||
if (isFolder) return state.paths[0] | ||
return helpers.getFolderPath(state.paths[0]) | ||
}, | ||
notIndexedFiles: (state: State) => { | ||
return state.files.filter((file) => !file.name) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how moving file works. This might need to be reworked as well for multiple files