Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add news announcement carousel to dashboard #9617

Merged
merged 48 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d53a04e
Add news announcement model and transformer
cl8n Dec 9, 2022
b253dd2
Add news announcement carousel thing to dashboard
cl8n Dec 9, 2022
a8259cb
...JSON
cl8n Dec 9, 2022
41aec09
Merge master
cl8n Aug 7, 2023
e27be8b
Fix component and migration filename
cl8n Aug 7, 2023
f8c965c
Darker background for announcement content overlay
cl8n Aug 8, 2023
ee2dd65
Simplify / clean up news announcements component
cl8n Aug 8, 2023
aba24ec
Make buttons cover full news announcement height
cl8n Aug 8, 2023
499abb2
Null entire content JSON field if content_markdown is null
cl8n Aug 8, 2023
fddcc3f
Fix indicator rows changing size
cl8n Aug 8, 2023
dfd92c8
Add "infinite scrolling" look to carousel
cl8n Aug 8, 2023
77f8be2
Simpler auto rotate timer clear
cl8n Aug 8, 2023
6e7403f
Match indicator opacity to figma design
cl8n Aug 9, 2023
f84a71a
Add placeholder for news announcements to prevent page jump
cl8n Aug 9, 2023
6c4f99d
Fix operator precedence in news announcement query
cl8n Aug 9, 2023
d263666
Move news announcements component to component directory
cl8n Aug 9, 2023
11be4fb
Missing type
cl8n Aug 9, 2023
9fa75db
Rename "button" to "arrow"
cl8n Aug 16, 2023
1b2067c
Always return early from setIndex if index is the same
cl8n Aug 16, 2023
ec6c83e
Move indicators inside the main div
cl8n Aug 16, 2023
3bc3816
Make indicators act as buttons
cl8n Aug 16, 2023
83e8b93
Merge master
cl8n Jun 17, 2024
c55973b
Readonly lint
cl8n Jun 17, 2024
4c2ef66
Add MenuContent
cl8n Jun 17, 2024
05cc085
Delete NewsAnnouncement things
cl8n Jun 17, 2024
1e22658
Rename everything else
cl8n Jun 17, 2024
fcbfe79
Remove content and 2x features
cl8n Jun 17, 2024
1b99484
Oopses
cl8n Jun 17, 2024
2336e51
Use variables to reference menu image heights and margins
cl8n Jun 17, 2024
3acce36
Better image fit
cl8n Jun 17, 2024
c9f0903
Separate component for single image
cl8n Jun 17, 2024
45356f0
Remove now unnecessary overflow hiding
cl8n Jun 17, 2024
ca45a28
Reword comment about image clones
cl8n Jun 17, 2024
573cdd5
Update fitting for new images
cl8n Jun 24, 2024
ea8a0d3
Merge remote-tracking branch 'origin/master' into HEAD
nanaya Oct 2, 2024
4c1f8af
Default variable value
nanaya Oct 2, 2024
ab817a6
Use default text shadow
nanaya Oct 2, 2024
2d87cd0
Skip extra container
nanaya Oct 2, 2024
1590e2a
Remove derivable variables
nanaya Oct 2, 2024
06c0002
Use shorthand function syntax
nanaya Oct 2, 2024
0226c08
Hide arrow until hovered
nanaya Oct 2, 2024
cb96fdd
Absolute positioning already implies block display
nanaya Oct 2, 2024
5781a55
Fix css lint
nanaya Oct 2, 2024
0bd2d11
Configurable menu content url
nanaya Oct 4, 2024
df65d56
Use class directly
nanaya Oct 4, 2024
8a90f1d
Pause animation if document is hidden
nanaya Oct 4, 2024
254ce39
Skip if no image at all
nanaya Oct 4, 2024
1ae898e
Merge branch 'master' into news-announcements
notbakaneko Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use App;
use App\Libraries\CurrentStats;
use App\Libraries\MenuContent;
use App\Libraries\Search\AllSearch;
use App\Libraries\Search\QuickSearch;
use App\Models\BeatmapDownload;
Expand Down Expand Up @@ -98,10 +99,12 @@ public function index()
$news = NewsPost::default()->limit($newsLimit)->get();

if (Auth::check()) {
$menuImages = json_collection(MenuContent::activeImages(), 'MenuImage');
nanaya marked this conversation as resolved.
Show resolved Hide resolved
$newBeatmapsets = Beatmapset::latestRanked();
$popularBeatmapsets = Beatmapset::popular()->get();

return ext_view('home.user', compact(
'menuImages',
'newBeatmapsets',
'news',
'popularBeatmapsets'
Expand Down
67 changes: 67 additions & 0 deletions app/Libraries/MenuContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries;

use Carbon\Carbon;
use Exception;
use GuzzleHttp\Client;

class MenuContent
{
/**
* Get all active menu content images.
*
* @return array<string, mixed>[]
*/
public static function activeImages(): array
{
return cache_remember_mutexed('menu-content-active-images', 60, [], function () {
$images = self::parse(self::fetch());
$now = Carbon::now();

return array_values(array_filter($images, function ($image) use ($now) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use fn ($image) => ...

return ($image['started_at']?->lessThanOrEqualTo($now) ?? true)
&& ($image['ended_at']?->greaterThan($now) ?? true);
}));
});
}

private static function fetch(): array
{
$response = (new Client())
->get(osu_url('menu_content'))
->getBody()
->getContents();

return json_decode($response, true);
}

private static function parse(array $data): array
{
if (!is_array($data['images'] ?? null)) {
throw new Exception('Invalid "images" key in menu-content response');
}

$parsedImages = [];

foreach ($data['images'] as $image) {
if (!is_string($image['image']) || !is_string($image['url'])) {
throw new Exception('Invalid "image" or "url" key in menu-content image');
}

$parsedImages[] = [
'ended_at' => parse_time_to_carbon($image['expires']),
'image_url' => $image['image'],
'started_at' => parse_time_to_carbon($image['begins']),
'url' => $image['url'],
];
}

return $parsedImages;
}
}
21 changes: 21 additions & 0 deletions app/Transformers/MenuImageTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Transformers;

class MenuImageTransformer extends TransformerAbstract
{
public function transform(array $menuImage): array
{
return [
'ended_at' => json_time($menuImage['ended_at']),
'image_url' => $menuImage['image_url'],
'started_at' => json_time($menuImage['started_at']),
'url' => $menuImage['url'],
];
}
}
1 change: 1 addition & 0 deletions config/osu.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
'lazer_dl.windows_x64' => presence(env('OSU_URL_LAZER_WINDOWS_X64')) ?? 'https://github.com/ppy/osu/releases/latest/download/install.exe',
'lazer_dl_other' => presence(env('OSU_URL_LAZER_OTHER')) ?? 'https://github.com/ppy/osu/#running-osu',
'lazer_info' => presence(env('OSU_URL_LAZER_INFO')),
'menu_content' => 'https://assets.ppy.sh/menu-content.json',
nanaya marked this conversation as resolved.
Show resolved Hide resolved
'osx' => 'https://osx.ppy.sh',
'server_status' => 'https://status.ppy.sh',
'smilies' => '/forum/images/smilies',
Expand Down
2 changes: 2 additions & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
@import "bem/logo";
@import "bem/love-beatmap-dialog";
@import "bem/medals-group";
@import "bem/menu-image";
@import "bem/menu-images";
@import "bem/message-length-counter";
@import "bem/mobile-menu";
@import "bem/mobile-menu-tab";
Expand Down
20 changes: 20 additions & 0 deletions resources/css/bem/menu-image.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.menu-image {
height: 100%;
left: calc(100% * var(--index, 0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable should be defined otherwise it may end up using unrelated variable from its parents

position: absolute;
width: 100%;

&__image {
height: 100%;
object-fit: cover;
width: 100%;
}

&__link {
display: block;
height: 100%;
}
}
86 changes: 86 additions & 0 deletions resources/css/bem/menu-images.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.menu-images {
@container-height: 250px;
@indicator-height: 6px;
@indicators-margin: 10px;
@margin: 20px;

margin-top: @margin;
overflow-x: hidden;
position: relative;

&__arrow {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe only show this when hovering the area

.reset-input();
height: @container-height;
padding: 10px;
position: absolute;
top: 0;

&:hover {
color: @osu-colour-l1;
}

&--left {
--icon: @fa-var-chevron-left;
left: 0;
}

&--right {
--icon: @fa-var-chevron-right;
right: 0;
}

&::before {
.fas();
content: var(--icon);
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine with default text shadow

}
}

&__container {
height: @container-height;
transform: translateX(calc(-100% * var(--index, 0)));

&--transition {
transition: transform 300ms ease-in-out;
}
}

&__indicator {
.reset-input();
align-items: center;
display: flex;
height: @indicator-height;

&::before {
background: @osu-colour-h1;
border-radius: 10000px;
content: '';
height: 2px;
opacity: 0.5;
transition: 100ms ease-out;
transition-property: height, opacity;
width: 30px;
}

&:hover::before {
height: @indicator-height;
}

&--active::before {
height: @indicator-height;
opacity: 1;
}
}

&__indicators {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
margin-top: @indicators-margin;
}
}
14 changes: 14 additions & 0 deletions resources/css/bem/user-home.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
}
}

&__menu-images-placeholder {
align-items: center;
display: flex;
height: .menu-images[@container-height];
justify-content: center;
margin-top: .menu-images[@margin];

&--with-indicators {
// This part won't be identical to the real component if the indicators
// wrap onto more than one line, but it's good enough for a placeholder
margin-bottom: .menu-images[@indicator-height] + .menu-images[@indicators-margin];
}
}

&__news-posts-group {
.default-box-shadow();
display: block;
Expand Down
25 changes: 25 additions & 0 deletions resources/js/components/menu-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import MenuImageJson from 'interfaces/menu-image-json';
import * as React from 'react';

const bn = 'menu-image';

interface Props {
image: MenuImageJson;
index?: number;
}

export default function MenuImage({ image, index }: Props) {
return (
<div
className={bn}
style={{ '--index': index } as React.CSSProperties}
>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this div can just be the anchor instead?

<a className={`${bn}__link`} href={image.url}>
<img className={`${bn}__image`} src={image.image_url} />
</a>
</div>
);
}
Loading