Permalink
Browse files

Episode 83

  • Loading branch information...
JeffreyWay committed Oct 4, 2017
1 parent d7a612e commit 558f664d8152181cc0a0c3026470e33b0c6841ca
@@ -1,7 +1,7 @@
let user = window.App.user;
module.exports = {
updateReply (reply) {
return reply.user_id === user.id;
owns (model, prop = 'user_id') {
return model[prop] === user.id;
}
};
@@ -1,7 +1,7 @@
<template>
<div>
<div v-for="(reply, index) in items" :key="reply.id">
<reply :data="reply" @deleted="remove(index)"></reply>
<reply :reply="reply" @deleted="remove(index)"></reply>
</div>
<paginator :dataSet="dataSet" @changed="fetch"></paginator>
@@ -3,13 +3,13 @@
<div class="panel-heading">
<div class="level">
<h5 class="flex">
<a :href="'/profiles/'+data.owner.name"
v-text="data.owner.name">
<a :href="'/profiles/' + reply.owner.name"
v-text="reply.owner.name">
</a> said <span v-text="ago"></span>
</h5>
<div v-if="signedIn">
<favorite :reply="data"></favorite>
<favorite :reply="reply"></favorite>
</div>
</div>
</div>
@@ -29,13 +29,13 @@
<div v-else v-html="body"></div>
</div>
<div class="panel-footer level">
<div v-if="authorize('updateReply', reply)">
<div class="panel-footer level" v-if="authorize('owns', reply) || authorize('owns', reply.thread)">
<div v-if="authorize('owns', reply)">
<button class="btn btn-xs mr-1" @click="editing = true">Edit</button>
<button class="btn btn-xs btn-danger mr-1" @click="destroy">Delete</button>
</div>
<button class="btn btn-xs btn-default ml-a" @click="markBestReply" v-show="! isBest">Best Reply?</button>
<button class="btn btn-xs btn-default ml-a" @click="markBestReply" v-if="authorize('owns', reply.thread)">Best Reply?</button>
</div>
</div>
</template>
@@ -45,23 +45,22 @@
import moment from 'moment';
export default {
props: ['data'],
props: ['reply'],
components: { Favorite },
data() {
return {
editing: false,
id: this.data.id,
body: this.data.body,
isBest: this.data.isBest,
reply: this.data
id: this.id,
body: this.reply.body,
isBest: this.reply.isBest,
};
},
computed: {
ago() {
return moment(this.data.created_at).fromNow() + '...';
return moment(this.reply.created_at).fromNow() + '...';
}
},
@@ -74,7 +73,7 @@
methods: {
update() {
axios.patch(
'/replies/' + this.data.id, {
'/replies/' + this.id, {
body: this.body
})
.catch(error => {
@@ -87,15 +86,15 @@
},
destroy() {
axios.delete('/replies/' + this.data.id);
axios.delete('/replies/' + this.id);
this.$emit('deleted', this.data.id);
this.$emit('deleted', this.id);
},
markBestReply() {
axios.post('/replies/' + this.data.id + '/best');
axios.post('/replies/' + this.id + '/best');
window.events.$emit('best-reply-selected', this.data.id);
window.events.$emit('best-reply-selected', this.id);
}
}
}

0 comments on commit 558f664

Please sign in to comment.