|
139 | 139 | <script> |
140 | 140 | /* eslint-disable prefer-destructuring */ |
141 | 141 | /* eslint-disable prefer-const */ |
| 142 | +/* eslint-disable no-await-in-loop */ |
142 | 143 | import MenuButton from '@/components/app/settings/MenuButton.vue'; |
143 | 144 | import SectionHeader from '@/components/app/settings/SectionHeader.vue'; |
144 | 145 | import AccountInput from '@/components/app/settings/AccountInput.vue'; |
@@ -235,10 +236,21 @@ export default { |
235 | 236 | this.fetchingImages = false; |
236 | 237 | }, |
237 | 238 | async deleteImage(...args) { |
238 | | - const [imageId] = args; |
| 239 | + const [imageId, isPrimary] = args; |
239 | 240 | await this.$http.delete(`/profile/images/${imageId}`, { accessTokenRequired: true }); |
240 | | - const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`, { accessTokenRequired: true }); |
241 | | - await this.$store.dispatch('login', user.data); |
| 241 | + const userImages = this.$store.getters.getLoggedInUser.images; |
| 242 | + if (userImages.length > 1 && isPrimary) { |
| 243 | + const len = userImages.length; |
| 244 | + for (let i = 0; i < len; i += 1) { |
| 245 | + if (userImages[i].id !== imageId) { |
| 246 | + await this.makePrimaryImage([userImages[i].id]); |
| 247 | + return; |
| 248 | + } |
| 249 | + } |
| 250 | + } else { |
| 251 | + const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`, { accessTokenRequired: true }); |
| 252 | + await this.$store.dispatch('login', user.data); |
| 253 | + } |
242 | 254 | }, |
243 | 255 | async makePrimaryImage(...args) { |
244 | 256 | const [imageId] = args; |
|
0 commit comments