Skip to content

Commit

Permalink
Fix issue with dragging same folder multiple times not keeping folder…
Browse files Browse the repository at this point in the history
… contents.
  • Loading branch information
We-Gold committed Aug 9, 2024
1 parent 06a33b7 commit 8742c04
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/renderer/src/contexts/DirectoryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ function DirectoryProvider({ children }: { children: React.ReactNode }): JSX.Ele
const [directoryPath, setDirectoryPath] = useState<string | null>(null)
const [nodes, setNodes] = useState<NodeChildren>({})

const setDirectory = useCallback((directory: string): void => {
if (!directory || directory.length === 0) return
const setDirectory = useCallback(
(directory: string): void => {
// Make sure the directory is not empty
if (!directory || directory.length === 0) return

setDirectoryPath(directory)
// Make sure the directory is not the same as the current directory
if (directory === directoryPath) return

// Clean up the directory name
const directorySplit = directory.split(/[/\\]/)
setDirectoryName(directorySplit[directorySplit.length - 1])
setDirectoryPath(directory)

// Clear the folder contents
setNodes({})
}, [])
// Clean up the directory name
const directorySplit = directory.split(/[/\\]/)
setDirectoryName(directorySplit[directorySplit.length - 1])

// Clear the folder contents
setNodes({})
},
[directoryPath]
)

useEffect(() => {
const clearSelectedFolderListener = window.electron.ipcRenderer.on(
Expand Down

0 comments on commit 8742c04

Please sign in to comment.