2026-04-21 11:30:07 +02:00
|
|
|
/**
|
|
|
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-12 20:03:20 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { createRoot } from 'react-dom/client';
|
2026-04-21 11:30:07 +02:00
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
|
import { AvatarUpload, BattleDialog, ProfileCharts } from '@global-components';
|
|
|
|
|
|
|
|
|
|
const queryClient = new QueryClient();
|
2026-04-13 15:50:28 +02:00
|
|
|
|
|
|
|
|
const avatarRoot = document.getElementById('profile-avatar-root');
|
|
|
|
|
if (avatarRoot) {
|
|
|
|
|
const { uploadUrl, thumbUrl, initials } = avatarRoot.dataset;
|
|
|
|
|
createRoot(avatarRoot).render(
|
2026-04-21 11:30:07 +02:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<AvatarUpload
|
|
|
|
|
uploadUrl={uploadUrl}
|
|
|
|
|
initialThumbUrl={thumbUrl || null}
|
|
|
|
|
initials={initials}
|
|
|
|
|
/>
|
|
|
|
|
</QueryClientProvider>,
|
2026-04-13 15:50:28 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-04-12 20:03:20 +02:00
|
|
|
|
|
|
|
|
const chartsRoot = document.getElementById('profile-charts-root');
|
|
|
|
|
if (chartsRoot) {
|
|
|
|
|
createRoot(chartsRoot).render(
|
|
|
|
|
<ProfileCharts chartData={JSON.parse(chartsRoot.dataset.chartData)} />,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const battleRoot = document.getElementById('profile-battle-root');
|
|
|
|
|
if (battleRoot) {
|
|
|
|
|
createRoot(battleRoot).render(
|
|
|
|
|
<BattleDialog games={JSON.parse(battleRoot.dataset.games)} />,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-19 22:11:58 +02:00
|
|
|
|
|
|
|
|
const list = document.querySelector('.profile-games');
|
|
|
|
|
const loadMoreBtn = document.querySelector('[data-load-more]');
|
|
|
|
|
if (list && loadMoreBtn) {
|
|
|
|
|
const batchSize = parseInt(list.dataset.batchSize, 10) || 5;
|
|
|
|
|
loadMoreBtn.addEventListener('click', () => {
|
|
|
|
|
const hidden = list.querySelectorAll('.profile-game--hidden');
|
2026-04-21 11:30:07 +02:00
|
|
|
Array.from(hidden).slice(0, batchSize).forEach(el => el.classList.remove('profile-game--hidden'));
|
|
|
|
|
if (0 === list.querySelectorAll('.profile-game--hidden').length) {
|
2026-04-19 22:11:58 +02:00
|
|
|
loadMoreBtn.remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filterInput = document.querySelector('[data-filter]');
|
|
|
|
|
if (list && filterInput) {
|
|
|
|
|
filterInput.addEventListener('input', () => {
|
|
|
|
|
const term = filterInput.value.trim().toLowerCase();
|
2026-04-21 11:30:07 +02:00
|
|
|
list.classList.toggle('is-filtering', 0 < term.length);
|
|
|
|
|
list.querySelectorAll('.profile-game').forEach(card => {
|
2026-04-19 22:11:58 +02:00
|
|
|
const opp = card.querySelector('.profile-game__opponent')?.textContent.trim().toLowerCase() ?? '';
|
2026-04-21 11:30:07 +02:00
|
|
|
card.classList.toggle('profile-game--filtered-out', 0 < term.length && !opp.includes(term));
|
2026-04-19 22:11:58 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|