Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Vue, ajax post comments #20
Browse files Browse the repository at this point in the history
  • Loading branch information
marky291 committed May 22, 2019
1 parent 346d7bb commit 8b4d024
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 267 deletions.
501 changes: 242 additions & 259 deletions .idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions app/ReviewComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

class ReviewComment extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['message'];

/**
* Comment belongs to a review.
*/
Expand Down
25 changes: 22 additions & 3 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15753,19 +15753,28 @@ __webpack_require__.r(__webpack_exports__);
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var moment__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! moment */ "./node_modules/moment/moment.js");
/* harmony import */ var moment__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(moment__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var vform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! vform */ "./node_modules/vform/dist/vform.common.js");
/* harmony import */ var vform__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(vform__WEBPACK_IMPORTED_MODULE_1__);


/* harmony default export */ __webpack_exports__["default"] = ({
props: ['review'],
components: {
'has-error': vform__WEBPACK_IMPORTED_MODULE_1__["HasError"],
'alert-error': vform__WEBPACK_IMPORTED_MODULE_1__["AlertError"]
},
data: function data() {
return {
starCount: 0,
viewingDetails: false,
commenting: false,
commentMessage: ''
comment: new vform__WEBPACK_IMPORTED_MODULE_1__["Form"]({
message: ''
})
};
},
computed: {
reportButtonText: function reportButtonText() {
commentButtonText: function commentButtonText() {
return this.viewingDetails ? 'Close comment' : 'Comment as server owner';
},
detailButtonText: function detailButtonText() {
Expand All @@ -15789,7 +15798,17 @@ __webpack_require__.r(__webpack_exports__);
return moment__WEBPACK_IMPORTED_MODULE_0___default()(this.review.created_at).startOf('day').fromNow();
},
postComment: function postComment() {
this.commenting = true;
var _this = this;

this.comment.post('/review/' + this.review.id + '/comment').then(function (response) {
_this.$Message.success('Great! We have notified this user of your comment');

_this.review.comments.push(response.data.comment);

_this.commenting = false;
})["catch"](function (error) {
_this.$Message.error(error.message);
});
},
reportReview: function reportReview() {}
}
Expand Down
2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=ad69a06e7802cb0d111f",
"/js/app.js": "/js/app.js?id=9767b81328e97feae7af",
"/css/app.css": "/css/app.css?id=2ca1c713699a279f42c3"
}
20 changes: 17 additions & 3 deletions resources/js/components/ReviewComponent.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<script>
import moment from 'moment';
import { Form, HasError, AlertError } from 'vform';
export default {
props: ['review'],
components: {
'has-error': HasError,
'alert-error': AlertError,
},
data() {
return {
starCount: 0,
viewingDetails: false,
commenting: false,
commentMessage: '',
comment: new Form({
message: '',
})
}
},
computed: {
reportButtonText: function() {
commentButtonText: function() {
return this.viewingDetails ? 'Close comment' : 'Comment as server owner';
},
detailButtonText: function() {
Expand All @@ -36,7 +44,13 @@
return moment(this.review.created_at).startOf('day').fromNow();
},
postComment() {
this.commenting = true;
this.comment.post('/review/'+this.review.id+'/comment').then(response => {
this.$Message.success('Great! We have notified this user of your comment');
this.review.comments.push(response.data.comment);
this.commenting = false;
}).catch(error => {
this.$Message.error(error.message);
})
},
reportReview() {
Expand Down
3 changes: 2 additions & 1 deletion resources/views/listing/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
</div>
<div v-show="commenting" class="tw-mt-3">
<p class="tw-text-red tw-font-semibold">Comment on this review as server owner</p>
<at-textarea v-model="commentMessage" min-rows="5" class="tw-mt-2" autosize placeholder="Write your reply towards this review"></at-textarea>
<at-textarea v-model="comment.message" min-rows="5" class="tw-mt-2" autosize placeholder="Write your reply towards this review"></at-textarea>
<has-error :form="comment" field="message"></has-error>
<at-button @click="postComment" type="error" class="tw-mt-2">Post Comment</at-button>
</div>
<div class="tw-flex tw-justify-end">
Expand Down
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// authentication routes (login & logout)
Auth::routes(['verify' => true]);

Route::resource('review.comment', 'ReviewCommentController', ['middleware'=>['auth']])->only([
'store'
]);

// default index page.
Route::get('/')->uses('ListingController@index')->name('index');

Expand Down

0 comments on commit 8b4d024

Please sign in to comment.