Skip to content

Commit 30dbd93

Browse files
committed
(UI) show spinner if image not loaded
1 parent 1494bca commit 30dbd93

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/ChatWindow/ChatMessage.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,28 @@ export default {
112112
data() {
113113
return {
114114
openMessageId: {},
115-
hoverMessageId: null
115+
hoverMessageId: null,
116+
imageLoading: false
117+
}
118+
},
119+
120+
watch: {
121+
message: {
122+
immediate: true,
123+
handler() {
124+
this.checkImgLoad()
125+
}
116126
}
117127
},
118128
119129
computed: {
120130
isImage() {
121-
if (!this.message.file) return
122-
const imageTypes = ['png', 'jpg']
123-
const { type } = this.message.file
124-
return imageTypes.some(t => type.includes(t))
131+
return this.checkImageFile()
125132
},
126133
isImageLoading() {
127-
return this.message.file.url.indexOf('blob:http') !== -1
134+
return (
135+
this.message.file.url.indexOf('blob:http') !== -1 || this.imageLoading
136+
)
128137
},
129138
isEditable() {
130139
return this.canEditMessage()
@@ -174,6 +183,19 @@ export default {
174183
},
175184
openFile({ url }) {
176185
window.open(url, '_blank')
186+
},
187+
checkImageFile() {
188+
if (!this.message.file) return
189+
const imageTypes = ['png', 'jpg']
190+
const { type } = this.message.file
191+
return imageTypes.some(t => type.includes(t))
192+
},
193+
checkImgLoad() {
194+
if (!this.checkImageFile()) return
195+
this.imageLoading = true
196+
const image = new Image()
197+
image.src = this.message.file.url
198+
image.addEventListener('load', () => (this.imageLoading = false))
177199
}
178200
}
179201
}
@@ -282,7 +304,7 @@ export default {
282304
}
283305
284306
.image-loading {
285-
filter: blur(5px);
307+
filter: blur(3px);
286308
}
287309
288310
@keyframes slide-up {

0 commit comments

Comments
 (0)