Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions assets/js/Common/HttpClient.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
class HttpClient {
constructor() {
this.onError = (response) => {
};
this.onError = () => true;
}

/**
* @param {String} url
* @returns {Promise}
*/
async get(url) {
const response = await fetch(url, {
headers: {'X-Requested-With': 'XMLHttpRequest'}
});
const response = await fetch(url);
const json = await response.json();

if (response.status >= 200 && response.status < 300) return json;
Expand All @@ -28,7 +25,6 @@ class HttpClient {
async post(url, data) {
const response = await fetch(url, {
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
body: new URLSearchParams(data)
});
const json = await response.json();
Expand Down
14 changes: 11 additions & 3 deletions assets/js/Common/NotificationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ customElements.define('notification-list', class extends HTMLElement {

this.insertBefore(messageNode, this.childNodes[0]);

await new Promise(resolve => setTimeout(resolve, timeout));
messageNode.addEventListener('animationend', () => this.removeChild(messageNode));
messageNode.classList.add('gp-fadeout');
let handle = this._scheduleRemoval(messageNode, timeout);

messageNode.addEventListener('mouseenter', () => clearTimeout(handle));
messageNode.addEventListener('mouseleave', () => handle = this._scheduleRemoval(messageNode, timeout));
}

_scheduleRemoval = (messageNode, timeout) => {
return setTimeout(() => {
messageNode.addEventListener('animationend', () => this.removeChild(messageNode));
messageNode.classList.add('gp-fadeout')
}, timeout);
}
});
8 changes: 8 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import '@tabler/core/dist/css/tabler.min.css'
import '@tabler/core/dist/js/tabler.min.js'
import '../css/app.css'

window.fetch = (fetch => async (resource, options = {}) => {
return fetch(
resource,
{...options, headers: {...(options.headers || {}), 'X-Requested-With': 'XMLHttpRequest'}}
);
})(window.fetch);

window.app = {
navigate: url => top.location.href = url,
loadElements: node => Promise.allSettled([...node.querySelectorAll(':not(:defined)')]
Expand All @@ -22,6 +29,7 @@ window.app = {
peInit() {
if (!window.pe) return window.addEventListener('pe:init', window.app.peInit);
window.app.navigate = window.pe.navigate;
window.pe.selectSource = window.pe.selectTarget = d => d.querySelector('[data-page-content]');
}
}

Expand Down
13 changes: 10 additions & 3 deletions assets/js/pe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function render(oldDocument, newDocument) {
oldDocument.title = newDocument.title || oldDocument.title;
oldDocument.body.replaceWith(newDocument.body);
[...oldDocument.body.getElementsByTagName('script')].forEach(n => {
const sourceNode = window.pe.selectSource(newDocument);
window.pe.selectTarget(oldDocument).replaceWith(sourceNode);
[...sourceNode.getElementsByTagName('script')].forEach(n => {
const s = oldDocument.createElement('script');
s.innerHTML = n.innerHTML;
[...n.attributes].forEach(a => s.setAttribute(a.nodeName, a.nodeValue));
Expand Down Expand Up @@ -96,7 +97,13 @@ async function submit(form) {
}
}

window.pe = {navigate: url => navigate(url, true), submit, abortController: new AbortController()};
window.pe = {
navigate: url => navigate(url, true),
submit,
abortController: new AbortController(),
selectSource: d => d.body,
selectTarget: d => d.body
};

window.addEventListener('popstate', () => navigate(top.location.href, false));
document.addEventListener('click', e => {
Expand Down
5 changes: 5 additions & 0 deletions config/web-interface/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ security:
- 'web-interface.security.arrival_authenticator'
logout:
path: /logout

when@dev:
services:
Gaming\WebInterface\Infrastructure\Symfony\ReplaceSymfonyToolbar:
tags: [{ name: kernel.event_listener, event: kernel.response }]
17 changes: 17 additions & 0 deletions src/WebInterface/Infrastructure/Symfony/ReplaceSymfonyToolbar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Gaming\WebInterface\Infrastructure\Symfony;

use Symfony\Component\HttpKernel\Event\ResponseEvent;

final class ReplaceSymfonyToolbar
{
public function onKernelResponse(ResponseEvent $event): void
{
if ($event->getRequest()->isXmlHttpRequest()) {
$event->getResponse()->headers->set('Symfony-Debug-Toolbar-Replace', '1');
}
}
}
2 changes: 1 addition & 1 deletion src/WebInterface/Presentation/Http/View/game.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@web-interface/layout/fluid.html.twig' %}
{% extends '@web-interface/layout/condensed.html.twig' %}

{% set page_title = 'Anonymous vs. Anonymous' %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script type="module" src="{{ asset('js/pe.js') }}"></script>
<script>window.matchMedia("(prefers-color-scheme:dark)").matches && document.documentElement.setAttribute('data-bs-theme', 'dark');</script>
</head>
<body class="{{ body_class is defined ? body_class : 'layout-fluid' }}">
<body>
<notification-list></notification-list>
{% block body %}{% endblock %}
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{% extends '@web-interface/layout/base.html.twig' %}

{% set body_class = 'd-flex flex-column' %}

{% block body %}
<div class="page page-center">
<div class="page page-center" data-page-content>
<div class="container container-tight">
<p class="text-center fw-medium my-5">
<a href="{{ path('lobby') }}" class="link-secondary navbar-brand-autodark text-decoration-none">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% extends '@web-interface/layout/base.html.twig' %}

{% block body %}
<div class="page">
<div class="page" data-page-content>
<header class="navbar navbar-expand d-print-none sticky-top">
<div class="container-xl">
<div class="container-xxl">
<div class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-lg-1">
<a href="{{ path('lobby') }}">
<img src="{{ asset('img/logo.png') }}"
Expand Down Expand Up @@ -99,13 +99,13 @@
</header>
<div class="page-wrapper">
<div class="page-body">
<div class="container">
<div class="container-xxl">
{% block content %}{% endblock %}
</div>
</div>
</div>
<footer class="footer footer-transparent d-print-none">
<div class="container-xl">
<div class="container-xxl">
<div class="row text-center align-items-center flex-row-reverse">
<div class="col-lg-auto ms-lg-auto">
<ul class="list-inline list-inline-dots mb-0">
Expand Down
2 changes: 1 addition & 1 deletion src/WebInterface/Presentation/Http/View/lobby.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@web-interface/layout/fluid.html.twig' %}
{% extends '@web-interface/layout/condensed.html.twig' %}

{% set page_title = 'Lobby' %}

Expand Down
2 changes: 1 addition & 1 deletion src/WebInterface/Presentation/Http/View/profile.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@web-interface/layout/fluid.html.twig' %}
{% extends '@web-interface/layout/condensed.html.twig' %}

{% set page_title = 'Profile' %}

Expand Down
Loading