Skip to content
5 changes: 5 additions & 0 deletions .changeset/free-donkeys-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@svenvw/fdm-app": minor
---

Fixes that user can drop files as well for Mijn Percelen shapefile upload and Soil Analysis pdf upload.
5 changes: 5 additions & 0 deletions .changeset/new-hornets-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@svenvw/fdm-app": minor
---

The users can now drop files onto the entire shapefile upload area during farm creation, not just on top of the text and icons.
115 changes: 59 additions & 56 deletions fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ export function MijnPercelenUploadForm({
)

form.setValue("shapefile", updatedFiles, { shouldValidate: true })

const fileInput = document.getElementById(
"file-upload",
) as HTMLInputElement | null
if (fileInput) {
const container = new DataTransfer()
updatedFiles.forEach((f) => {
container.items.add(f)
})
fileInput.files = container.files
}
await handleFilesSet(updatedFiles)
e.dataTransfer.clearData()
}
Expand Down Expand Up @@ -361,13 +372,56 @@ export function MijnPercelenUploadForm({
name,
onBlur,
onChange,
disabled,
ref,
},
}) => (
<FormItem>
<div>Shapefile</div>
<div className="relative">
<Input
name={name}
onBlur={onBlur}
onChange={async (
event,
) => {
await handleFileChange(
event,
onChange,
)
}}
ref={ref}
type="file"
placeholder=""
className="hidden"
multiple
required
id="file-upload"
/>
<label
// biome-ignore lint/a11y/noNoninteractiveTabindex: The label is interactive and should be focusable
tabIndex={0}
className="relative block"
htmlFor="file-upload"
aria-label="Upload shapefile files by clicking or dragging and dropping"
onKeyDown={(e) => {
if (
e.key ===
"Enter" ||
e.key ===
" "
) {
e.preventDefault()
document
.getElementById(
"file-upload",
)
?.click()
}
}}
onDragOver={
handleDragOver
}
onDrop={handleDrop}
>
{fileNames.length >
0 && (
<Button
Expand Down Expand Up @@ -403,58 +457,7 @@ export function MijnPercelenUploadForm({
"border-green-500 bg-green-50",
)}
>
<Input
name={name}
onBlur={
onBlur
}
onChange={async (
event,
) => {
await handleFileChange(
event,
onChange,
)
}}
ref={ref}
type="file"
placeholder=""
className="hidden"
multiple
required
disabled={
disabled
}
id="file-upload"
/>
<label
htmlFor="file-upload"
className="flex flex-col items-center justify-center w-full h-full cursor-pointer"
aria-label="Upload shapefile files by clicking or dragging and dropping"
onKeyDown={(
e,
) => {
if (
e.key ===
"Enter" ||
e.key ===
" "
) {
e.preventDefault()
document
.getElementById(
"file-upload",
)
?.click()
}
}}
onDragOver={
handleDragOver
}
onDrop={
handleDrop
}
>
<div className="flex flex-col items-center justify-center w-full h-full cursor-pointer">
{uploadState ===
"idle" && (
<>
Expand Down Expand Up @@ -509,9 +512,9 @@ export function MijnPercelenUploadForm({
</div>
</>
)}
</label>
</div>
</div>
</div>
</label>
<FormDescription />
<FormMessage />
</FormItem>
Expand Down
Loading