Skip to content

Commit

Permalink
Added dashboard and comment deletion if timeline owner
Browse files Browse the repository at this point in the history
  • Loading branch information
katsulon committed Dec 18, 2024
1 parent 346c1ba commit 8196bd3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
20 changes: 18 additions & 2 deletions timeliner/app/Http/Controllers/TimelineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@

class TimelineController extends Controller
{
public function timelinesWithOwnership()
{
$timelines = Timeline::all();

return $timelines->filter(function ($timeline) {
return Auth::check() && Ownership::find($timeline->id . Auth::user()->id);
});
}

public function index()
{
$timelines = Timeline::all();
return view('index', ['timelines' => $timelines]);

$timelinesWithOwnership = $this->timelinesWithOwnership();

return view('index', ['timelines' => $timelines, 'timelinesWithOwnership' => $timelinesWithOwnership]);
}

public function timelinelist()
{
return view('timeline.timelinelist');
$timelinesWithOwnership = $this->timelinesWithOwnership();

$timelines = $timelinesWithOwnership;

return view('dashboard', ['timelines' => $timelines, 'timelinesWithOwnership' => $timelinesWithOwnership]);
}

public function show($id)
Expand Down
3 changes: 3 additions & 0 deletions timeliner/resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __("You're logged in!") }}
</div>
<div class="p-6 text-gray-900 dark:text-gray-100">
@include("timeline.partials.timelinelist", $timelines)
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p class="card-text" style="white-space: pre-wrap">{{ $comment->comment }}</p>

@auth
@if ($comment->user_id == Auth::id())
@if ($comment->user_id == Auth::id() || $isOwner)
<button class="btn btn-primary bi bi-pencil toggle-button" data-target="editComment{{ $comment->id }}"> Edit Comment</button>
<form id="editComment{{ $comment->id }}" class="hidden" action="{{ route('comment.update', $comment->id) }}" method="POST">
@csrf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@php
use App\Models\Ownership;
@endphp
<div class="timeline-for-list-template">
<div class="row align-items-stretch d-flex">
<div class="col-11 p-0">
Expand All @@ -18,7 +15,7 @@
</div>

@auth
@if (Ownership::find($timeline->id . Auth::user()->id))
@if($timelinesWithOwnership->contains($timeline->id))
<form class="d-flex align-items-stretch mb-4" action="{{ route('timeline.destroy', $timeline->id) }}" method="POST" onsubmit="return confirm('Are you sure you want to delete this timeline?');">
@csrf
@method('DELETE')
Expand Down
6 changes: 1 addition & 5 deletions timeliner/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
return view('about');
})->name('about');

Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');


Route::get('dashboard', [TimelineController::class, 'timelinelist'])->name('dashboard')->middleware(['auth', 'verified']);

Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Expand Down

0 comments on commit 8196bd3

Please sign in to comment.