Skip to content

Commit 0bc62f4

Browse files
committed
feat: add loader to file uploads
1 parent caf1343 commit 0bc62f4

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/components/cards/FileSystemCard.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { SocketActions } from '@/socketActions'
5151
import DialogFileEditor from '@/components/dialogs/dialogFileEditor.vue'
5252
import UtilsMixin from '@/mixins/utils'
5353
import { KlipperFile } from '@/store/files/types'
54+
import { Waits } from '@/globals'
5455
5556
@Component({
5657
components: {
@@ -140,15 +141,21 @@ export default class FileSystemCard extends Mixins(UtilsMixin) {
140141
filename = `${path}/${filename}`.substring(7)
141142
formData.append('file', file, filename)
142143
formData.append('root', root)
143-
return this.$http.post(
144-
this.apiUrl + '/server/files/upload',
145-
formData,
146-
{
147-
headers: {
148-
'Content-Type': 'multipart/form-data'
144+
this.$store.dispatch('socket/addWait', Waits.onUploadGcode)
145+
console.log('uploading, set wait', Waits.onUploadGcode)
146+
return this.$http
147+
.post(
148+
this.apiUrl + '/server/files/upload',
149+
formData, {
150+
headers: {
151+
'Content-Type': 'multipart/form-data'
152+
}
149153
}
150-
}
151-
)
154+
)
155+
.finally(() => {
156+
console.log('finished uploading, remove wait', Waits.onUploadGcode)
157+
this.$store.dispatch('socket/removeWait', Waits.onUploadGcode)
158+
})
152159
}
153160
154161
saveEdit (content: string, filename: string, path: string) {

src/components/inputs/BtnFileUpload.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
style="display: none"
1111
@change="fileChanged"
1212
>
13-
<v-btn small :color="color" @click="$refs.uploadFile.click()"><v-icon small v-if="icon">{{ icon }}</v-icon>{{ label }}</v-btn>
13+
<v-btn
14+
small
15+
:color="color"
16+
:loading="loading"
17+
@click="$refs.uploadFile.click()">
18+
<v-icon small v-if="icon">{{ icon }}</v-icon>
19+
{{ label }}
20+
</v-btn>
1421
</div>
1522
</template>
1623

@@ -34,6 +41,9 @@ export default class BtnFileUpload extends Vue {
3441
@Prop({ type: String, required: false })
3542
public color!: string
3643
44+
@Prop({ type: Boolean })
45+
public loading!: boolean
46+
3747
fileChanged (e: Event) {
3848
const target = e.target as HTMLInputElement
3949
const files = target.files

src/components/widgets/filesystem/FileSystemBrowser.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
color="secondary"
5555
class="mr-2"
5656
:accept="accept"
57+
:loading="hasWait(waits.onUploadGcode)"
5758
@file-update="uploadFile">
5859
</btn-file-upload>
5960
<v-btn

src/globals.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export const Waits = Object.freeze({
169169
onSetVelocity: 'onSetVelocity',
170170
onSetAcceleration: 'onSetAcceleration',
171171
onSetDeceleration: 'onSetDeceleration',
172-
onSetSCV: 'onSetSCV'
172+
onSetSCV: 'onSetSCV',
173+
onUploadGcode: 'onUploadGcode'
173174
})
174175

175176
export const chartConfiguration: ChartConfiguration = Object.freeze({

0 commit comments

Comments
 (0)