1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
"use client"
import React, { useState, useEffect } from "react"
import { Search, Folder, Move } from "lucide-react"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
import { toast } from "@/hooks/use-toast"
import { DriveLsEntry } from "@/lib/drive_types"
interface DriveMoveDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
selectedCount: number
onMove: (destinationPath: string) => void
}
export function DriveMoveDialog({ open, onOpenChange, selectedCount, onMove }: DriveMoveDialogProps) {
const [directories, setDirectories] = useState<DriveLsEntry[]>([])
const [filteredDirectories, setFilteredDirectories] = useState<DriveLsEntry[]>([])
const [searchQuery, setSearchQuery] = useState("")
const [selectedDirectory, setSelectedDirectory] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
// Load all directories when dialog opens
useEffect(() => {
if (open) {
loadDirectories()
}
}, [open])
// Filter directories based on search query
useEffect(() => {
if (!searchQuery.trim()) {
setFilteredDirectories(directories)
} else {
const query = searchQuery.toLowerCase()
const filtered = directories.filter(dir =>
dir.path.toLowerCase().includes(query)
)
setFilteredDirectories(filtered)
}
}, [searchQuery, directories])
const loadDirectories = async () => {
setLoading(true)
try {
const response = await fetch('/api/directories')
if (!response.ok) {
throw new Error(`Failed to fetch directories: ${response.statusText}`)
}
const dirs = await response.json()
setDirectories(dirs)
setFilteredDirectories(dirs)
} catch (error) {
console.error('Error loading directories:', error)
toast({
title: "Failed to load directories",
description: error instanceof Error ? error.message : 'Unknown error occurred',
variant: "destructive"
})
} finally {
setLoading(false)
}
}
const handleMove = () => {
if (selectedDirectory) {
onMove(selectedDirectory)
// Reset dialog state
setSelectedDirectory(null)
setSearchQuery("")
}
}
const handleClose = () => {
onOpenChange(false)
// Reset dialog state
setSelectedDirectory(null)
setSearchQuery("")
}
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="max-w-md max-h-[80vh]">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Move className="h-5 w-5" />
Move {selectedCount} item{selectedCount !== 1 ? "s" : ""}
</DialogTitle>
</DialogHeader>
<div className="space-y-4">
{/* Search Input */}
<div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search directories..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10"
/>
</div>
{/* Directory List */}
<ScrollArea className="h-[300px] border rounded-md">
<div className="p-2">
{loading ? (
<div className="flex items-center justify-center py-8">
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900"></div>
</div>
) : filteredDirectories.length === 0 ? (
<div className="text-center py-8 text-muted-foreground">
{searchQuery ? 'No directories found matching your search' : 'No directories available'}
</div>
) : (
<div className="space-y-1">
{filteredDirectories.map((directory) => (
<div
key={directory.path}
className={`flex items-center gap-2 p-2 rounded cursor-pointer transition-colors ${
selectedDirectory === directory.path
? 'bg-blue-50 border border-blue-200'
: 'hover:bg-muted/50'
}`}
onClick={() => setSelectedDirectory(directory.path)}
>
<Folder className="h-4 w-4 text-blue-500 flex-shrink-0" />
<span className="text-sm font-mono break-all">
{directory.path}
</span>
</div>
))}
</div>
)}
</div>
</ScrollArea>
{/* Selected Directory Display */}
{selectedDirectory && (
<div className="bg-blue-50 border border-blue-200 rounded-lg p-3">
<div className="text-sm font-medium text-blue-900 mb-1">
Moving to:
</div>
<div className="text-sm font-mono text-blue-700">
{selectedDirectory}
</div>
</div>
)}
{/* Action Buttons */}
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={handleClose}>
Cancel
</Button>
<Button
onClick={handleMove}
disabled={!selectedDirectory || loading}
>
<Move className="mr-2 h-4 w-4" />
Move Here
</Button>
</div>
</div>
</DialogContent>
</Dialog>
)
}
|