Skip to content

Commit

Permalink
fix(profile-chapters): change chapters tree render
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Groza committed Sep 10, 2019
1 parent d904f58 commit dc6877b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
9 changes: 7 additions & 2 deletions app/Http/Controllers/UserController.php
Expand Up @@ -11,11 +11,16 @@ public function show(string $name)
{
$user = User::where('name', $name)->firstOrFail();

$allChapters = Chapter::with('user')->get();
$allChapters = Chapter::all();
$userReadChapters = $user->readChapters;

$chaptersTree = $allChapters->each(function ($chapter) use ($userReadChapters) {
$chapter->is_read = $userReadChapters->contains('id', $chapter->id);
})->pluck('is_read', 'path');

return view('user.index', [
'user' => $user,
'allChapters' => $allChapters
'chaptersTree' => $chaptersTree
]);
}
}
6 changes: 3 additions & 3 deletions resources/views/user/index.blade.php
Expand Up @@ -11,13 +11,13 @@
</div>
<div class="col-12 col-md-9 my-4 d-flex flex-column">
<ul class="chapters-tree">
@foreach($allChapters as $chapter)
@foreach($chaptersTree as $path => $is_read)

<li class="chapters-tree-item">
<label>
<input type="checkbox" {{ $chapter->is_read ? 'checked' : '' }}>
<input type="checkbox" {{ $is_read ? 'checked' : '' }}>
</label>
{{ $chapter->path }}
{{ $path }}
</li>

@endforeach
Expand Down
24 changes: 0 additions & 24 deletions tests/Unit/Model/ChapterTest.php

This file was deleted.

0 comments on commit dc6877b

Please sign in to comment.