Skip to content

Commit 3650c0f

Browse files
committed
FileHirerarchy solved bug when drop on file
1 parent d4eb82d commit 3650c0f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

client/src/main/scala/org/scastie/client/components/fileHierarchy/FileHierarchy.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object FileHierarchy {
2222
*/
2323
private case class FileHierarchyState(selectedFile: String, dragOver: String)
2424

25-
private val initialFhs = FileHierarchyState(selectedFile = "/root", dragOver = "")
25+
private val initialFhs = FileHierarchyState(selectedFile = "", dragOver = "")
2626

2727
private val component = ScalaFnComponent.withHooks[(Folder, File => Callback, (FileOrFolder, String) => Callback)]
2828
.useState(initialFhs)
@@ -40,9 +40,13 @@ object FileHierarchy {
4040
if (dragInfo.end) {
4141
val src = dragInfo.fileOrFolder
4242
val dstPath = fhs.value.dragOver
43-
44-
moveFileOrFolder(src, dstPath) >>
45-
fhs.setState(FileHierarchyState(selectedFile = dstPath + "/" + src.name, dragOver = ""))
43+
if (dstPath.isEmpty) {
44+
/* do nothing if the user never dragged over a folder and just dropped the fileOrFolder on a file */
45+
Callback.empty
46+
} else {
47+
moveFileOrFolder(src, dstPath) >>
48+
fhs.setState(FileHierarchyState(selectedFile = dstPath + "/" + src.name, dragOver = ""))
49+
}
4650
} else {
4751
fhs.modState(_.copy(dragOver = dragInfo.fileOrFolder.path))
4852
}

0 commit comments

Comments
 (0)