-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJourney.vue
96 lines (89 loc) · 2.16 KB
/
Journey.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
<template>
<div>
<h2>{{ title }}</h2>
<div class="center">
<base-button buttonColor="pink" @click="redirectToGroup()">More explanations</base-button>
</div>
<h4 class="white-text center" v-if="isLoading">Clicking the doodle to replay it as an animation.</h4>
<p class="white-text center" v-if="doodle.length == 0">Fetching chat log...</p>
<!-- Chatlog -->
<div class="messages-wrapper" style="width: 45%; margin: auto;">
<message-history v-if="messages.length != 0" :messages="messages"/>
</div>
<p class="white-text center" v-if="doodle.length == 0">Fetching doodle...</p>
<!-- Doodle -->
<doodle :allStrokes="doodle"/>
</div>
</template>
<script>
import db from '@/firebase/init.js'
import Doodle from '@/components/reusables/Doodle.vue'
import MessageHistory from '@/components/reusables/MessageHistory.vue'
import { mapState } from 'vuex'
export default {
components: {
Doodle,
MessageHistory
},
computed: {
...mapState({
user: state => state.user.user,
hasFetchedUser: state => state.user.hasFetchedUser
})
},
data() {
return {
title: '',
doodle: [],
messages: [],
forGroup: '',
hasFetchedConversation: false,
isLoading: true
}
},
watch: {
hasFetchedUser: {
handler: 'fetchConversation',
immediate: true
}
},
methods: {
redirectToGroup() {
if (this.forGroup) {
this.$router.push(`/chat/${this.forGroup}`)
}
},
async fetchConversation() {
if (this.hasFetchedConversation || !this.hasFetchedUser) {
return
}
// get document from firestore
const id = this.$route.params.convo_id
const ref = db.collection('conversations').doc(id)
const doc = await ref.get()
if (doc.exists) {
const data = doc.data()
this.doodle = data.doodle
this.messages = data.messages
this.title = data.title
this.hasFetchedConversation = true
this.forGroup = data.forGroup
this.isLoading = false
}
}
}
}
</script>
<style lang="scss" scoped>
h2 {
@extend .center;
}
.flexbox-container {
display: flex;
justify-content: space-around;
}
.doodle-wrapper,
.doodle-wrapper {
height: 600px;
}
</style>