|
54 | 54 | let searchEnabled = false; |
55 | 55 | let fileSelector: HTMLInputElement; |
56 | 56 | let uploading = false; |
| 57 | + let uploadProgress = 0; |
57 | 58 | let view: 'grid' | 'list' = 'list'; |
58 | 59 | $: planMaxSize = |
59 | 60 | isCloud && $currentPlan?.['fileSize'] |
|
97 | 98 | async function uploadFile() { |
98 | 99 | try { |
99 | 100 | uploading = true; |
| 101 | + uploadProgress = 0; |
100 | 102 | let file = null; |
| 103 | +
|
101 | 104 | if (localFileBucketSelected) { |
102 | 105 | file = await sdk.forConsoleIn(page.params.region).storage.createFile({ |
103 | 106 | bucketId: 'default', |
104 | 107 | fileId: ID.unique(), |
105 | | - file: localFile[0] |
| 108 | + file: localFile[0], |
| 109 | + onProgress: (progress) => { |
| 110 | + uploadProgress = progress.progress; |
| 111 | + } |
106 | 112 | }); |
107 | 113 | } else { |
108 | 114 | file = await sdk |
|
111 | 117 | bucketId: selectedBucket, |
112 | 118 | fileId: ID.unique(), |
113 | 119 | file: fileSelector.files[0], |
114 | | - permissions: [Permission.read(Role.any())] |
| 120 | + permissions: [Permission.read(Role.any())], |
| 121 | + onProgress: (progress) => { |
| 122 | + uploadProgress = progress.progress; |
| 123 | + } |
115 | 124 | }); |
116 | 125 | search.set($search === null ? '' : null); |
117 | 126 | } |
|
123 | 132 | }); |
124 | 133 | } finally { |
125 | 134 | uploading = false; |
| 135 | + uploadProgress = 0; |
126 | 136 | } |
127 | 137 | } |
128 | 138 |
|
|
246 | 256 | <svelte:document on:visibilitychange={handleVisibilityChange} /> |
247 | 257 |
|
248 | 258 | <Form {onSubmit} isModal class="file-picker-modal-form"> |
249 | | - <Modal bind:open={show} title="Select file" size="l"> |
| 259 | + <Modal bind:open={show} title="Select file" size="l" dismissible={!uploading}> |
250 | 260 | <Layout.Stack direction={$isSmallViewport ? 'column' : 'row'} height="50vh" gap="none"> |
251 | 261 | <!-- min-width to avoid a layout-shift --> |
252 | 262 | <aside> |
|
428 | 438 | bind:this={fileSelector} /> |
429 | 439 | {#if uploading} |
430 | 440 | <div class="loader is-small"></div> |
431 | | - <span>Uploading</span> |
| 441 | + <span |
| 442 | + >Uploading{uploadProgress > 0 |
| 443 | + ? ` ${uploadProgress}%` |
| 444 | + : ''}</span> |
432 | 445 | {:else} |
433 | 446 | <span class="icon-upload" aria-hidden="true"></span> |
434 | 447 | <span>Upload</span> |
|
711 | 724 | </Layout.Stack> |
712 | 725 | <svelte:fragment slot="footer"> |
713 | 726 | <Layout.Stack direction="row" justifyContent="flex-end"> |
714 | | - <Button text on:click={closeModal}>Cancel</Button> |
| 727 | + <Button text disabled={uploading} on:click={closeModal}>Cancel</Button> |
715 | 728 | <Button |
716 | 729 | submit |
717 | | - disabled={(selectedBucket === null && localFileBucketSelected === false) || |
718 | | - (selectedFile === null && localFile === null)} |
719 | | - >Select |
| 730 | + disabled={uploading || |
| 731 | + (selectedBucket === null && localFileBucketSelected === false) || |
| 732 | + (selectedFile === null && localFile === null)}> |
| 733 | + {#if uploading} |
| 734 | + <div class="loader is-small"></div> |
| 735 | + <span>Uploading{uploadProgress > 0 ? ` ${uploadProgress}%` : ''}</span> |
| 736 | + {:else} |
| 737 | + Select |
| 738 | + {/if} |
720 | 739 | </Button> |
721 | 740 | </Layout.Stack> |
722 | 741 | </svelte:fragment> |
|
0 commit comments