Reset ISAC icon uploads after additions
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
required = false,
|
||||
currentUrl = '',
|
||||
emptyLabel = 'NO IMAGE',
|
||||
browseLabel = 'CHOOSE FILE'
|
||||
browseLabel = 'CHOOSE FILE',
|
||||
resetToken = 0
|
||||
}: {
|
||||
name: string;
|
||||
accept: string;
|
||||
@@ -15,16 +16,38 @@
|
||||
currentUrl?: string | null;
|
||||
emptyLabel?: string;
|
||||
browseLabel?: string;
|
||||
resetToken?: string | number;
|
||||
} = $props();
|
||||
|
||||
let input: HTMLInputElement;
|
||||
let input: HTMLInputElement | undefined;
|
||||
let previewUrl = $state('');
|
||||
let fileName = $state('');
|
||||
let dragging = $state(false);
|
||||
let error = $state('');
|
||||
let handledResetToken: string | number | null = null;
|
||||
|
||||
function resetUpload() {
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
previewUrl = '';
|
||||
fileName = '';
|
||||
dragging = false;
|
||||
error = '';
|
||||
if (input) input.value = '';
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (handledResetToken === null) {
|
||||
handledResetToken = resetToken;
|
||||
return;
|
||||
}
|
||||
if (resetToken !== handledResetToken) {
|
||||
handledResetToken = resetToken;
|
||||
resetUpload();
|
||||
}
|
||||
});
|
||||
|
||||
function setFile(file: File | undefined) {
|
||||
if (!file) return;
|
||||
if (!file || !input) return;
|
||||
if (!file.type.startsWith('image/')) {
|
||||
error = 'Clipboard or dropped content must be an image.';
|
||||
return;
|
||||
@@ -108,7 +131,7 @@
|
||||
<span>{fileName || 'OR USE AN UPLOAD METHOD'}</span>
|
||||
</div>
|
||||
<div class="image-upload-actions">
|
||||
<button type="button" class="secondary" onclick={(event) => { event.stopPropagation(); input.click(); }}>{browseLabel}</button>
|
||||
<button type="button" class="secondary" onclick={(event) => { event.stopPropagation(); input?.click(); }}>{browseLabel}</button>
|
||||
<button type="button" class="secondary" onclick={(event) => { event.stopPropagation(); pasteFromClipboard(); }}>PASTE IMAGE</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user