-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Uploads jpeg file to folder on backend.
Still needs to associated image with entity (org, in this case). Still needs to add / display uploaded images in entitys UI.
- Loading branch information
1 parent
57e8c5d
commit a33bb53
Showing
10 changed files
with
101 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 23 additions & 70 deletions
93
frontend/components/modal/upload-images/ModalUploadImagesFileDropZone.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,30 @@ | ||
<!-- SPDX-License-Identifier: AGPL-3.0-or-later --> | ||
<template> | ||
<button | ||
@drop.prevent="onDrop" | ||
@dragenter.prevent="activate" | ||
@dragover.prevent="activate" | ||
@dragleave.prevent="deactivate" | ||
class="card-style-base flex w-full rounded-lg" | ||
:class="{ | ||
'bg-highlight': isActive, | ||
'bg-layer-1': !isActive, | ||
}" | ||
<div | ||
class="flex h-32 w-full cursor-pointer items-center justify-center rounded-md border-2 border-dashed border-primary-text bg-layer-0 p-4 text-center text-primary-text" | ||
@dragenter.prevent="isDropZoneActive = true" | ||
@dragleave.prevent="isDropZoneActive = false" | ||
@dragover.prevent="isDropZoneActive = true" | ||
@drop.prevent=" | ||
isDropZoneActive = false; | ||
$emit('files-dropped', ($event.dataTransfer as DataTransfer)?.files); | ||
" | ||
@click="$refs.file.click()" | ||
> | ||
<label | ||
for="file-input" | ||
class="flex h-80 w-full cursor-pointer items-center justify-center" | ||
> | ||
<slot :isDropZoneActive="isActive"></slot> | ||
<input | ||
@change="onInputChange" | ||
id="file-input" | ||
class="hidden" | ||
type="file" | ||
multiple | ||
/> | ||
</label> | ||
</button> | ||
<input | ||
ref="file" | ||
type="file" | ||
class="hidden" | ||
accept="image/jpeg,image/png" | ||
@change=" | ||
$emit('files-dropped', ($event.target as HTMLInputElement)?.files) | ||
" | ||
multiple | ||
/> | ||
<slot :isDropZoneActive="isDropZoneActive" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const emit = defineEmits(["files-dropped"]); | ||
|
||
const isActive = ref(false); | ||
|
||
let deactivateTimeoutKey: number | null = null; | ||
|
||
const activate = () => { | ||
isActive.value = true; | ||
if (deactivateTimeoutKey) clearTimeout(deactivateTimeoutKey); | ||
}; | ||
|
||
const deactivate = () => { | ||
isActive.value = false; | ||
deactivateTimeoutKey = window.setTimeout(() => { | ||
isActive.value = false; | ||
}, 50); | ||
}; | ||
|
||
function onDrop(e: DragEvent) { | ||
if (!e.dataTransfer) return; | ||
emit("files-dropped", [...e.dataTransfer.files]); | ||
} | ||
|
||
function onInputChange(e: Event) { | ||
const target = e.target as HTMLInputElement; | ||
if (!target.files) return; | ||
emit("files-dropped", [...target.files]); | ||
} | ||
|
||
function preventDefaults(e: Event) { | ||
e.preventDefault(); | ||
} | ||
|
||
const events = ["dragenter", "dragover", "dragleave", "drop"]; | ||
|
||
onMounted(() => { | ||
events.forEach((eventName) => { | ||
document.body.addEventListener(eventName, preventDefaults); | ||
}); | ||
}); | ||
|
||
onUnmounted(() => { | ||
events.forEach((eventName) => { | ||
document.body.removeEventListener(eventName, preventDefaults); | ||
}); | ||
}); | ||
const isDropZoneActive = ref(false); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters