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 17 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
6 changes: 6 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\BeatmapDownload;
use App\Models\Beatmapset;
use App\Models\Forum\Post;
use App\Models\NewsAnnouncement;
use App\Models\NewsPost;
use App\Models\UserDonation;
use Auth;
Expand Down Expand Up @@ -99,11 +100,16 @@ public function index()

if (Auth::check()) {
$newBeatmapsets = Beatmapset::latestRanked();
$newsAnnouncements = json_collection(
NewsAnnouncement::default()->get(),
'NewsAnnouncement',
);
$popularBeatmapsets = Beatmapset::popular()->get();

return ext_view('home.user', compact(
'newBeatmapsets',
'news',
'newsAnnouncements',
'popularBeatmapsets'
));
} else {
Expand Down
72 changes: 72 additions & 0 deletions app/Models/NewsAnnouncement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;

/**
* @property-read string|null $content_html
* @property string|null $content_markdown
* @property Carbon|null $ended_at
* @property-read string|null $ended_at_json
* @property int $id
* @property string $image_url
* @property int $order
* @property Carbon $started_at
* @property-read string $started_at_json
* @property string $url
* @method static Builder default()
*/
class NewsAnnouncement extends Model
cl8n marked this conversation as resolved.
Show resolved Hide resolved
{
public $incrementing = false;
public $timestamps = false;

protected $dates = ['ended_at', 'started_at'];

public function scopeDefault(Builder $query): void
{
$now = Carbon::now();

$query
->where('started_at', '<=', $now)
->where(function (Builder $query) use ($now) {
$query
->where('ended_at', '>', $now)
->orWhereNull('ended_at');
})
->orderBy('order');
}

public function getAttribute($key)
{
return match ($key) {
'content_markdown',
'id',
'image_url',
'order',
'url' => $this->getRawAttribute($key),

'ended_at',
'started_at' => $this->getTimeFast($key),

'ended_at_json',
'started_at_json' => $this->getJsonTimeFast($key),

'content_html' => $this->getContentHtml(),
};
}

private function getContentHtml(): ?string
{
return $this->content_markdown === null
? null
: markdown($this->content_markdown);
}
}
29 changes: 29 additions & 0 deletions app/Transformers/NewsAnnouncementTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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;

use App\Models\NewsAnnouncement;

class NewsAnnouncementTransformer extends TransformerAbstract
{
public function transform(NewsAnnouncement $newsAnnouncement): array
{
return [
'content' => $newsAnnouncement->content_markdown === null ? null : [
'html' => $newsAnnouncement->content_html,
'markdown' => $newsAnnouncement->content_markdown,
],
'ended_at' => $newsAnnouncement->ended_at_json,
'id' => $newsAnnouncement->getKey(),
'image_url' => $newsAnnouncement->image_url,
'order' => $newsAnnouncement->order,
'started_at' => $newsAnnouncement->started_at_json,
'url' => $newsAnnouncement->url,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('news_announcements', function (Blueprint $table): void {
$table->mediumIncrements('id');
$table->text('content_markdown')->nullable();
$table->timestamp('ended_at')->nullable();
$table->string('image_url');
$table->tinyInteger('order');
$table->timestamp('started_at')->useCurrent();
$table->string('url');
cl8n marked this conversation as resolved.
Show resolved Hide resolved
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('news_announcements');
}
};
2 changes: 2 additions & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
@import "bem/navbar-mobile";
@import "bem/navbar-mobile-before";
@import "bem/navbar-mobile-item";
@import "bem/news-announcement";
@import "bem/news-announcements";
@import "bem/news-card";
@import "bem/news-index";
@import "bem/news-post-preview";
Expand Down
31 changes: 31 additions & 0 deletions resources/css/bem/news-announcement.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.

.news-announcement {
height: 100%;
left: calc(100% * var(--index, 0));
overflow-x: hidden;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
width: 100%;

&__content {
background: hsla(var(--hsl-b4), 0.7);
bottom: 0;
padding: 10px;
position: absolute;
text-align: center;
width: 100%;
}

&__image {
height: 100%;
left: 50%;
position: absolute;
transform: translateX(-50%);
cl8n marked this conversation as resolved.
Show resolved Hide resolved
}

&__link {
display: block;
height: 100%;
}
}
76 changes: 76 additions & 0 deletions resources/css/bem/news-announcements.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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.

.news-announcements {
margin-top: 20px;
overflow-x: hidden;
position: relative;

&__button {
.reset-input();
bottom: 0;
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);
}
}

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

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

&__indicator {
align-items: center;
display: flex;
height: 6px;

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

&--active::before {
height: 6px;
opacity: 1;
}
}

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

&__news-announcements-placeholder {
align-items: center;
display: flex;
height: 250px; // news-announcements__container height
justify-content: center;
margin-top: 20px; // news-announcements 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:
10px /* news-announcements__indicators margin */ +
6px /* news-announcements__indicator height */;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
}
}

&__news-posts-group {
.default-box-shadow();
display: block;
Expand Down
Loading