From 6ea5c7e4426a665acaad8a24e32ca52b50bae6ac Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Wed, 26 Aug 2020 14:28:58 -0300 Subject: [PATCH] upload event and list on Feed --- src/components/cpmEventForm.vue | 94 +++++++++++++++-------------- src/main.js | 10 --- src/store/index.js | 5 +- src/store/modules/FeedVuex.js | 38 ++++++++++++ src/store/modules/getActionsVuex.js | 50 --------------- src/store/modules/postActionVuex.js | 44 -------------- src/util/uploadImage.js | 13 ++++ src/views/private/Feed.vue | 31 ++++++++-- 8 files changed, 131 insertions(+), 154 deletions(-) create mode 100644 src/store/modules/FeedVuex.js delete mode 100644 src/store/modules/getActionsVuex.js delete mode 100644 src/store/modules/postActionVuex.js create mode 100644 src/util/uploadImage.js diff --git a/src/components/cpmEventForm.vue b/src/components/cpmEventForm.vue index bbc3f11..c915dda 100644 --- a/src/components/cpmEventForm.vue +++ b/src/components/cpmEventForm.vue @@ -103,7 +103,7 @@ > ({ @@ -179,6 +179,7 @@ export default { selectedFile:'', url:process.env.VUE_APP_BASE_URL, + uploadUrl:process.env.VUE_APP_UPLOAD_URL, active:0, @@ -195,7 +196,7 @@ export default { latitude:'', longitude:'', address:'', - eventeDate:'', + eventDate:'', img:'', user:'1' }, @@ -239,6 +240,10 @@ export default { photo:'', }), + created(){ + this.eventForm.private = false + }, + methods: { ...mapActions({ createEvent: 'createEvent' @@ -282,26 +287,19 @@ export default { this.imageUrl = fileReader.result }) fileReader.readAsDataURL(files[0]) - this.uploadPhoto() }, uploadPhoto(){ - - uploadImageToFirebase(this.imageData) - // const storageImage = firebase.storage().ref(`${this.imageData.name}`).put(this.imageData) - // storageImage.on(`state_changed`, snapshot => { - // this.uploadedValue = (snapshot.bytesTransferred/snapshot.totalBytes)*100 - // console.log(this.uploadedValue) - // }, - // error => {console.log(error.message)}, - // ()=> {this.uploadedValue=100; - // storageImage.snapshot.ref.getDownloadURL().then((url) => { - // this.photo = url - // console.log("MANO... DEU TUDO CERTO, SÓ VAI") - // console.log(url) - // this.eventForm.img = url - // }) - // }) + + const fd = new FormData(); + console.log(this.imageData) + fd.append('photo', this.imageData) + + this.$http.post(this.uploadUrl + '/upload/image', fd) + .then(resp => { + console.log(resp) + this.eventForm.img = resp.data + }) }, onFileChange(event) { @@ -321,33 +319,41 @@ export default { this.eventForm.longitude = param.longitude }, - createEvent(){ - + async createEvent(){ + + try{ + const fd = new FormData(); + console.log(this.imageData) + fd.append('photo', this.imageData); + await axios.post(this.uploadUrl + '/upload/image', fd).then(resp => { + this.eventForm.img = resp.data + }) + + + let body = { + title:this.eventForm.name, + description:this.eventForm.description, + address:this.eventForm.address, + img:this.eventForm.img, + privated:this.eventForm.private, + eventDate:this.eventForm.eventDate, + latitude:this.eventForm.latitude, + longitude:this.eventForm.longitude, + user:{user: this.eventForm.user}, + } - - const fd = new FormData(); - fd.append('title', this.eventForm.name); - fd.append('description', this.eventForm.description); - fd.append('adress', this.eventForm.address); - fd.append('img', this.eventForm.img); - fd.append('privated', this.eventForm.private); - fd.append('eventeDate', this.eventForm.eventeDate); - fd.append('latitude', this.eventForm.latitude); - fd.append('longitude', this.eventForm.longitude); - fd.append('user', this.eventForm.user); - - console.log(this.eventForm) - console.log(fd); - - - let body = fd console.log(body) - // this.createEvent(body) - this.$http.post(this.url + '/event', fd) - .then(resp => { - console.log(resp) - }) + axios.post(this.url + '/event/create', body) + .then(resp => { + console.log(resp) + }) + + } + + catch(e){ + throw e + } } diff --git a/src/main.js b/src/main.js index 38a7f66..4682163 100644 --- a/src/main.js +++ b/src/main.js @@ -12,16 +12,6 @@ import firebase from 'firebase' Vue.use(VueIziToast, defaultOptionsObject); -firebase.initializeApp({ - apiKey: "AIzaSyClLsWBLQWwjE0xTiyMCVQZWoGCCu8Q3Gc", - authDomain: "eventyy-007.firebaseapp.com", - databaseURL: "https://eventyy-007.firebaseio.com", - projectId: "eventyy-007", - storageBucket: "eventyy-007.appspot.com", - messagingSenderId: "644960387013", - appId: "1:644960387013:web:0651bdf4a4efa5af6c55ac", - measurementId: "G-05D1TRXJLR" -}) import 'leaflet/dist/leaflet.css'; diff --git a/src/store/index.js b/src/store/index.js index 3dccd3f..df77c62 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,6 +1,6 @@ import Vue from 'vue' import Vuex from 'vuex' -import postActionVuex from './modules/postActionVuex' +import FeedVuex from './modules/FeedVuex' import RegisterVuex from './modules/RegisterVuex' import LoginVuex from './modules/LoginVuex' import ProfileVuex from './modules/ProfileVuex' @@ -8,6 +8,7 @@ import ProfileVuex from './modules/ProfileVuex' Vue.use(Vuex) export default new Vuex.Store({ + state: { coordinateSelected:'', uploadedFile:'', @@ -27,8 +28,8 @@ export default new Vuex.Store({ actions: { }, modules: { - postActionVuex, RegisterVuex, + FeedVuex, LoginVuex, ProfileVuex } diff --git a/src/store/modules/FeedVuex.js b/src/store/modules/FeedVuex.js new file mode 100644 index 0000000..36bfc5a --- /dev/null +++ b/src/store/modules/FeedVuex.js @@ -0,0 +1,38 @@ +import axios from '../../util/axios' + + +export default { + + namespaced: true, + + state: { + cardsEventData:'' + }, + + getters: { + + cardsEventData: state => state.cardsEventData + + }, + + mutations: { + setFeedEventsData(state, newSate){ + state.cardsEventData = newSate + }, + + }, + + actions: { + async getEvents(context){ + + await axios.get(process.env.VUE_APP_BASE_URL+'/event/list') + .then(resp => { + console.log(resp) + context.commit('setFeedEventsData',resp.data) + return resp.data; + }) + + }, + + } +} diff --git a/src/store/modules/getActionsVuex.js b/src/store/modules/getActionsVuex.js deleted file mode 100644 index 760e2ad..0000000 --- a/src/store/modules/getActionsVuex.js +++ /dev/null @@ -1,50 +0,0 @@ -import axios from '../../util/axios' - -export default { - - namespaced: true, - - state: { - - - - }, - - getters: { - - - }, - - mutations: { - - }, - - actions: { - - async listPublicEvents(context, newData) { - - console.log(newData) - let privated = newData - - await axios.get(process.env.VUE_APP_BASE_URL + `/event/${privated}`) - .then(resp => { - console.log(resp) - }) - - - }, - - async listAllEvents(context, newData) { - - console.log(newData) - - await axios.get(process.env.VUE_APP_BASE_URL + '/event/list') - .then(resp => { - console.log(resp) - }) - - - }, - - } -} diff --git a/src/store/modules/postActionVuex.js b/src/store/modules/postActionVuex.js deleted file mode 100644 index c5fe92a..0000000 --- a/src/store/modules/postActionVuex.js +++ /dev/null @@ -1,44 +0,0 @@ -import axios from '../../util/axios' -import uploadCloudinary from '../../util/cloudinary' - -export default { - - namespaced: true, - - state: { - - }, - - getters: { - - - }, - - mutations: { - - }, - - actions: { - - async createEvent (context, newData) { - - const cloudinary = await uploadCloudinary(newData.avatar) - - newData.avatar = cloudinary.data.secure_url - - const user = await axios.post(process.env.VUE_APP_BASE_URL + '/event', newData) - - .then(resp => { - console.log(resp) - }) - - .catch((err) => { - console.log(err) - alert("Erro ao criar evento") - }) - - return user - - }, - } -} diff --git a/src/util/uploadImage.js b/src/util/uploadImage.js new file mode 100644 index 0000000..a7eeaad --- /dev/null +++ b/src/util/uploadImage.js @@ -0,0 +1,13 @@ +import axios from 'axios'; +// import { mapActions } from 'vuex' + +export default async function uploadUrl(file){ + const fd = new FormData(); + fd.append('photo', file); + + await axios.post(process.env.VUE_APP_UPLOAD_URL + '/upload/image', fd) + .then(resp => { + console.log("UPLOAD FEITO") + return resp.data + }) +} \ No newline at end of file diff --git a/src/views/private/Feed.vue b/src/views/private/Feed.vue index 94bd0b3..8646862 100644 --- a/src/views/private/Feed.vue +++ b/src/views/private/Feed.vue @@ -3,14 +3,14 @@

Feed

- + -
+
- +
-

{{ item.date }}

+

{{ item.eventDate }}

{{ item.title }}

Criado por {{ item.user }}
@@ -21,6 +21,9 @@ \ No newline at end of file