More user page tweaks

This commit is contained in:
Timothy Warren 2023-05-18 16:25:50 -04:00
parent b678a3401e
commit f2b7f61030
9 changed files with 37 additions and 39 deletions

View File

@ -16,7 +16,9 @@ use Aviat\AnimeClient\Kitsu;
<aside class="info"> <aside class="info">
<table class="media-details invisible"> <table class="media-details invisible">
<tr> <tr>
<td><?= $helper->img($data['avatar'], ['alt' => '']); ?></td> <?php if($data['avatar'] !== null): ?>
<td><?= $helper->img($data['avatar'], ['alt' => '', 'width' => '225']); ?></td>
<?php endif ?>
<td><?= $escape->html($data['about']) ?></td> <td><?= $escape->html($data['about']) ?></td>
</tr> </tr>
</table> </table>
@ -25,6 +27,7 @@ use Aviat\AnimeClient\Kitsu;
<?php foreach ([ <?php foreach ([
'joinDate' => 'Joined', 'joinDate' => 'Joined',
'birthday' => 'Birthday', 'birthday' => 'Birthday',
'gender' => 'Gender',
'location' => 'Location' 'location' => 'Location'
] as $key => $label): ?> ] as $key => $label): ?>
<?php if ($data[$key] !== null): ?> <?php if ($data[$key] !== null): ?>
@ -42,7 +45,7 @@ use Aviat\AnimeClient\Kitsu;
</tr> </tr>
<?php endif ?> <?php endif ?>
<?php if ( ! empty($data['waifu'])): ?> <?php if ($data['waifu']['character'] !== null): ?>
<tr> <tr>
<td><?= $escape->html($data['waifu']['label']) ?></td> <td><?= $escape->html($data['waifu']['label']) ?></td>
<td> <td>

View File

@ -1,15 +0,0 @@
{
"name": "Anilist Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Anilist": {
"url": "https://graphql.anilist.co",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}

View File

@ -0,0 +1,8 @@
schema: schema.graphql
extensions:
endpoints:
Anilist:
url: https://graphql.anilist.co
headers:
user-agent: JS GraphQL
introspect: true

View File

@ -1,15 +0,0 @@
{
"name": "Kitsu Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Kitsu": {
"url": "https://kitsu.io/api/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}

View File

@ -21,6 +21,7 @@ query ($slug: String!) {
createdAt createdAt
id id
location location
gender
name name
proMessage proMessage
proTier proTier

View File

@ -39,17 +39,18 @@ final class UserTransformer extends AbstractTransformer
] : []; ] : [];
return User::from([ return User::from([
'about' => $base['about'], 'about' => $base['about'] ?? '',
'avatar' => $base['avatarImage']['original']['url'], 'avatar' => $base['avatarImage']['original']['url'] ?? null,
'birthday' => Kitsu::formatDate($base['birthday']) . ' (' . Kitsu::friendlyTime(Kitsu::getDateDiff($base['birthday']), 'year') . ')', 'birthday' => $base['birthday'] !== null ? Kitsu::formatDate($base['birthday']) . ' (' . Kitsu::friendlyTime(Kitsu::getDateDiff($base['birthday']), 'year') . ')' : null,
'joinDate' => Kitsu::formatDate($base['createdAt']) . ' (' . Kitsu::friendlyTime(Kitsu::getDateDiff($base['createdAt']), 'day') . ')', 'joinDate' => Kitsu::formatDate($base['createdAt']) . ' (' . Kitsu::friendlyTime(Kitsu::getDateDiff($base['createdAt']), 'day') . ' ago)',
'gender' => $base['gender'],
'favorites' => $this->organizeFavorites($favorites), 'favorites' => $this->organizeFavorites($favorites),
'location' => $base['location'], 'location' => $base['location'],
'name' => $base['name'], 'name' => $base['name'],
'slug' => $base['slug'], 'slug' => $base['slug'],
'stats' => $this->organizeStats($stats), 'stats' => $this->organizeStats($stats),
'waifu' => $waifu, 'waifu' => $waifu,
'website' => $base['siteLinks']['nodes'][0]['url'], 'website' => $base['siteLinks']['nodes'][0]['url'] ?? null,
]); ]);
} }

View File

@ -0,0 +1,8 @@
schema: schema.graphql
extensions:
endpoints:
Kitsu:
url: https://kitsu.io/api/graphql
headers:
user-agent: JS GraphQL
introspect: true

View File

@ -69,6 +69,12 @@ final class User extends BaseController
: $username; : $username;
$rawData = $this->kitsuModel->getUserData($username); $rawData = $this->kitsuModel->getUserData($username);
if ($rawData['data']['findProfileBySlug'] === null)
{
$this->notFound('Sorry, user not found', "The user '$username' does not seem to exist.");
return;
}
$data = (new UserTransformer())->transform($rawData)->toArray(); $data = (new UserTransformer())->transform($rawData)->toArray();
$this->outputHTML('user/details', [ $this->outputHTML('user/details', [

View File

@ -22,12 +22,13 @@ final class User extends AbstractType
public ?string $about; public ?string $about;
public ?string $avatar; public ?string $avatar;
public ?string $birthday; public ?string $birthday;
public ?string $joinDate; public string $joinDate;
public ?string $gender;
public ?array $favorites; public ?array $favorites;
public ?string $location; public ?string $location;
public ?string $name; public ?string $name;
public ?string $slug; public ?string $slug;
public ?array $stats; public ?array $stats;
public ?array $waifu; public array $waifu;
public ?string $website; public ?string $website;
} }