Skip to content

Commit

Permalink
Added Toaster notification message for file(s) fail to be dropped in …
Browse files Browse the repository at this point in the history
…drop-zone
  • Loading branch information
hujambo-dunia committed Nov 8, 2023
1 parent 9ef91e0 commit 1f2c8b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/src/components/Upload/DragAndDropModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { useFileDrop } from "composables/fileDrop";
import { useGlobalUploadModal } from "composables/globalUploadModal";
import { computed, ref } from "vue";
import { Toast } from "@/composables/toast";
const modalContentElement = ref(null);
const { isFileOverDocument, isFileOverDropZone } = useFileDrop(modalContentElement, onDrop, true);
const { isFileOverDocument, isFileOverDropZone } = useFileDrop(modalContentElement, onDrop, onDropFail, true);
const modalClass = computed(() => {
if (isFileOverDropZone.value) {
Expand All @@ -26,6 +28,12 @@ function onDrop(event) {
});
}
}
function onDropFail(event) {
if (event.dataTransfer?.files?.length > 0) {
Toast.error("Please try again", "File failed");
}
}
</script>
<template>
Expand Down
5 changes: 5 additions & 0 deletions client/src/composables/fileDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export type FileDropHandler = (event: DragEvent) => void;
* Custom File-Drop composable
* @param dropZone Element which files should be dropped on
* @param onDrop callback function called when drop occurs
* @param onDropFail callback function called when drop fails (missed zone)
* @param solo when true, only reacts if no modal is open
* @param idleTime how long to wait until state resets
*/
export function useFileDrop(
dropZone: MaybeRefOrGetter<EventTarget | null | undefined>,
onDrop: Ref<FileDropHandler> | FileDropHandler,
onDropFail: Ref<FileDropHandler> | FileDropHandler,
solo: MaybeRefOrGetter<boolean>,
idleTime = 800
) {
Expand Down Expand Up @@ -72,6 +74,9 @@ export function useFileDrop(
if (isFileOverDropZone.value) {
const dropHandler = unref(onDrop);
dropHandler(event as DragEvent);
} else {
const dropFailHandler = unref(onDropFail);
dropFailHandler(event as DragEvent);
}
return "idle";
case "dragend":
Expand Down

0 comments on commit 1f2c8b5

Please sign in to comment.