summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Portti <mportti2@local>2023-11-16 00:29:31 +0200
committerMikko Portti <mportti2@local>2023-11-16 00:29:31 +0200
commit93a927b130ba09cea29aba2077848f785ac48844 (patch)
tree05c7ae4b7df861e1efd03637c9f0cb6c45787d4b
parent92b368c3486fd20e550a2ec7b8e7717f7e061c96 (diff)
Fixing navigation on site in case of redirect
-rw-r--r--SCHEMA.sql (renamed from TABLES)0
-rw-r--r--nick.py2
-rw-r--r--routes.py12
-rw-r--r--static/menu.js18
-rw-r--r--static/pages.json5
5 files changed, 25 insertions, 12 deletions
diff --git a/TABLES b/SCHEMA.sql
index 1c5c372..1c5c372 100644
--- a/TABLES
+++ b/SCHEMA.sql
diff --git a/nick.py b/nick.py
index 438dc8e..f476d29 100644
--- a/nick.py
+++ b/nick.py
@@ -16,7 +16,7 @@ def new_nick():
session["id"] = D.user_new(nick)
return redirect("/")
session["alert"]="Nick in not created: "+msg
- return redirect("/#create")
+ return redirect("/#nick")
def invalid_nick(nick):
diff --git a/routes.py b/routes.py
index fde054f..b38cf3c 100644
--- a/routes.py
+++ b/routes.py
@@ -7,8 +7,6 @@ def get_alert():
del session["alert"]
return f"{alert}"
return ""
-
-
@app.route("/")
def index():
@@ -21,21 +19,25 @@ def info():
@app.route("/pages/create.html")
def create():
if "id" not in session:
- return render_template("nick.html", alert=get_alert() )
+ return "redirect = #nick"
return render_template("create.html", alert=get_alert() )
@app.route("/pages/answer.html")
def answer():
if "id" not in session:
- return render_template("nick.html", alert=get_alert() )
+ return "redirect = #nick"
return render_template("answer.html", alert=get_alert() )
@app.route("/pages/analyse.html")
def analyse():
if "id" not in session:
- return render_template("nick.html", alert=get_alert() )
+ return "redirect = #nick"
return render_template("analyse.html", alert=get_alert() )
@app.route("/pages/moderate.html")
def moderate():
return render_template("moderate.html", alert=get_alert() )
+
+@app.route("/pages/nick.html")
+def nick():
+ return render_template("nick.html", alert=get_alert() )
diff --git a/static/menu.js b/static/menu.js
index a014793..ee8f977 100644
--- a/static/menu.js
+++ b/static/menu.js
@@ -76,7 +76,7 @@ createMenu = () => {
menuNav.className = 'menuHidden'
Object.keys(pages).forEach(p => {
-
+
const entryDiv = document.createElement('div')
entryDiv.className = 'menuItem'
entryDiv.id = `${p}_menuEntry`
@@ -92,6 +92,8 @@ createMenu = () => {
name === "" ? ' menuSpacer' : ' menuTitle'
else entryDiv.onclick = () => window.location.hash = p;
+ if ( pages[p].hidden ) entryDiv.style.display = 'none';
+
menuNav.append( entryDiv )
})
document.documentElement.lastChild.append( menuNav )
@@ -114,7 +116,7 @@ toggleMenu = () => {
if (menuNav.className === '') window.scrollTo(0,0)
}
-hashToPage = () => {
+hashToPage = async () => {
const p = !document.location.hash
? Object.keys(pages)[0] : document.location.hash.substr(1) in pages
? document.location.hash.substr(1) : Object.keys(pages)[0]
@@ -130,15 +132,19 @@ hashToPage = () => {
else document.getElementById(`${currentPage}_page`).className = 'page'
pageElement.className = 'page pageActive'
- if ( !pageElement.loaded ) fetch( pages[p].URL )
+ if ( !pageElement.loaded ) await fetch( pages[p].URL )
.then( response => {
if (!response.ok) return `ERROR loading "${pages[p].URL}"!`
return response.text()
} )
.then( text => {
- pageElement.innerHTML = text
- pageElement.loaded = true
- } )
+ pageElement.innerHTML = text;
+ pageElement.loaded = true;
+ } )
+ if ( pageElement.innerHTML.startsWith("redirect = ") ) {
+ pageElement.loaded = false;
+ window.location.assign( pageElement.innerHTML.slice( 11 ) );
+ }
document.getElementById(`${currentPage}_menuEntry`)
.className = 'menuItem'
document.getElementById(`${p}_menuEntry`)
diff --git a/static/pages.json b/static/pages.json
index 4935c1d..4a18ca9 100644
--- a/static/pages.json
+++ b/static/pages.json
@@ -27,6 +27,11 @@
"pageTitle": "Moderoi sivustoa",
"URL": "pages/moderate.html",
"menuName": "Moderoi"
+ },
+ "nick": {
+ "pageTitle": "Anna nimimerkki",
+ "URL": "pages/nick.html",
+ "hidden": "yes"
}
}
}