Permalink
Browse files

Episode 92

  • Loading branch information...
JeffreyWay committed Oct 31, 2017
1 parent e7f5318 commit 7c73869d3355a51b7aa509b72ae27f7215dc4db7
@@ -6,9 +6,14 @@
class UserAvatarController extends Controller
{
/**
* Store a new user avatar.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$this->validate(request(), [
request()->validate([
'avatar' => ['required', 'image']
]);
@@ -56,7 +56,7 @@ public function update(Reply $reply)
{
$this->authorize('update', $reply);
$this->validate(request(), ['body' => 'required|spamfree']);
request()->validate(['body' => 'required|spamfree']);
$reply->update(request(['body']));
}
@@ -7,7 +7,6 @@
use App\Rules\Recaptcha;
use App\Thread;
use App\Trending;
use Illuminate\Http\Request;
class ThreadsController extends Controller
{
@@ -54,13 +53,12 @@ public function create()
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Rules\Recaptcha $recaptcha
* @param \App\Rules\Recaptcha $recaptcha
* @return \Illuminate\Http\Response
*/
public function store(Request $request, Recaptcha $recaptcha)
public function store(Recaptcha $recaptcha)
{
$this->validate($request, [
request()->validate([
'title' => 'required|spamfree',
'body' => 'required|spamfree',
'channel_id' => 'required|exists:channels,id',
@@ -58125,16 +58125,46 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
data: function data() {
return {
repliesCount: this.thread.replies_count,
locked: this.thread.locked
locked: this.thread.locked,
title: this.thread.title,
body: this.thread.body,
form: {},
editing: false
};
},
created: function created() {
this.resetForm();
},
methods: {
toggleLock: function toggleLock() {
axios[this.locked ? 'delete' : 'post']('/locked-threads/' + this.thread.slug);
var uri = '/locked-thread/' + this.thread.slug;
axios[this.locked ? 'delete' : 'post'](uri);
this.locked = !this.locked;
},
update: function update() {
var _this = this;
var uri = '/threads/' + this.thread.channel.slug + '/' + this.thread.slug;
axios.patch(uri, this.form).then(function () {
_this.editing = false;
_this.title = _this.form.title;
_this.body = _this.form.body;
flash('Your thread has been updated.');
});
},
resetForm: function resetForm() {
this.form = {
title: this.thread.title,
body: this.thread.body
};
this.editing = false;
}
}
});
@@ -58375,7 +58405,7 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
data: function data() {
return {
editing: false,
id: this.id,
id: this.reply.id,
body: this.reply.body,
isBest: this.reply.isBest
};
@@ -52,7 +52,7 @@
data() {
return {
editing: false,
id: this.id,
id: this.reply.id,
body: this.reply.body,
isBest: this.reply.isBest,
};
@@ -10,17 +10,46 @@
data () {
return {
repliesCount: this.thread.replies_count,
locked: this.thread.locked
locked: this.thread.locked,
title: this.thread.title,
body: this.thread.body,
form: {},
editing: false
};
},
created () {
this.resetForm();
},
methods: {
toggleLock () {
axios[
this.locked ? 'delete' : 'post'
]('/locked-threads/' + this.thread.slug);
let uri = `/locked-thread/${this.thread.slug}`;
axios[this.locked ? 'delete' : 'post'](uri);
this.locked = ! this.locked;
},
update () {
let uri = `/threads/${this.thread.channel.slug}/${this.thread.slug}`;
axios.patch(uri, this.form).then(() => {
this.editing = false;
this.title = this.form.title;
this.body = this.form.body;
flash('Your thread has been updated.');
})
},
resetForm () {
this.form = {
title: this.thread.title,
body: this.thread.body
};
this.editing = false;
}
}
}
@@ -25,6 +25,7 @@
<style>
body { padding-bottom: 100px; }
.level { display: flex; align-items: center; }
.level-item { margin-right: 1em; }
.flex { flex: 1; }
.mr-1 { margin-right: 1em; }
.ml-a { margin-left: auto; }
@@ -0,0 +1,56 @@
{{-- Editing the question. --}}
<div class="panel panel-default" v-if="editing">
<div class="panel-heading">
<div class="level">
<input type="text" class="form-control" v-model="form.title">
</div>
</div>
<div class="panel-body">
<div class="form-group">
<textarea class="form-control" rows="10" v-model="form.body"></textarea>
</div>
</div>
<div class="panel-footer">
<div class="level">
<button class="btn btn-xs level-item" @click="editing = true" v-show="! editing">Edit</button>
<button class="btn btn-primary btn-xs level-item" @click="update">Update</button>
<button class="btn btn-xs level-item" @click="resetForm">Cancel</button>
@can ('update', $thread)
<form action="{{ $thread->path() }}" method="POST" class="ml-a">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-link">Delete Thread</button>
</form>
@endcan
</div>
</div>
</div>
{{-- Viewing the question. --}}
<div class="panel panel-default" v-else>
<div class="panel-heading">
<div class="level">
<img src="{{ $thread->creator->avatar_path }}"
alt="{{ $thread->creator->name }}"
width="25"
height="25"
class="mr-1">
<span class="flex">
<a href="{{ route('profile', $thread->creator) }}">{{ $thread->creator->name }}</a> posted: <span v-text="title"></span>
</span>
</div>
</div>
<div class="panel-body" v-text="body"></div>
<div class="panel-footer" v-if="authorize('owns', thread)">
<button class="btn btn-xs" @click="editing = true">Edit</button>
</div>
</div>
@@ -8,36 +8,8 @@
<thread-view :thread="{{ $thread }}" inline-template>
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<div class="level">
<img src="{{ $thread->creator->avatar_path }}"
alt="{{ $thread->creator->name }}"
width="25"
height="25"
class="mr-1">
<span class="flex">
<a href="{{ route('profile', $thread->creator) }}">{{ $thread->creator->name }}</a> posted:
{{ $thread->title }}
</span>
@can ('update', $thread)
<form action="{{ $thread->path() }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-link">Delete Thread</button>
</form>
@endcan
</div>
</div>
<div class="panel-body">
{{ $thread->body }}
</div>
</div>
<div class="col-md-8" v-cloak>
@include ('threads._question')
<replies @added="repliesCount++" @removed="repliesCount--"></replies>
</div>

0 comments on commit 7c73869

Please sign in to comment.