From 35d1ce20e64f3373d74816ed1bf9440b4213fa1a Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 16 Nov 2022 17:49:05 +0100 Subject: [PATCH] random comments on profile page --- app/Http/Controllers/UserController.php | 1 + app/Models/User.php | 11 +++++++++++ resources/js/components/users/Profile.js | 12 +++++++++++- resources/sass/common.scss | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4bf2bb3..01b8f06 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -70,6 +70,7 @@ class UserController extends Controller public function single(Request $request, $id) { $user = User::findOrFail($id); $this->authorize('view', $user); + $user->append('random_quote'); $user->load('participation'); $user->load('participation.tournament'); $user->loadCount('round_first'); diff --git a/app/Models/User.php b/app/Models/User.php index 164fb02..8373b5d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -28,6 +29,16 @@ class User extends Authenticatable return $this->username; } + public function getRandomQuoteAttribute() { + return $this->results() + ->where('comment', '!=', '') + ->whereHas('round', function(Builder $query) { + $query->where('locked', true); + }) + ->inRandomOrder() + ->first(); + } + public function isAdmin() { return $this->role === 'admin'; diff --git a/resources/js/components/users/Profile.js b/resources/js/components/users/Profile.js index a8a4e95..b4c4060 100644 --- a/resources/js/components/users/Profile.js +++ b/resources/js/components/users/Profile.js @@ -1,6 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; -import { Button, Col, Container, Row } from 'react-bootstrap'; +import { Alert, Button, Col, Container, Row } from 'react-bootstrap'; import { withTranslation } from 'react-i18next'; import Box from './Box'; @@ -17,6 +17,13 @@ const Profile = ({ user }) => {' '} + {user.random_quote && user.random_quote.comment ? + +
+ {user.random_quote.comment} +
+
+ : null}

{i18n.t('users.discordTag')}

@@ -70,6 +77,9 @@ Profile.propTypes = { nickname: PropTypes.string, participation: PropTypes.arrayOf(PropTypes.shape({ })), + random_quote: PropTypes.shape({ + comment: PropTypes.string, + }), round_first_count: PropTypes.number, round_second_count: PropTypes.number, round_third_count: PropTypes.number, diff --git a/resources/sass/common.scss b/resources/sass/common.scss index 97822fe..c8528e1 100644 --- a/resources/sass/common.scss +++ b/resources/sass/common.scss @@ -29,6 +29,18 @@ h1 { max-width: none !important; } +.quote-alert { + position: relative; + &::after { + position: absolute; + top: 0; + right: 1ex; + content: "”"; + font-size: 3em; + opacity: .5; + } +} + .spoiler { border-radius: 0.5ex; padding: 0 0.5ex; -- 2.39.2