feat: position filter

This commit is contained in:
Rico van Zelst
2023-11-08 21:40:51 +01:00
parent c7eae5d41a
commit 00018878e0
5 changed files with 68 additions and 8 deletions

View File

@@ -51,9 +51,13 @@ class ChampionController extends Controller
return $champion->load('skins', 'lanes'); return $champion->load('skins', 'lanes');
}); });
$splashColor = Cache::remember('championSplashColorCache' . $champion->slug, 60 * 60 * 24, function () use ($champion) { $splashColor = Cache::remember(
return getAverageColorFromImageUrl($champion->getChampionImageAttribute()); 'championSplashColorCache' . $champion->slug,
}); 60 * 60 * 24,
function () use ($champion) {
return getAverageColorFromImageUrl($champion->getChampionImageAttribute());
}
);
$champion->splash_color = $splashColor; $champion->splash_color = $splashColor;

View File

@@ -0,0 +1,35 @@
document.addEventListener('DOMContentLoaded', function () {
const laneFilters = document.querySelectorAll('.lane-filter');
const championDivs = document.querySelectorAll('.champ-card');
laneFilters.forEach((filter) => {
filter.addEventListener('click', function () {
const selectedLane = filter.getAttribute('data-lane');
if (filter.classList.contains('opacity-100')) {
// If the filter is already active, unselect it and show all
championDivs.forEach((championDiv) => {
championDiv.style.display = 'block';
});
filter.classList.remove('opacity-100');
filter.classList.add('opacity-40');
} else {
// If the filter is not active, activate it and filter champions
laneFilters.forEach((otherFilter) => {
otherFilter.classList.remove('opacity-100');
otherFilter.classList.add('opacity-40');
});
filter.classList.remove('opacity-40');
filter.classList.add('opacity-100');
championDivs.forEach((championDiv) => {
if (selectedLane === 'All' || championDiv.classList.contains('POS-' + selectedLane)) {
championDiv.style.display = 'block';
} else {
championDiv.style.display = 'none';
}
});
}
});
});
});

View File

@@ -42,6 +42,7 @@
@vite('resources/css/app.css') @vite('resources/css/app.css')
@vite('resources/js/app.js') @vite('resources/js/app.js')
@vite('resources/js/lane-filter.js')
</head> </head>
<body class="antialiased bg-stone-900 dark scroll-smooth"> <body class="antialiased bg-stone-900 dark scroll-smooth">

View File

@@ -0,0 +1,19 @@
<div class="lane-selector">
<div class="flex mt-2">
<div class="cursor-pointer mr-4 lane-icon lane-filter opacity-40 hover:opacity-70" data-lane="Toplane">
<x-icon-position-top class="text-orange-400"/>
</div>
<div class="cursor-pointer mr-4 lane-icon lane-filter opacity-40 hover:opacity-70" data-lane="Jungle">
<x-icon-position-jungle class="text-orange-400"/>
</div>
<div class="cursor-pointer mr-4 lane-icon lane-filter opacity-40 hover:opacity-70" data-lane="Midlane">
<x-icon-position-middle class="text-orange-400"/>
</div>
<div class="cursor-pointer mr-4 lane-icon lane-filter opacity-40 hover:opacity-70" data-lane="Botlane">
<x-icon-position-bottom class="text-orange-400"/>
</div>
<div class="cursor-pointer lane-icon lane-filter opacity-40 hover:opacity-70" data-lane="Support">
<x-icon-position-utility class="text-orange-400"/>
</div>
</div>
</div>

View File

@@ -3,21 +3,22 @@
/** @var App\Models\ChampionRole $roles */ /** @var App\Models\ChampionRole $roles */
?> ?>
<section class="max-w-screen-xl mx-auto mt-12"> <section class="max-w-screen-xl mx-auto mt-12">
<h2 <h2
class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text"> bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
Champions</h2> Champions</h2>
<div class="flex justify-center items-center mx-auto max-w-screen-xl mt-2.5">
<x-champions.lane-selector class="text-center"/>
</div>
<div class="container mx-auto p-4 flex items-center justify-center mt-3"> <div class="container mx-auto p-4 flex items-center justify-center mt-3">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-12 "> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-12 ">
@foreach($champions as $key => $champion) @foreach($champions as $key => $champion)
<div <div
class="flex flex-col text-gray-700 bg-stone-800/40 shadow-md rounded-2xl bg-clip-border class="champ-card flex flex-col text-gray-700 bg-stone-800/40 shadow-md rounded-2xl bg-clip-border
border border-stone-800 hover:border-orange-500/10 hover:shadow-orange-500/10"> border border-stone-800 hover:border-orange-500/10 hover:shadow-orange-500/10 @foreach($roles[$key]->roles as $lane)POS-{{$lane}}@endforeach">
<div <div
class="mx-4 mt-4 overflow-hidden h-52 rounded-2xl bg-clip-border border-2 border-orange-400/40"> class="mx-4 mt-4 overflow-hidden h-52 rounded-2xl bg-clip-border border-2 border-orange-400/40">
<img @if($key < 8) loading="eager" @else loading="lazy" @endif <img @if($key < 8) loading="eager" @else loading="lazy" @endif