]> git.localhorst.tv Git - alttp.git/commitdiff
random comments on profile page
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 16 Nov 2022 16:49:05 +0000 (17:49 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 16 Nov 2022 16:49:05 +0000 (17:49 +0100)
app/Http/Controllers/UserController.php
app/Models/User.php
resources/js/components/users/Profile.js
resources/sass/common.scss

index 4bf2bb30324cf88c73c4b0225123de81793f1e7d..01b8f06fabeec18bdea89117806b9aea0c39f866 100644 (file)
@@ -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');
index 164fb026bfecba420a784daf83b44697f37cd869..8373b5d236c134a5cd0f2fc8127505e0dfb53966 100644 (file)
@@ -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';
index a8a4e95143d40891dc631835249403d6621644b8..b4c40605abbdb06e0027e966d9e00b89c7d53a22 100644 (file)
@@ -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 }) => <Container>
                {' '}
                <EditNicknameButton user={user} />
        </h1>
+       {user.random_quote && user.random_quote.comment ?
+               <Alert className="quote-alert" variant="dark">
+                       <blockquote className="blockquote mb-0">
+                               {user.random_quote.comment}
+                       </blockquote>
+               </Alert>
+       : null}
        <Row>
                <Col md={6} className="mb-5">
                        <h2>{i18n.t('users.discordTag')}</h2>
@@ -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,
index 97822fe32037ad1185f6e004635a5371de4fb258..c8528e19b6f260657e3ebdb7d8a3353831562754 100644 (file)
@@ -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;