-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.vue
108 lines (101 loc) · 2.54 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
<div id="app">
<div class="app-phone">
<div class="phone-header">
<img src="https://i.imgur.com/iuyXEIv.png" />
<a class="cancel-cta" v-if="step === 2 || step === 3" @click="goToHome">
Cancel
</a>
<a class="next-cta" v-if="step === 2" @click="step++;"> Next </a>
<a class="next-cta" v-if="step === 3" @click="sharePost"> Share Me </a>
</div>
<phone-body
:step="step"
:posts="posts"
:filters="filters"
:image="image"
:selectedFilter="selectedFilter"
v-model="caption"
/>
<div class="phone-footer">
<div class="home-cta" @click="goToHome">
<i class="fas fa-home fa-lg"></i>
</div>
<div class="upload-cta">
<input
type="file"
name="file"
id="file"
class="inputfile"
@change="uploadImage"
:disabled="step !== 1"
/>
<label for="file"> <i class="far fa-plus-square fa-lg"></i> </label>
</div>
</div>
</div>
</div>
</template>
<script>
import PhoneBody from "./components/PhoneBody";
import posts from "./data/posts";
import filters from "./data/filters";
import EventBus from "./event-bus.js";
export default {
name: "App",
data() {
return {
step: 1,
posts,
filters,
image: "",
selectedFilter: "",
caption: ""
};
},
created() {
EventBus.$on("filter-selected", evt => {
this.selectedFilter = evt.filter;
});
},
methods: {
uploadImage(evt) {
const files = evt.target.files;
if (!files.length) return;
const reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onload = evt => {
this.image = evt.target.result;
this.step = 2;
};
// To enable reuploading of same files in Chrome
document.querySelector("#file").value = "";
},
sharePost() {
const post = {
username: "LikeMe_Official",
userImage:
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/1211695/vue_lg_bg.png",
postImage: this.image,
likes: 0,
caption: this.caption,
filter: this.filterType
};
this.posts.unshift(post);
this.goToHome();
},
goToHome() {
this.image = "";
this.selectedFilter = "";
this.caption = "";
this.step = 1;
}
},
components: {
"phone-body": PhoneBody
}
};
</script>
<style lang="scss" src="./styles/app.scss">
// Styles from stylesheet
</style>