Skip to content

Commit

Permalink
upload event and list on Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Lopes committed Aug 26, 2020
1 parent b42dff4 commit 6ea5c7e
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 154 deletions.
94 changes: 50 additions & 44 deletions src/components/cpmEventForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
></v-text-field>

<v-text-field
v-model="eventForm.eventeDate"
v-model="eventForm.eventDate"
label="Data do evento"
:rules="dateRules"
:error="false"
Expand Down Expand Up @@ -168,7 +168,7 @@ import {
export default {
components:{
SetMap
SetMap
},
data:() => ({
Expand All @@ -179,6 +179,7 @@ export default {
selectedFile:'',
url:process.env.VUE_APP_BASE_URL,
uploadUrl:process.env.VUE_APP_UPLOAD_URL,
active:0,
Expand All @@ -195,7 +196,7 @@ export default {
latitude:'',
longitude:'',
address:'',
eventeDate:'',
eventDate:'',
img:'',
user:'1'
},
Expand Down Expand Up @@ -239,6 +240,10 @@ export default {
photo:'',
}),
created(){
this.eventForm.private = false
},
methods: {
...mapActions({
createEvent: 'createEvent'
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 3 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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'

Vue.use(Vuex)

export default new Vuex.Store({

state: {
coordinateSelected:'',
uploadedFile:'',
Expand All @@ -27,8 +28,8 @@ export default new Vuex.Store({
actions: {
},
modules: {
postActionVuex,
RegisterVuex,
FeedVuex,
LoginVuex,
ProfileVuex
}
Expand Down
38 changes: 38 additions & 0 deletions src/store/modules/FeedVuex.js
Original file line number Diff line number Diff line change
@@ -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;
})

},

}
}
50 changes: 0 additions & 50 deletions src/store/modules/getActionsVuex.js

This file was deleted.

44 changes: 0 additions & 44 deletions src/store/modules/postActionVuex.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/util/uploadImage.js
Original file line number Diff line number Diff line change
@@ -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
})
}
31 changes: 27 additions & 4 deletions src/views/private/Feed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<ToolBar/>
<h1 class="alg-txt-c">Feed</h1>

<Card />
<!-- <Card /> -->

<div class="p15 mt-10" v-for="(item, i) in itens" :key="i">
<div class="p15 mt-10" v-for="(item, i) in cardsEventData" :key="i">
<v-card max-width="500" class="ac card-style-1">
<img :src='item.imageEvent' class="img-size">
<img :src='item.img' class="img-size">

<div class="p10 alg-txt-s">
<h4 class="clr-red">{{ item.date }}</h4>
<h4 class="clr-red">{{ item.eventDate }}</h4>
<h1 class="mt-1">{{ item.title }}</h1>
<span class="mt-2 display-b">Criado por <strong>{{ item.user }}</strong> </span>
</div>
Expand All @@ -21,6 +21,9 @@
<script>
import ToolBar from '@/components/cpmToolBar'
import Card from '@/components/cpmCard'
import {
mapActions, mapGetters
} from 'vuex'
export default {
data:() => ({
Expand All @@ -39,6 +42,26 @@ export default {
components:{
ToolBar,
Card
},
computed: {
...mapGetters({
cardsEventData: 'FeedVuex/cardsEventData',
}),
},
created(){
this.getEvents()
},
methods:{
...mapActions({
getEvents: 'FeedVuex/getEvents'
}),
}
}
</script>

0 comments on commit 6ea5c7e

Please sign in to comment.