From 573c848d510ef7f1b959b20eb8a6bf4c167a856b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 11 Apr 2020 20:37:51 +0100 Subject: [PATCH] Added dark/light mode toggle to profile dropdown menu - Also fixed some remaining areas which needed dark mode support. --- app/Http/Controllers/UserController.php | 10 ++++++++++ resources/icons/dark-mode.svg | 1 + resources/icons/light-mode.svg | 1 + resources/sass/_lists.scss | 3 +++ resources/views/base.blade.php | 10 +++------- resources/views/common/header.blade.php | 12 ++++++++++++ routes/web.php | 1 + 7 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 resources/icons/dark-mode.svg create mode 100644 resources/icons/light-mode.svg diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 43cbad1fb..775e2a984 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -312,6 +312,16 @@ class UserController extends Controller return $this->changeListSort($id, $request, $type); } + /** + * Toggle dark mode for the current user. + */ + public function toggleDarkMode() + { + $enabled = setting()->getForCurrentUser('dark-mode-enabled', false); + setting()->putUser(user(), 'dark-mode-enabled', $enabled ? 'false' : 'true'); + return redirect()->back(); + } + /** * Update the stored section expansion preference for the given user. */ diff --git a/resources/icons/dark-mode.svg b/resources/icons/dark-mode.svg new file mode 100644 index 000000000..8b00d72a5 --- /dev/null +++ b/resources/icons/dark-mode.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/icons/light-mode.svg b/resources/icons/light-mode.svg new file mode 100644 index 000000000..cf2961d2e --- /dev/null +++ b/resources/icons/light-mode.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/sass/_lists.scss b/resources/sass/_lists.scss index 8165d532d..5eb672697 100644 --- a/resources/sass/_lists.scss +++ b/resources/sass/_lists.scss @@ -603,6 +603,9 @@ ul.pagination { li.border-bottom { border-bottom: 1px solid #DDD; } + li hr { + margin: $-xs 0; + } } // Books grid view diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index 0f43532fb..a5404a365 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -1,5 +1,7 @@ - + {{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name') }} @@ -23,12 +25,6 @@ @stack('translations') - - diff --git a/resources/views/common/header.blade.php b/resources/views/common/header.blade.php index ec90739ee..af7aaeeb0 100644 --- a/resources/views/common/header.blade.php +++ b/resources/views/common/header.blade.php @@ -70,6 +70,18 @@ @icon('logout'){{ trans('auth.logout') }} @endif +

  • +
  • +
    + {{ csrf_field() }} + {{ method_field('patch') }} + @if(setting()->getForCurrentUser('dark-mode-enabled')) + + @else + + @endif +
    +
  • @endif diff --git a/routes/web.php b/routes/web.php index 4dfccdf36..3e05e394d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -183,6 +183,7 @@ Route::group(['middleware' => 'auth'], function () { Route::patch('/users/{id}/switch-shelf-view', 'UserController@switchShelfView'); Route::patch('/users/{id}/change-sort/{type}', 'UserController@changeSort'); Route::patch('/users/{id}/update-expansion-preference/{key}', 'UserController@updateExpansionPreference'); + Route::patch('/users/toggle-dark-mode', 'UserController@toggleDarkMode'); Route::post('/users/create', 'UserController@store'); Route::get('/users/{id}', 'UserController@edit'); Route::put('/users/{id}', 'UserController@update');