diff options
| author | Pitu <[email protected]> | 2019-04-24 08:36:28 +0000 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-04-24 08:36:28 +0000 |
| commit | 3bd8d119ba88e940932eca50be406d50d73040fb (patch) | |
| tree | 9d24cdfc1edc53cce6670ffabb60597636571ecd /src/site/pages/dashboard/albums | |
| parent | Get rid of the icons altogether in a future commit (diff) | |
| download | host.fuwn.me-3bd8d119ba88e940932eca50be406d50d73040fb.tar.xz host.fuwn.me-3bd8d119ba88e940932eca50be406d50d73040fb.zip | |
Refactor a bit since we globally catch API exceptions
Diffstat (limited to 'src/site/pages/dashboard/albums')
| -rw-r--r-- | src/site/pages/dashboard/albums/_id.vue | 48 | ||||
| -rw-r--r-- | src/site/pages/dashboard/albums/index.vue | 66 |
2 files changed, 43 insertions, 71 deletions
diff --git a/src/site/pages/dashboard/albums/_id.vue b/src/site/pages/dashboard/albums/_id.vue index ed5f8fd..037957c 100644 --- a/src/site/pages/dashboard/albums/_id.vue +++ b/src/site/pages/dashboard/albums/_id.vue @@ -79,9 +79,16 @@ export default { metaInfo() { return { title: 'Album' }; }, - mounted() { - this.getFiles(); - this.getAlbums(); + async asyncData({ $axios, route }) { + try { + const response = await $axios.$get(`album/${route.params.id}/full`); + return { + files: response.files ? response.files : [] + }; + } catch (error) { + console.error(error); + return { files: [] }; + } }, methods: { isAlbumSelected(id) { @@ -90,37 +97,22 @@ export default { return found ? found.id ? true : false : false; }, openAlbumModal(file) { + // Only get the list if the usuer actually wants to change a file's album, otherwise useless call + this.getAlbums(); this.showingModalForFile = file; this.isAlbumsModalActive = true; }, async albumCheckboxClicked(value, id) { - try { - const response = await this.$axios.$post(`file/album/${value ? 'add' : 'del'}`, { - albumId: id, - fileId: this.showingModalForFile.id - }); - this.$toast.open(response.message); - this.getFiles(); - } catch (error) { - this.$onPromiseError(error); - } - }, - async getFiles() { - // TODO: Make this think SSR with AsyncData - try { - const response = await this.$axios.$get(`album/${this.$route.params.id}/full`); - this.files = response.files; - } catch (error) { - console.error(error); - } + const response = await this.$axios.$post(`file/album/${value ? 'add' : 'del'}`, { + albumId: id, + fileId: this.showingModalForFile.id + }); + this.$toast.open(response.message); + this.getFiles(); }, async getAlbums() { - try { - const response = await this.$axios.$get(`albums/dropdown`); - this.albums = response.albums; - } catch (error) { - this.$onPromiseError(error); - } + const response = await this.$axios.$get(`albums/dropdown`); + this.albums = response.albums; } } }; diff --git a/src/site/pages/dashboard/albums/index.vue b/src/site/pages/dashboard/albums/index.vue index c2c054d..079114d 100644 --- a/src/site/pages/dashboard/albums/index.vue +++ b/src/site/pages/dashboard/albums/index.vue @@ -310,13 +310,9 @@ export default { }); }, async deleteAlbum(id, purge) { - try { - const response = await this.$axios.$delete(`album/${id}/${purge ? true : ''}`); - this.getAlbums(); - return this.$toast.open(response.message); - } catch (error) { - return this.$onPromiseError(error); - } + const response = await this.$axios.$delete(`album/${id}/${purge ? true : ''}`); + this.getAlbums(); + return this.$toast.open(response.message); }, promptDeleteAlbumLink(identifier) { this.$dialog.confirm({ @@ -325,29 +321,21 @@ export default { }); }, async deleteAlbumLink(identifier) { - console.log('> deleteAlbumLink', identifier); - try { - const response = await this.$axios.$delete(`album/link/delete/${identifier}`); - return this.$toast.open(response.message); - } catch (error) { - return this.$onPromiseError(error); - } + const response = await this.$axios.$delete(`album/link/delete/${identifier}`); + return this.$toast.open(response.message); }, async linkOptionsChanged(link) { - try { - const response = await this.$axios.$post(`album/link/edit`, - { - identifier: link.identifier, - enableDownload: link.enableDownload, - enabled: link.enabled - }); - this.$toast.open(response.message); - } catch (error) { - this.$onPromiseError(error); - } + const response = await this.$axios.$post(`album/link/edit`, + { + identifier: link.identifier, + enableDownload: link.enableDownload, + enabled: link.enabled + }); + this.$toast.open(response.message); }, async createLink(album) { album.isCreatingLink = true; + // Since we actually want to change the state even if the call fails, use a try catch try { const response = await this.$axios.$post(`album/link/new`, { albumId: album.id }); @@ -360,33 +348,25 @@ export default { expiresAt: null }); } catch (error) { - this.$onPromiseError(error); + // } finally { album.isCreatingLink = false; } }, async createAlbum() { if (!this.newAlbumName || this.newAlbumName === '') return; - try { - const response = await this.$axios.$post(`album/new`, - { name: this.newAlbumName }); - this.newAlbumName = null; - this.$toast.open(response.message); - this.getAlbums(); - } catch (error) { - this.$onPromiseError(error); - } + const response = await this.$axios.$post(`album/new`, + { name: this.newAlbumName }); + this.newAlbumName = null; + this.$toast.open(response.message); + this.getAlbums(); }, async getAlbums() { - try { - const response = await this.$axios.$get(`albums/mini`); - for (const album of response.albums) { - album.isDetailsOpen = false; - } - this.albums = response.albums; - } catch (error) { - this.$onPromiseError(error); + const response = await this.$axios.$get(`albums/mini`); + for (const album of response.albums) { + album.isDetailsOpen = false; } + this.albums = response.albums; } } }; |