From 6cd26e23a800b35a5f83df77cb723d00c70a2dec Mon Sep 17 00:00:00 2001 From: jakob Date: Wed, 30 Oct 2019 11:23:42 +0100 Subject: [PATCH] Allow toggling between grid and list view in shelf view (shelves.show) --- app/Http/Controllers/BookshelfController.php | 2 ++ resources/views/shelves/show.blade.php | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index 57e67dc00..5c9da762f 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -103,6 +103,7 @@ class BookshelfController extends Controller public function show(string $slug) { $shelf = $this->bookshelfRepo->getBySlug($slug); + $view = setting()->getForCurrentUser('books_view_type', config('app.views.books')); $this->checkOwnablePermission('book-view', $shelf); Views::add($shelf); @@ -111,6 +112,7 @@ class BookshelfController extends Controller $this->setPageTitle($shelf->getShortName()); return view('shelves.show', [ 'shelf' => $shelf, + 'view' => $view, 'activity' => Activity::entityActivity($shelf, 20, 1) ]); } diff --git a/resources/views/shelves/show.blade.php b/resources/views/shelves/show.blade.php index 2212e1c1e..56df61c91 100644 --- a/resources/views/shelves/show.blade.php +++ b/resources/views/shelves/show.blade.php @@ -13,11 +13,19 @@

{!! nl2br(e($shelf->description)) !!}

@if(count($shelf->visibleBooks) > 0) -
- @foreach($shelf->visibleBooks as $book) - @include('books.list-item', ['book' => $book]) - @endforeach -
+ @if($view === 'list') +
+ @foreach($shelf->visibleBooks as $book) + @include('books.list-item', ['book' => $book]) + @endforeach +
+ @else +
+ @foreach($shelf->visibleBooks as $key => $book) + @include('books.grid-item', ['book' => $book]) + @endforeach +
+ @endif @else

@@ -87,6 +95,8 @@ @endif + @include('partials.view-toggle', ['view' => $view, 'type' => 'book']) +
@if(userCan('bookshelf-update', $shelf))