Add dropdown to switch between add site and subscribe in same input box
This commit is contained in:
parent
80a1d44dee
commit
a3429409eb
1 changed files with 22 additions and 2 deletions
24
handlers.py
24
handlers.py
|
|
@ -338,12 +338,29 @@ def handle_search(query):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def handle_add_form(msg=""):
|
def handle_add_form(msg="", action_type="index"):
|
||||||
|
if action_type == "subscribe":
|
||||||
|
return _respond(
|
||||||
|
f"<h1>subscribe</h1>"
|
||||||
|
f"<p>Subscribe to a friend's TinyWeb instance to sync their index</p>"
|
||||||
|
f'<form method="post" action="/subscriptions/add">'
|
||||||
|
f'{_csrf_field()}'
|
||||||
|
f'<input name="dest_hash" placeholder="destination hash (32 hex chars)" size="50"><br><br>'
|
||||||
|
f'<button type="submit">subscribe</button>'
|
||||||
|
f"</form>"
|
||||||
|
f"<p><small>or <a href=\"/add\">add a single site</a></small></p>"
|
||||||
|
f"<p>{msg}</p>"
|
||||||
|
f'<a href="/">back</a>'
|
||||||
|
)
|
||||||
return _respond(
|
return _respond(
|
||||||
f"<h1>add url</h1>"
|
f"<h1>add url</h1>"
|
||||||
f"<p>Add a site via URL or Reticulum destination hash</p>"
|
f"<p>Add a site via URL or Reticulum destination hash</p>"
|
||||||
f'<form method="post" action="/add">'
|
f'<form method="post" action="/add">'
|
||||||
f'{_csrf_field()}'
|
f'{_csrf_field()}'
|
||||||
|
f'<select name="action_type" onchange="this.form.action = this.value === \'subscribe\' ? \'/subscriptions/add\' : \'/add\'">'
|
||||||
|
f'<option value="/add" selected>Add site (index)</option>'
|
||||||
|
f'<option value="/subscriptions/add">Subscribe to instance</option>'
|
||||||
|
f'</select><br><br>'
|
||||||
f'<input name="url" placeholder="https://example.com" size="50"><br>'
|
f'<input name="url" placeholder="https://example.com" size="50"><br>'
|
||||||
f'<small>or</small><br>'
|
f'<small>or</small><br>'
|
||||||
f'<input name="reticulum_dest" placeholder="reticulum destination hash (32 hex chars)" size="50"><br><br>'
|
f'<input name="reticulum_dest" placeholder="reticulum destination hash (32 hex chars)" size="50"><br><br>'
|
||||||
|
|
@ -351,6 +368,7 @@ def handle_add_form(msg=""):
|
||||||
f'<input name="tags" placeholder="tags (comma-separated, e.g. solarpunk, mesh)" size="50"><br><br>'
|
f'<input name="tags" placeholder="tags (comma-separated, e.g. solarpunk, mesh)" size="50"><br><br>'
|
||||||
f'<button type="submit">index</button>'
|
f'<button type="submit">index</button>'
|
||||||
f"</form>"
|
f"</form>"
|
||||||
|
f"<p><small>or <a href=\"/subscriptions\">manage subscriptions</a></small></p>"
|
||||||
f"<p>{msg}</p>"
|
f"<p>{msg}</p>"
|
||||||
f'<a href="/">back</a>'
|
f'<a href="/">back</a>'
|
||||||
)
|
)
|
||||||
|
|
@ -901,6 +919,7 @@ def handle_subscriptions(msg=""):
|
||||||
f'<input name="dest_hash" placeholder="destination hash" size="40"> '
|
f'<input name="dest_hash" placeholder="destination hash" size="40"> '
|
||||||
f'<button>subscribe</button>'
|
f'<button>subscribe</button>'
|
||||||
f'</form>'
|
f'</form>'
|
||||||
|
f'<p><small>or <a href="/add?type=subscribe">subscribe to an instance</a></small></p>'
|
||||||
f'<p>{msg}</p>'
|
f'<p>{msg}</p>'
|
||||||
f'<hr>{listing}'
|
f'<hr>{listing}'
|
||||||
f'<br><a href="/">back</a>'
|
f'<br><a href="/">back</a>'
|
||||||
|
|
@ -1266,7 +1285,8 @@ def _dispatch_inner(data):
|
||||||
if path == "/":
|
if path == "/":
|
||||||
return handle_search(query)
|
return handle_search(query)
|
||||||
elif path == "/add":
|
elif path == "/add":
|
||||||
return handle_add_form()
|
action_type = query.get("type", ["index"])[0]
|
||||||
|
return handle_add_form(action_type=action_type if action_type == "subscribe" else "index")
|
||||||
elif path == "/pages":
|
elif path == "/pages":
|
||||||
return handle_pages(query)
|
return handle_pages(query)
|
||||||
elif path.startswith("/edit/"):
|
elif path.startswith("/edit/"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue