Skip to content

Commit a08a650

Browse files
committed
Add last updated information to forum posts
1 parent c42c64f commit a08a650

File tree

9 files changed

+157
-22
lines changed

9 files changed

+157
-22
lines changed

app/Http/Controllers/HomeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function index(Request $request): \Illuminate\Contracts\View\Factory|\Ill
9393
'latest_posts:by-group:'.auth()->user()->group_id,
9494
$expiresAt,
9595
fn () => Post::query()
96-
->with('user', 'user.group', 'topic:id,name')
96+
->with('user', 'user.group', 'topic:id,name', 'updatedBy.group')
9797
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
9898
->withSum('tips', 'bon')
9999
->withExists([

app/Http/Controllers/PostController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ public function update(Request $request, int $id): \Illuminate\Http\RedirectResp
207207
abort_unless($post->topic()->authorized(canReplyTopic: true)->exists(), 403);
208208

209209
$post->update([
210-
'content' => $request->input('content'),
210+
'content' => $request->input('content'),
211+
'updated_by' => $user->id,
211212
]);
212213

213214
return redirect()->to($postUrl)

app/Http/Controllers/User/PostController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminat
2929
return view('user.post.index', [
3030
'user' => $user,
3131
'posts' => $user->posts()
32-
->with('user', 'user.group', 'topic:id,name,state')
32+
->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group')
3333
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
3434
->withSum('tips', 'bon')
3535
->authorized(canReadTopic: true)

app/Http/Livewire/PostSearch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final public function updatingSearch(): void
4343
final public function posts(): \Illuminate\Pagination\LengthAwarePaginator
4444
{
4545
return Post::query()
46-
->with('user', 'user.group', 'topic:id,name,state')
46+
->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group')
4747
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
4848
->withSum('tips', 'bon')
4949
->withExists([

app/Http/Livewire/TopicPostSearch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final public function updatingSearch(): void
5353
final public function posts(): \Illuminate\Pagination\LengthAwarePaginator
5454
{
5555
$posts = Post::query()
56-
->with('user', 'user.group')
56+
->with('user', 'user.group', 'updatedBy.group')
5757
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
5858
->withSum('tips', 'bon')
5959
->where('topic_id', '=', $this->topic->id)

app/Models/Post.php

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @property string $content
3030
* @property \Illuminate\Support\Carbon|null $created_at
3131
* @property \Illuminate\Support\Carbon|null $updated_at
32+
* @property int $updated_by
3233
* @property int $user_id
3334
* @property int $topic_id
3435
*/
@@ -48,6 +49,7 @@ class Post extends Model
4849
'content',
4950
'topic_id',
5051
'user_id',
52+
'updated_by',
5153
];
5254

5355
/**
@@ -73,6 +75,16 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
7375
]);
7476
}
7577

78+
/**
79+
* Belongs To An Updated User.
80+
*
81+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, $this>
82+
*/
83+
public function updatedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
84+
{
85+
return $this->belongsTo(User::class, 'updated_by', 'id')->withTrashed();
86+
}
87+
7688
/**
7789
* A Post Has Many Likes.
7890
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author HDVinnie <[email protected]>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
Schema::table('posts', function (Blueprint $table): void {
28+
$table->unsignedInteger('updated_by')->nullable()->after('updated_at');
29+
$table->foreign('updated_by')->references('id')->on('users')->cascadeOnUpdate()->nullOnDelet();
30+
});
31+
}
32+
33+
/**
34+
* Reverse the migrations.
35+
*
36+
* @return void
37+
*/
38+
public function down(): void
39+
{
40+
Schema::table('posts', function (Blueprint $table): void {
41+
$table->dropForeign(['updated_by']);
42+
$table->dropColumn('updated_by');
43+
});
44+
}
45+
};

resources/sass/components/forum/_post.scss

+59-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
grid-template-areas:
2727
'aside header'
2828
'aside content'
29+
'aside timestamps'
2930
'aside footer';
3031
grid-template-columns: minmax(153px, min-content) minmax(0, 1fr);
3132
grid-template-rows: auto 1fr auto;
@@ -38,8 +39,8 @@
3839
.post__header {
3940
grid-area: header;
4041
display: grid;
41-
grid-template-areas: 'datetime topic . tip-stats toolbar';
42-
grid-template-columns: auto auto 1fr auto auto;
42+
grid-template-areas: 'topic . tip-stats toolbar';
43+
grid-template-columns: auto 1fr auto auto;
4344
align-items: center;
4445
gap: 9px;
4546
font-size: 13px;
@@ -48,10 +49,6 @@
4849
padding-left: 9px;
4950
}
5051

51-
.post__datetime {
52-
grid-area: datetime;
53-
}
54-
5552
.post__topic {
5653
grid-area: topic;
5754
}
@@ -158,6 +155,7 @@
158155
background-color: transparent;
159156
color: var(--post-like-fg);
160157
}
158+
161159
.votes__dislike {
162160
background-color: transparent;
163161
color: var(--post-dislike-fg);
@@ -254,6 +252,43 @@
254252
line-height: 1.5;
255253
}
256254

255+
.post__timestamps {
256+
grid-area: timestamps;
257+
display: grid;
258+
grid-template-areas: '. datetime updated';
259+
grid-template-columns: 1fr auto auto;
260+
border-top: 2px solid var(--post-aside-bg);
261+
padding: 4px;
262+
font-size: 13px;
263+
}
264+
265+
.post__datetime {
266+
grid-area: datetime;
267+
}
268+
269+
.post__updated {
270+
grid-area: updated;
271+
cursor: pointer;
272+
margin-left: 4px;
273+
}
274+
275+
.post__updated-dropdown {
276+
display: none;
277+
background-color: var(--post-toolbar-bg);
278+
color: var(--post-toolbar-fg);
279+
position: absolute;
280+
padding: 5px;
281+
box-shadow: var(--post-shadow);
282+
border-radius: 5px;
283+
box-shadow: var(--post-shadow);
284+
z-index: 1;
285+
}
286+
287+
/* Show dropdown menu when the dropdown is focused */
288+
.post__updated:hover .post__updated-dropdown {
289+
display: block;
290+
}
291+
257292
.post__footer {
258293
grid-area: footer;
259294
border-top: 2px solid var(--post-aside-bg);
@@ -282,15 +317,15 @@
282317
cursor: pointer;
283318
}
284319

285-
@media screen and (max-width: 576px) {
320+
@media screen and (max-width: 1358px) {
286321
.post {
287-
grid-template-areas: 'aside' 'header' 'content' 'footer';
322+
grid-template-areas: 'aside' 'header' 'content' 'timestamps' 'footer';
288323
grid-template-columns: 100%;
289324
}
290325

291326
.post__header {
292-
grid-template-areas: 'datetime topic . tip-stats overflow' '. . . . toolbar';
293-
grid-template-columns: auto auto 1fr auto auto;
327+
grid-template-areas: 'topic tip-stats overflow' '. . . . toolbar';
328+
grid-template-columns: auto 1fr auto auto;
294329
gap: 0 6px;
295330
}
296331

@@ -353,15 +388,27 @@
353388
}
354389
}
355390

391+
@media screen and (max-width: 867px) {
392+
.post__timestamps {
393+
display: grid;
394+
grid-template-areas: '. datetime updated .';
395+
grid-template-columns: 1fr auto auto 1fr;
396+
border-top: 2px solid var(--post-aside-bg);
397+
padding: 4px;
398+
}
399+
}
400+
356401
@-webkit-keyframes post__like-animation {
357402
0% {
358403
-webkit-transform: scale(1);
359404
transform: scale(1);
360405
}
406+
361407
50% {
362408
-webkit-transform: scale(1.1);
363409
transform: scale(1.1);
364410
}
411+
365412
100% {
366413
-webkit-transform: scale(1);
367414
transform: scale(1);
@@ -373,10 +420,12 @@
373420
-webkit-transform: scale(1);
374421
transform: scale(1);
375422
}
423+
376424
50% {
377425
-webkit-transform: scale(1.1);
378426
transform: scale(1.1);
379427
}
428+
380429
100% {
381430
-webkit-transform: scale(1);
382431
transform: scale(1);

resources/views/components/forum/post.blade.php

+35-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
<article class="post" id="post-{{ $post->id }}" x-data>
66
<header class="post__header">
7-
<time
8-
class="post__datetime"
9-
datetime="{{ $post->created_at }}"
10-
title="{{ $post->created_at }}"
11-
>
12-
{{ $post->created_at?->diffForHumans() }}
13-
</time>
147
@if (! Route::is('topics.show'))
158
<span class="post__topic">
169
{{ __('forum.in') }}
@@ -234,6 +227,41 @@ class="post__content bbcode-rendered"
234227
>
235228
@joypixels($post->getContentHtml())
236229
</div>
230+
<span class="post__timestamps">
231+
<time
232+
class="post__datetime"
233+
datetime="{{ $post->created_at }}"
234+
title="{{ $post->created_at }}"
235+
>
236+
{{ $post->created_at?->diffForHumans() }}
237+
</time>
238+
@if ($post->updated_at > $post->created_at)
239+
<div class="post__updated">
240+
&bull; edited
241+
<i class="{{ config('other.font-awesome') }} fa-caret-down"></i>
242+
<div class="post__updated-dropdown">
243+
<time
244+
class="post__datetime"
245+
datetime="{{ $post->updated_at }}"
246+
title="{{ $post->updated_at }}"
247+
>
248+
{{ $post->updated_at?->diffForHumans() }}
249+
</time>
250+
by
251+
<a
252+
class="user-tag__link {{ $post->updatedBy->group->icon ?? $post->user->group->icon }}"
253+
href="{{ route('users.show', ['user' => $post->updatedBy ?? $post->user]) }}"
254+
style="
255+
color: {{ $post->updatedBy->group->color ?? $post->user->group->color }};
256+
"
257+
title="{{ $post->updatedBy->group->name ?? $post->user->group->name }}"
258+
>
259+
{{ $post->updatedBy?->username ?? $post->user->username }}
260+
</a>
261+
</div>
262+
</div>
263+
@endif
264+
</span>
237265
@if (! empty($post->user->signature))
238266
<footer class="post__footer" x-init>
239267
<p class="post__signature">

0 commit comments

Comments
 (0)