From fe46206547b56c0574a354771506339ce617719a Mon Sep 17 00:00:00 2001 From: MKM Date: Fri, 19 Apr 2024 21:21:35 +0300 Subject: [PATCH] =?UTF-8?q?F=C4=B0N=C4=B0SHED=20SEND=20REQUSETSDAS=C4=9EOK?= =?UTF-8?q?D=20AJS=C5=9ELD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Apps/Game/urls.py | 2 +- Backend/static/scripts/requests.js | 2 +- Backend/static/scripts/spa.js | 65 ++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Backend/Apps/Game/urls.py b/Backend/Apps/Game/urls.py index 925329e6..68e883b0 100644 --- a/Backend/Apps/Game/urls.py +++ b/Backend/Apps/Game/urls.py @@ -4,5 +4,5 @@ from . import views urlpatterns = [ - path('',views.index,name='index'), + path('/',views.index,name='index'), ] \ No newline at end of file diff --git a/Backend/static/scripts/requests.js b/Backend/static/scripts/requests.js index b59f09af..6dfadd92 100644 --- a/Backend/static/scripts/requests.js +++ b/Backend/static/scripts/requests.js @@ -66,7 +66,7 @@ async function handleGameAcceptedCallback(data) game_id: response.game_id, } socket.send(JSON.stringify(sendBody)); - console.log("redirected to game") + loadPage(`/game/${response.game_id}/`); } catch (error) { diff --git a/Backend/static/scripts/spa.js b/Backend/static/scripts/spa.js index fbf407b1..688f5a73 100644 --- a/Backend/static/scripts/spa.js +++ b/Backend/static/scripts/spa.js @@ -484,16 +484,51 @@ const routes = new Map([ auth_required: true, url: [/game\/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})/], html: ` -
-
- Player 1 -

Player 1  
Point: 2000                                                                                                               

-

Player 2  
Point: 2000

- Player 2 -
- -
+ ` }], ['error', { @@ -596,7 +631,6 @@ export function loadPage(fileName) { let data = findRouteFile(fileName); const route = routes.get(data); let isMatch = false; - if (Array.isArray(route.url)) { isMatch = route.url.some(url => { if (url instanceof RegExp) { @@ -610,9 +644,16 @@ export function loadPage(fileName) { } else { isMatch = window.location.pathname.includes(route.url); } - + let split = fileName.split('/').filter(Boolean); if (!isMatch) { - history.pushState({}, '', window.location.origin + route.url); + if(split.length > 1) + { + console.log("split",split) + history.pushState({}, '', window.location.origin + `/${split[0]}/${split[1]}/`); + } + else + history.pushState({}, '', window.location.origin + route.url); + } let content = document.getElementById('main'); content.innerHTML = route.html;