-
Notifications
You must be signed in to change notification settings - Fork 381
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
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
d53a04e
Add news announcement model and transformer
cl8n b253dd2
Add news announcement carousel thing to dashboard
cl8n a8259cb
...JSON
cl8n 41aec09
Merge master
cl8n e27be8b
Fix component and migration filename
cl8n f8c965c
Darker background for announcement content overlay
cl8n ee2dd65
Simplify / clean up news announcements component
cl8n aba24ec
Make buttons cover full news announcement height
cl8n 499abb2
Null entire content JSON field if content_markdown is null
cl8n fddcc3f
Fix indicator rows changing size
cl8n dfd92c8
Add "infinite scrolling" look to carousel
cl8n 77f8be2
Simpler auto rotate timer clear
cl8n 6e7403f
Match indicator opacity to figma design
cl8n f84a71a
Add placeholder for news announcements to prevent page jump
cl8n 6c4f99d
Fix operator precedence in news announcement query
cl8n d263666
Move news announcements component to component directory
cl8n 11be4fb
Missing type
cl8n 9fa75db
Rename "button" to "arrow"
cl8n 1b2067c
Always return early from setIndex if index is the same
cl8n ec6c83e
Move indicators inside the main div
cl8n 3bc3816
Make indicators act as buttons
cl8n 83e8b93
Merge master
cl8n c55973b
Readonly lint
cl8n 4c2ef66
Add MenuContent
cl8n 05cc085
Delete NewsAnnouncement things
cl8n 1e22658
Rename everything else
cl8n fcbfe79
Remove content and 2x features
cl8n 1b99484
Oopses
cl8n 2336e51
Use variables to reference menu image heights and margins
cl8n 3acce36
Better image fit
cl8n c9f0903
Separate component for single image
cl8n 45356f0
Remove now unnecessary overflow hiding
cl8n ca45a28
Reword comment about image clones
cl8n 573cdd5
Update fitting for new images
cl8n ea8a0d3
Merge remote-tracking branch 'origin/master' into HEAD
nanaya 4c1f8af
Default variable value
nanaya ab817a6
Use default text shadow
nanaya 2d87cd0
Skip extra container
nanaya 1590e2a
Remove derivable variables
nanaya 06c0002
Use shorthand function syntax
nanaya 0226c08
Hide arrow until hovered
nanaya cb96fdd
Absolute positioning already implies block display
nanaya 5781a55
Fix css lint
nanaya 0bd2d11
Configurable menu content url
nanaya df65d56
Use class directly
nanaya 8a90f1d
Pause animation if document is hidden
nanaya 254ce39
Skip if no image at all
nanaya 1ae898e
Merge branch 'master' into news-announcements
notbakaneko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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, fn ($image) => ( | ||
($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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
.menu-image { | ||
--index: 0; | ||
width: 100%; | ||
height: 100%; | ||
left: calc(100% * var(--index)); | ||
position: absolute; | ||
|
||
&__image { | ||
object-fit: contain; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
.menu-images { | ||
--arrow-opacity: 0; | ||
--container-height: 90px; | ||
--indicators-opacity: 1; | ||
|
||
margin-top: 20px; | ||
overflow-x: hidden; | ||
position: relative; | ||
|
||
&:hover { | ||
--arrow-opacity: 1; | ||
} | ||
|
||
&--placeholder { | ||
--indicators-opacity: 0; | ||
} | ||
|
||
&__arrow { | ||
.reset-input(); | ||
.fade-element(@hover-transition-duration); | ||
height: var(--container-height); | ||
padding: 10px; | ||
position: absolute; | ||
top: 0; | ||
opacity: var(--arrow-opacity); | ||
|
||
&:hover { | ||
color: @osu-colour-l1; | ||
} | ||
|
||
&--left { | ||
--icon: @fa-var-chevron-left; | ||
left: 0; | ||
} | ||
|
||
&--right { | ||
--icon: @fa-var-chevron-right; | ||
right: 0; | ||
} | ||
|
||
&::before { | ||
.fas(); | ||
.default-text-shadow(); | ||
content: var(--icon); | ||
} | ||
} | ||
|
||
&__container { | ||
.center-content(); | ||
display: flex; | ||
height: var(--container-height); | ||
transform: translateX(calc(-100% * var(--index, 0))); | ||
|
||
&--transition { | ||
transition: transform 300ms ease-in-out; | ||
} | ||
} | ||
|
||
&__indicator { | ||
.reset-input(); | ||
align-items: center; | ||
display: flex; | ||
|
||
width: 30px; | ||
height: 6px; | ||
|
||
--content-height: 2px; | ||
--content-opacity: 0.5; | ||
|
||
&::before { | ||
content: ""; | ||
|
||
background: @osu-colour-h1; | ||
border-radius: 10000px; | ||
opacity: var(--content-opacity); | ||
|
||
transition: 100ms ease-out; | ||
transition-property: height, opacity; | ||
|
||
width: 100%; | ||
height: var(--content-height); | ||
} | ||
|
||
&:hover { | ||
--content-height: 100%; | ||
} | ||
|
||
&--active { | ||
--content-height: 100%; | ||
--content-opacity: 1; | ||
} | ||
} | ||
|
||
&__indicators { | ||
align-items: center; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 10px; | ||
justify-content: center; | ||
margin-top: 10px; | ||
opacity: var(--indicators-opacity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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 ( | ||
<a | ||
className={bn} | ||
href={image.url} | ||
style={{ '--index': index } as React.CSSProperties} | ||
> | ||
<img className={`${bn}__image`} src={image.image_url} /> | ||
</a> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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