From e5cdc80b6497c19b07785054d94e636f31a5b5be Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 24 Feb 2018 07:22:13 -0800 Subject: [PATCH] add progress bar for file uploads resolves #53 --- src/pages/stream/stream.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index f9b73e4..a379ca1 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -361,6 +361,7 @@ export class StreamPage { + @@ -380,6 +381,7 @@ export class NewPostModal { title: string; replyid: string; ptext: string = ""; + showProgress: boolean = false; files: Array = []; fname: string = ""; fpath: string = ""; @@ -491,7 +493,7 @@ export class NewPostModal { } attachImage() { - console.log('file chooser'); + // console.log('file chooser'); const fileTransfer: FileTransferObject = this.transfer.create(); this.fileChooser.open().then(uri => { @@ -499,9 +501,6 @@ export class NewPostModal { this.filePath.resolveNativePath(uri).then(filePath => { this.fpath = filePath; this.fname = filePath.split('/').pop(); - console.log('-filepath-'); - console.log(this.fpath); - console.log(this.fname); let options: FileUploadOptions = { fileKey: 'content', @@ -514,10 +513,9 @@ export class NewPostModal { headers: {'Authorization': 'Bearer ' + this.authToken} } + this.showProgress = true; fileTransfer.upload(this.fpath, 'https://api.pnut.io/v0/files', options).then((response) => { - console.log('-file created-'); - console.log(response.response); - console.log('-file created-'); + let rdata = JSON.parse(response.response); let oembed = { '+io.pnut.core.file': { @@ -526,7 +524,7 @@ export class NewPostModal { format: 'oembed' } } - console.log(JSON.stringify(oembed)); + // console.log(JSON.stringify(oembed)); this.raw.push({ type: "io.pnut.core.oembed", value: oembed @@ -536,10 +534,10 @@ export class NewPostModal { link: rdata.data.link, id: this.raw.length - 1 }); + this.showProgress = false; }).catch((err) => { - console.log('-create file error-'); - console.log(JSON.stringify(err)); - console.log('-create file error-'); + + this.showProgress = false; let edata = JSON.parse(err.body); this.presentToast(edata.meta.error_message); });