From: Daniel Karbach Date: Wed, 16 Nov 2022 16:49:05 +0000 (+0100) Subject: random comments on profile page X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=35d1ce20e64f3373d74816ed1bf9440b4213fa1a;p=alttp.git random comments on profile page --- 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;