mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: uploader closes and shows uploadboc
This commit is contained in:
1 parent
cc3b94e031
commit
1d426a8587
4 files changed
+44
-40
No files matched your search
@@ -37,6 +37,8 @@
|
||||
<div class="upload-box-content" class:is-open={!$uploader.isCollapsed}>
|
||||
<ul class="upload-box-list">
|
||||
{#each $uploader.files as file}
|
||||
{@const progress = Math.round(file.progress)}
|
||||
|
||||
{#if file.completed || file.progress === 100}
|
||||
<li class="upload-box-item">
|
||||
<div class="u-margin-inline-end-16">
|
||||
@@ -46,7 +48,7 @@
|
||||
name={file.name} />
|
||||
</div>
|
||||
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<label for={file.name} class="file-name u-trim">{file.name}</label>
|
||||
<span class="icon-check" />
|
||||
</li>
|
||||
{:else if file.failed}
|
||||
@@ -55,12 +57,12 @@
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow={file.progress}
|
||||
aria-valuenow={progress}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">{file.progress}%</span>
|
||||
<span class="icon">{progress}%</span>
|
||||
</div>
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<label for={file.name} class="file-name u-trim">{file.name}</label>
|
||||
<Pill danger>Failed</Pill>
|
||||
<button
|
||||
class="icon-button"
|
||||
@@ -69,27 +71,20 @@
|
||||
<span class="icon-x" />
|
||||
</button>
|
||||
</li>
|
||||
{:else if file.cancelled}
|
||||
cancelled?
|
||||
{:else}
|
||||
<li class="upload-box-item">
|
||||
<div class="upload-image u-margin-inline-end-16">
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow={file.progress}
|
||||
style={`--progress-value:${progress}`}
|
||||
aria-valuenow={progress}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100} />
|
||||
<span class="icon">{file.progress}%</span>
|
||||
<span class="icon">{progress}%</span>
|
||||
</div>
|
||||
<label for={file.name} class="file-name">{file.name}</label>
|
||||
<label for={file.name} class="file-name u-trim">{file.name}</label>
|
||||
<Pill warning>Pending</Pill>
|
||||
<button
|
||||
class="icon-button"
|
||||
aria-label="Pending"
|
||||
on:click={() => removeFile(file.$id, file.bucketId)}>
|
||||
<span class="icon-x" />
|
||||
</button>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
+26
-15
@@ -1,5 +1,6 @@
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { sdkForProject } from './sdk';
|
||||
|
||||
type UploaderFile = {
|
||||
$id: string;
|
||||
@@ -8,7 +9,6 @@ type UploaderFile = {
|
||||
progress: number;
|
||||
completed: boolean;
|
||||
failed: boolean;
|
||||
cancelled: boolean;
|
||||
error?: string;
|
||||
};
|
||||
export type Uploader = {
|
||||
@@ -57,22 +57,37 @@ const createUploader = () => {
|
||||
isCollapsed: false,
|
||||
files: []
|
||||
}),
|
||||
addFile: async (file: Models.File, isOpen = true, isCollapsed = false) => {
|
||||
uploadFile: async (bucketId: string, id: string, file: File, permissions: string[]) => {
|
||||
const newFile: UploaderFile = {
|
||||
$id: file.$id,
|
||||
bucketId: file.bucketId,
|
||||
$id: id,
|
||||
bucketId: bucketId,
|
||||
name: file.name,
|
||||
progress: calculateProgress(file),
|
||||
completed: calculateProgress(file) === 100 ? true : false,
|
||||
failed: false,
|
||||
cancelled: false
|
||||
progress: 0,
|
||||
completed: false,
|
||||
failed: false
|
||||
};
|
||||
return update((n) => {
|
||||
n.isOpen = isOpen;
|
||||
n.isCollapsed = isCollapsed;
|
||||
update((n) => {
|
||||
n.isOpen = true;
|
||||
n.isCollapsed = false;
|
||||
n.files.unshift(newFile);
|
||||
return n;
|
||||
});
|
||||
const uploadedFile = await sdkForProject.storage.createFile(
|
||||
bucketId,
|
||||
id ?? 'unique()',
|
||||
file,
|
||||
permissions,
|
||||
(p) => {
|
||||
newFile.$id = p.$id;
|
||||
newFile.progress = p.progress;
|
||||
newFile.completed = p.progress === 100 ? true : false;
|
||||
updateFile(p.$id, newFile);
|
||||
}
|
||||
);
|
||||
newFile.$id = uploadedFile.$id;
|
||||
newFile.progress = 100;
|
||||
newFile.completed = true;
|
||||
updateFile(newFile.$id, newFile);
|
||||
},
|
||||
removeFile: async (file: Models.File) => {
|
||||
if (file.chunksTotal === file.chunksUploaded) {
|
||||
@@ -81,10 +96,6 @@ const createUploader = () => {
|
||||
|
||||
return n;
|
||||
});
|
||||
} else {
|
||||
if (confirm('Are you sure you want to cancel the upload?')) {
|
||||
updateFile(file.$id, { cancelled: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,11 +162,15 @@
|
||||
</button>
|
||||
<svelte:fragment slot="list">
|
||||
<DropListLink
|
||||
on:click={() => {
|
||||
showDropdown[index] = false;
|
||||
}}
|
||||
href={`${base}/console/project-${projectId}/storage/bucket-${bucketId}/file-${file.$id}`}
|
||||
icon="pencil">Update</DropListLink>
|
||||
<DropListItem
|
||||
icon="trash"
|
||||
on:click={() => {
|
||||
showDropdown[index] = false;
|
||||
selectedFile = file;
|
||||
showDelete = true;
|
||||
}}>Delete</DropListItem>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { Button, FormList, InputFile } from '$lib/elements/forms';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Modal, CustomId, Heading, Alert } from '$lib/components';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { uploader } from '$lib/stores/uploader';
|
||||
@@ -25,20 +24,15 @@
|
||||
|
||||
async function create() {
|
||||
try {
|
||||
const file = await sdkForProject.storage.createFile(
|
||||
bucketId,
|
||||
id ?? 'unique()',
|
||||
files[0],
|
||||
permissions
|
||||
);
|
||||
files = null;
|
||||
showCreate = false;
|
||||
await uploader.uploadFile(bucketId, id, files[0], permissions);
|
||||
files = null;
|
||||
showCustomId = false;
|
||||
uploader.addFile(file);
|
||||
// uploader.addFile(file);
|
||||
dispatch('created');
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${file.name} has been created`
|
||||
message: `File has been uploaded`
|
||||
});
|
||||
trackEvent('submit_file_create');
|
||||
} catch ({ message }) {
|
||||
|
||||
Reference in new issue
Block a user