From caafef580c7202ea26af2acb7ae2ca79d8ea3942 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 17 Jan 2021 20:25:19 -0700 Subject: [PATCH] Update ComposeModal, use new routes --- .../assets/js/components/ComposeModal.vue | 168 ++++++++++++++++-- 1 file changed, 153 insertions(+), 15 deletions(-) diff --git a/resources/assets/js/components/ComposeModal.vue b/resources/assets/js/components/ComposeModal.vue index a1f64732d..82499a14f 100644 --- a/resources/assets/js/components/ComposeModal.vue +++ b/resources/assets/js/components/ComposeModal.vue @@ -86,10 +86,46 @@ Next Post + Post
+
+ test +
+
+
+
+
+
+ + +
+

{{composeTextLength}}/{{config.uploader.max_caption_length}}

+

+ + + + + + + + + {{visibilityTag}} + +

+
+
+
+
+
+
@@ -107,6 +143,26 @@
+ +
+
+
+
+ +
+
+

+ New Text Post + + BETA + +

+

Share a text only post

+
+
+
+
+
@@ -349,6 +405,19 @@
+
Turn off commenting
@@ -591,6 +660,8 @@ export default { nsfw: false, place: false, commentsDisabled: false, + optimizeMedia: true, + mediaCropped: false, pageTitle: '', cropper: { @@ -613,11 +684,13 @@ export default { 'addToStory', 'editMedia', 'cameraRoll', - 'tagPeopleHelp' + 'tagPeopleHelp', + 'textOptions' ], cameraRollMedia: [], taggedUsernames: [], - taggedPeopleSearch: null + taggedPeopleSearch: null, + textMode: false } }, @@ -664,6 +737,12 @@ export default { el.removeAttr('disabled'); }, + addText(event) { + this.pageTitle = 'New Text Post'; + this.page = 'addText'; + this.textMode = true; + }, + mediaWatcher() { let self = this; $(document).on('change', '#pf-dz', function(e) { @@ -705,7 +784,7 @@ export default { } }; - axios.post('/api/pixelfed/v1/media', form, xhrConfig) + axios.post('/api/compose/v0/media/upload', form, xhrConfig) .then(function(e) { self.uploadProgress = 100; self.ids.push(e.data.id); @@ -747,7 +826,7 @@ export default { } let id = this.media[this.carouselCursor].id; - axios.delete('/api/pixelfed/v1/media', { + axios.delete('/api/compose/v0/media/delete', { params: { id: id } @@ -794,9 +873,51 @@ export default { cw: this.nsfw, comments_disabled: this.commentsDisabled, place: this.place, - tagged: this.taggedUsernames + tagged: this.taggedUsernames, + optimize_media: this.optimizeMedia }; - axios.post('/api/local/status/compose', data) + axios.post('/api/compose/v0/publish', data) + .then(res => { + let data = res.data; + window.location.href = data; + }).catch(err => { + let msg = err.response.data.message ? err.response.data.message : 'An unexpected error occured.' + swal('Oops, something went wrong!', msg, 'error'); + }); + return; + break; + + case 'delete' : + this.ids = []; + this.media = []; + this.carouselCursor = 0; + this.composeText = ''; + this.composeTextLength = 0; + $('#composeModal').modal('hide'); + return; + break; + } + }, + + composeTextPost() { + let state = this.composeState; + + if(this.composeText.length > this.config.uploader.max_caption_length) { + swal('Error', 'Caption is too long', 'error'); + return; + } + + switch(state) { + case 'publish' : + let data = { + caption: this.composeText, + visibility: this.visibility, + cw: this.nsfw, + comments_disabled: this.commentsDisabled, + place: this.place, + tagged: this.taggedUsernames, + }; + axios.post('/api/compose/v0/publish/text', data) .then(res => { let data = res.data; window.location.href = data; @@ -828,6 +949,14 @@ export default { this.pageTitle = ''; switch(this.page) { + case 'addText': + this.page = 1; + break; + + case 'textOptions': + this.page = 'addText'; + break; + case 'cropPhoto': case 'editMedia': this.page = 2; @@ -838,7 +967,9 @@ export default { break; default: - this.namedPages.indexOf(this.page) != -1 ? this.page = 3 : this.page--; + this.namedPages.indexOf(this.page) != -1 ? + this.page = (this.textMode ? 'addText' : 3) : + (this.textMode ? 'addText' : this.page--); break; } }, @@ -860,10 +991,11 @@ export default { imageSmoothingEnabled: false, imageSmoothingQuality: 'high', }).toBlob(function(blob) { + self.mediaCropped = true; let data = new FormData(); data.append('file', blob); - let url = '/api/local/compose/media/update/' + self.ids[self.carouselCursor]; - + data.append('id', self.ids[self.carouselCursor]); + let url = '/api/compose/v0/media/update'; axios.post(url, data).then(res => { self.media[self.carouselCursor].url = res.data.url; self.pageLoading = false; @@ -921,7 +1053,7 @@ export default { locationSearch(input) { if (input.length < 1) { return []; }; let results = []; - return axios.get('/api/local/compose/location/search', { + return axios.get('/api/compose/v0/search/location', { params: { q: input } @@ -936,8 +1068,8 @@ export default { onSubmitLocation(result) { this.place = result; - this.pageTitle = ''; - this.page = 3; + this.pageTitle = this.textMode ? 'New Text Post' : ''; + this.page = (this.textMode ? 'addText' : 3); return; }, @@ -965,7 +1097,7 @@ export default { this.visibility = state; this.visibilityTag = tags[state]; this.pageTitle = ''; - this.page = 3; + this.page = this.textMode ? 'addText' : 3; }, showMediaDescriptionsCard() { @@ -1024,7 +1156,8 @@ export default { canvas.toBlob(function(blob) { data = new FormData(); data.append('file', blob); - axios.post('/api/local/compose/media/update/'+media.id, data).then(res => { + data.append('id', media.id); + axios.post('/api/compose/v0/media/update', data).then(res => { }).catch(err => { }); }); @@ -1039,7 +1172,7 @@ export default { if (input.length < 1) { return []; }; let self = this; let results = []; - return axios.get('/api/local/compose/tag/search', { + return axios.get('/api/compose/v0/search/tag', { params: { q: input } @@ -1070,6 +1203,11 @@ export default { untagUsername(index) { this.taggedUsernames.splice(index, 1); + }, + + showTextOptions() { + this.page = 'textOptions'; + this.pageTitle = 'Text Post Options'; } } }