0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-05-22 15:57:29 +00:00

Added core code-lang-favourites JS, PHP & CSS logic

- Got the functionality now working to favourite items and store that
  status within the system for the user.
- Improved CSS display for usability.
This commit is contained in:
Dan Brown 2022-07-25 13:10:27 +01:00
parent ebc5a53410
commit 0df5ae0658
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
5 changed files with 76 additions and 8 deletions
app/Http/Controllers

View file

@ -289,6 +289,27 @@ class UserController extends Controller
return response('', 204);
}
public function updateCodeLanguageFavourite(Request $request)
{
$validated = $this->validate($request, [
'language' => ['required', 'string', 'max:20'],
'active' => ['required', 'bool'],
]);
$currentFavoritesStr = setting()->getForCurrentUser('code-language-favourites', '');
$currentFavorites = array_filter(explode(',', $currentFavoritesStr));
$isFav = in_array($validated['language'], $currentFavorites);
if (!$isFav && $validated['active']) {
$currentFavorites[] = $validated['language'];
} else if ($isFav && !$validated['active']) {
$index = array_search($validated['language'], $currentFavorites);
array_splice($currentFavorites, $index, 1);
}
setting()->putUser(user(), 'code-language-favourites', implode(',', $currentFavorites));
}
/**
* Changed the stored preference for a list sort order.
*/