Skip to content

Commit

Permalink
[add] userimageuploaderに画像配信のstatusを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed Dec 28, 2018
1 parent 1e7b036 commit 5cae5f6
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/components/relay/userImageUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@
</v-card-actions>
</v-card>
</v-dialog>

<template v-if="!hideStatus">
<v-snackbar
:value="isSending"
:timeout="3000"
top>
画像をアップロード中
</v-snackbar>

<v-snackbar
@input="toStandby()"
:value="isSuccess"
:timeout="3000"
color="success"
top>
画像のアップロードに成功しました
</v-snackbar>

<v-snackbar
@input="toStandby()"
:value="isError"
:timeout="3000"
color="error"
top>
画像のアップロードに失敗しました
</v-snackbar>
</template>
</el-upload>
</template>

Expand All @@ -52,6 +79,13 @@ import Logger from '@/serviceLocator/Logger'
type RequestType = { file: File }
enum UploadState {
STANDBY,
SENDING,
SUCCESS,
ERROR,
}
@Component({
model: {
event: 'change',
Expand All @@ -60,11 +94,30 @@ type RequestType = { file: File }
})
export default class UserImageUploader extends Vue {
@Prop() public url!: string
@Prop({default: false}) public hideStatus!: boolean
public imageUrl = ''
public isNotAllowFileType = false
public isOverFileSize = false
public uploadState: UploadState = UploadState.STANDBY
get isSending() {
return this.uploadState === UploadState.SENDING
}
get isSuccess() {
return this.uploadState === UploadState.SUCCESS
}
get isError() {
return this.uploadState === UploadState.ERROR
}
public toStandby() {
this.uploadState = UploadState.STANDBY
}
@Watch('url', { immediate: true })
public setUrl() {
this.imageUrl = this.url
Expand All @@ -77,13 +130,16 @@ export default class UserImageUploader extends Vue {
}
try {
this.uploadState = UploadState.SENDING
const filename = uuid()
const imageRef = storage().ref().child(`/users/${user.id}/images/${filename}`)
await imageRef.put(request.file)
this.imageUrl = await imageRef.getDownloadURL()
this.$emit('change', this.imageUrl)
this.uploadState = UploadState.SUCCESS
} catch (e) {
Logger.getInstance().error(e)
this.uploadState = UploadState.ERROR
}
}
Expand Down

0 comments on commit 5cae5f6

Please sign in to comment.