Skip to content

Commit 33e6095

Browse files
committed
Fix minor bugs
1 parent f1bcd1c commit 33e6095

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

src/components/comments/AddComment.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<template>
22
<v-card class="transparent" flat>
33
<v-list-item three-line class="pl-0">
4-
<v-list-item-avatar size="50"
5-
><v-img :src="avatar"></v-img
6-
></v-list-item-avatar>
4+
<v-list-item-avatar size="50">
5+
<v-avatar v-if="!isAuthenticated" color="primary">
6+
<v-icon class="white--text">mdi-account</v-icon>
7+
</v-avatar>
8+
<v-img
9+
v-else-if="currentUser.photoUrl !== 'no-photo.jpg'"
10+
:src="`${getUrl}/uploads/avatars/${currentUser.photoUrl}`"
11+
></v-img>
12+
13+
<v-avatar v-else color="red">
14+
<span class="white--text headline ">
15+
{{ currentUser.channelName.split('')[0].toUpperCase() }}</span
16+
>
17+
</v-avatar>
18+
</v-list-item-avatar>
719
<v-list-item-content class="align-self-auto">
820
<v-text-field
921
v-model="comment"
1022
placeholder="Add a public comment..."
11-
@click="showCommentBtns = true"
23+
@click="clickTextField"
1224
>
1325
</v-text-field>
1426
<div v-if="showCommentBtns" class="d-inline-block text-right">
@@ -29,6 +41,7 @@
2941
</template>
3042

3143
<script>
44+
import { mapGetters } from 'vuex'
3245
import CommentService from '@/services/CommentService'
3346
export default {
3447
props: {
@@ -41,10 +54,12 @@ export default {
4154
return {
4255
showCommentBtns: false,
4356
loading: false,
44-
comment: '',
45-
avatar: `${process.env.VUE_APP_URL}/uploads/avatars/${this.$store.getters.currentUser.photoUrl}`
57+
comment: ''
4658
}
4759
},
60+
computed: {
61+
...mapGetters(['currentUser', 'getUrl', 'isAuthenticated'])
62+
},
4863
methods: {
4964
async createComment() {
5065
if (this.comment === '') return
@@ -68,6 +83,10 @@ export default {
6883
6984
this.$store.dispatch('addComment', comment.data.data)
7085
this.$emit('videoCommentLength')
86+
},
87+
clickTextField() {
88+
if (!this.isAuthenticated) return this.$router.push('/signin')
89+
this.showCommentBtns = true
7190
}
7291
}
7392
}

src/components/comments/CommentList.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</v-btn>
2929
</template>
3030

31-
<v-list>
31+
<v-list v-if="isAuthenticated">
3232
<v-list-item @click="deleteComment(comment._id)">
3333
<v-list-item-title
3434
><v-icon>mdi-trash</v-icon>Delete</v-list-item-title
@@ -55,10 +55,15 @@
5555
<v-list-item three-line class="pl-0">
5656
<v-list-item-avatar
5757
v-if="typeof comment.userId !== 'undefined'"
58-
class="mt-0"
58+
class="mt-2"
5959
size="40"
60-
><v-img
61-
:src="`${url}/uploads/avatars/${comment.userId.photoUrl}`"
60+
>
61+
<v-avatar v-if="!isAuthenticated" color="primary">
62+
<v-icon class="white--text">mdi-account</v-icon>
63+
</v-avatar>
64+
<v-img
65+
v-else
66+
:src="`${url}/uploads/avatars/${currentUser.photoUrl}`"
6267
></v-img
6368
></v-list-item-avatar>
6469
<v-list-item-content class="align-self-auto mt-0 pt-0">
@@ -67,13 +72,15 @@
6772
:ref="`${'input' + comment._id}`"
6873
class="pt-0 mt-0 body-2"
6974
placeholder="Add a public comment..."
75+
@click="clickTextField"
7076
:value="repliesInput[`input${comment._id}`]"
7177
>
7278
</v-text-field>
7379
</v-form>
7480
<div
7581
:ref="comment._id + 'btns'"
7682
class="d-inline-block text-right"
83+
v-if="isAuthenticated"
7784
>
7885
<v-btn text @click="hideReply(comment._id)" small
7986
>Cancel</v-btn
@@ -131,7 +138,7 @@
131138
{{ dateFormatter(reply.createdAt) }}</span
132139
>
133140
</v-list-item-title>
134-
<v-menu bottom left>
141+
<v-menu bottom left v-if="isAuthenticated">
135142
<template v-slot:activator="{ on }">
136143
<v-btn icon v-on="on">
137144
<v-icon>mdi-dots-vertical</v-icon>
@@ -175,6 +182,8 @@
175182

176183
<script>
177184
import moment from 'moment'
185+
import { mapGetters } from 'vuex'
186+
178187
import CommentService from '@/services/CommentService'
179188
import ReplyService from '@/services/ReplyService'
180189
export default {
@@ -195,6 +204,9 @@ export default {
195204
loading: false
196205
}
197206
},
207+
computed: {
208+
...mapGetters(['isAuthenticated', 'currentUser'])
209+
},
198210
methods: {
199211
async getComments() {
200212
this.loading = true
@@ -210,6 +222,7 @@ export default {
210222
// console.log(this.$store.getters.getComments.data)
211223
},
212224
async deleteComment(id) {
225+
if (!this.isAuthenticated) return
213226
// this.$store.dispatch('deleteComment', id)
214227
this.comments = this.comments.filter(
215228
(comment) => comment._id.toString() !== id.toString()
@@ -227,6 +240,7 @@ export default {
227240
this.$emit('videoCommentLength')
228241
},
229242
async addReply(event, id) {
243+
if (!this.isAuthenticated) return
230244
if (this.$refs[`input${id}`][0].$refs.input.value == '') return
231245
232246
this.btnLoading = true
@@ -273,6 +287,9 @@ export default {
273287
// .find((comment) => comment._id === id)
274288
// .replies.unshift(reply.data.data)
275289
},
290+
clickTextField() {
291+
if (!this.isAuthenticated) return this.$router.push('/signin')
292+
},
276293
showReply(id) {
277294
this.$refs[id][0].classList.toggle('d-none')
278295
},

0 commit comments

Comments
 (0)