Skip to content

Commit

Permalink
Merge pull request #121 from TheSecretOrganization/53-update-client-t…
Browse files Browse the repository at this point in the history
…itle-with-response-data

53 update client title with response data
  • Loading branch information
croueAlec authored Sep 20, 2024
2 parents 58aa906 + 8f7f56d commit 859ab33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
6 changes: 3 additions & 3 deletions django/src/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def create_response(

@require_GET
def index(request):
return create_response(request, 'index.html')
return create_response(request, 'index.html', title="Home")

@require_GET
def games(request):
return create_response(request, 'games.html')
return create_response(request, 'games.html', title='Games')

@require_GET
def login(request: HttpRequest):
Expand All @@ -39,4 +39,4 @@ def register(request: HttpRequest):

@require_GET
def error_404(request):
return create_response(request, '404.html')
return create_response(request, '404.html', title="Page not found")
14 changes: 3 additions & 11 deletions nginx/src/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ async function fetchPage(pageName) {
console.error(`Failed to fetch ${pageName}: ${data.error}`);
return null;
}

document.title = ('title' in data) ? data.title : "Missing title";

return data.html;
}

Expand All @@ -42,16 +45,6 @@ function loadScripts() {
});
}

function updateTitle(pageName) {
const titles = {
"index": "Home",
"games": "Games",
"404": "Page Not Found"
};
const title = titles[pageName] || "Page Not Found";
document.title = title;
}

function updateActiveRoute(path) {
const activeRoute = document.querySelector(`a[href="${path}"]`);
if (activeRoute) {
Expand All @@ -69,7 +62,6 @@ async function handleLocation() {

document.getElementById("content").innerHTML = html;
loadScripts();
updateTitle(pageName);
updateActiveRoute(path);
}

Expand Down

0 comments on commit 859ab33

Please sign in to comment.