Skip to content

Commit

Permalink
feat: working task view filters
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Oct 5, 2023
1 parent 5536270 commit 7105ebb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ class TaskController extends Controller
* @return \Illuminate\Http\Response
*
*/
public function index()
public function index($activeFilter = null)
{
$user = auth()->user();
$tasks = Task::where('recipient_user_id', $user->id)->where('status', TaskStatus::PENDING->value)->get()->sortBy('created_at');

return view('tasks.index', compact('tasks'));
if($activeFilter == 'sent'){
$tasks = Task::where('sender_user_id', $user->id)->get()->sortBy('created_at');
} elseif($activeFilter == 'archive'){
$tasks = Task::where('recipient_user_id', $user->id)->whereIn('status', [TaskStatus::COMPLETED->value, TaskStatus::DECLINED->value])->get()->sortBy('created_at');
} else {
$tasks = Task::where('recipient_user_id', $user->id)->where('status', TaskStatus::PENDING->value)->get()->sortBy('created_at');
}

return view('tasks.index', compact('tasks', 'activeFilter'));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions resources/views/tasks/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@section('title-flex')
<div>
<i class="fas fa-filter"></i>&nbsp;Filter:&nbsp;
<a class="btn btn-sm btn-primary" href="">Open</a>
<a class="btn btn-sm btn-outline-primary" href="">Sent</a>
<a class="btn btn-sm btn-outline-primary" href="">Archived</a>
<a class="btn btn-sm {{ ($activeFilter != 'sent' && $activeFilter != 'archived') ? 'btn-primary' : 'btn-outline-primary' }}" href="{{ route('tasks') }}">Open</a>
<a class="btn btn-sm {{ ($activeFilter == 'sent') ? 'btn-primary' : 'btn-outline-primary' }}" href="{{ route('tasks.filtered', 'sent') }}">Sent</a>
<a class="btn btn-sm {{ ($activeFilter == 'archived') ? 'btn-primary' : 'btn-outline-primary' }}" href="{{ route('tasks.filtered', 'archived') }}">Archived</a>
</div>
@endsection

Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

Route::controller(TaskController::class)->group(function () {
Route::get('/tasks', 'index')->name('tasks');
Route::get('/tasks/{activeFilter}', 'index')->name('tasks.filtered');
Route::get('/tasks/complete/{id}', 'complete')->name('task.complete');
Route::post('/task/store', 'store')->name('task.store');
});
Expand Down

0 comments on commit 7105ebb

Please sign in to comment.