Flesh out letter-adding.

Add new-letter button.
Refactor _formhelpers for increased modularity.
Re-style <select> tags
Invert logo colors on hover.
This commit is contained in:
Sage Vaillancourt 2022-09-29 16:35:26 +00:00
parent a5704c8c12
commit 04c16b50fe
4 changed files with 71 additions and 13 deletions

View File

@ -126,8 +126,12 @@ def logout() -> Response:
@writing_blueprint.route('/add_letter') @writing_blueprint.route('/add_letter')
def add_letter(user: db.User) -> Response: def add_letter() -> Response:
# TODO: Add new letter to db email_address = session.get('username')
if not email_address:
return render_index()
user = db.get_user(email_address)
existing_letter_count = len(db.get_user_letters(user.id)) existing_letter_count = len(db.get_user_letters(user.id))
new_letter_name = f'Letter{existing_letter_count + 2}' new_letter_name = f'Letter{existing_letter_count + 2}'
default_form_json = jsonify(CLForm().to_cl_data()).get_data(True) default_form_json = jsonify(CLForm().to_cl_data()).get_data(True)
@ -135,6 +139,7 @@ def add_letter(user: db.User) -> Response:
return redirect(f'/?letter_name={new_letter_name}') return redirect(f'/?letter_name={new_letter_name}')
@writing_blueprint.route('/', methods=['GET']) @writing_blueprint.route('/', methods=['GET'])
def index_get() -> Response: def index_get() -> Response:
email_address = session.get('username') email_address = session.get('username')

View File

@ -11,14 +11,30 @@ span.logo {
padding: 0.2em; padding: 0.2em;
} }
span.logo.left { h1 span.logo.left {
color: black; color: black;
background-color: white; background-color: white;
transition-property: color, background-color;
transition-duration: 300ms;
transition-timing-function: ease-in;
} }
span.logo.right { h1 span.logo.right {
color: white; color: white;
background-color: black; background-color: black;
transition-property: color, background-color;
transition-duration: 300ms;
transition-timing-function: ease-in;
}
h1:hover span.logo.left {
color: white;
background-color: black;
}
h1:hover span.logo.right {
color: black;
background-color: white;
} }
body { body {
@ -45,6 +61,11 @@ h2 {
margin-bottom: 1em; margin-bottom: 1em;
} }
.field {
display: flex;
flex-direction: column;
}
label { label {
font-size: 100%; font-size: 100%;
font-weight: bold; font-weight: bold;
@ -57,6 +78,14 @@ input, textarea {
font-family: sans-serif; font-family: sans-serif;
} }
select {
background-color: white;
border-radius: 0;
border-style: solid;
border-width: 1px;
border-color: #ccc;
}
.letter-form { .letter-form {
display: flex; display: flex;
flex-grow: 1; flex-grow: 1;
@ -98,7 +127,7 @@ div.user form input {
color: black; color: black;
background-color: white; background-color: white;
transition-property: color, background-color; transition-property: color, background-color;
transition-duration: 300ms; transition-duration: 135ms;
transition-timing-function: ease-in; transition-timing-function: ease-in;
} }
@ -114,7 +143,7 @@ div.user form input {
color: white; color: white;
background-color: black; background-color: black;
transition-property: color, background-color; transition-property: color, background-color;
transition-duration: 300ms; transition-duration: 135ms;
transition-timing-function: ease-in; transition-timing-function: ease-in;
} }
@ -224,8 +253,14 @@ textarea {
width: 100%; width: 100%;
} }
dd { dd {
margin-bottom: 2em;
margin-left: 0; margin-left: 0;
flex-grow: 1;
}
dd select {
flex-grow: 1;
}
.field {
margin-bottom: 2em;
} }
textarea { textarea {
width: 80vw; width: 80vw;

View File

@ -1,6 +1,8 @@
{% macro render_field(field, extra="") %} {% macro render_label(field) %}
<dt>{{ field.label }}</dt> <dt>{{ field.label }}</dt>
{% endmacro %}
{% macro render_input(field, extra="") %}
<dd {{extra}}> <dd {{extra}}>
{{ field(**kwargs)|safe }} {{ field(**kwargs)|safe }}
@ -13,3 +15,10 @@
{% endif %} {% endif %}
</dd> </dd>
{% endmacro %} {% endmacro %}
{% macro render_field(field, extra="") %}
<div class="field">
{{ render_label(field) }}
{{ render_input(field, extra, **kwargs) }}
</div>
{% endmacro %}

View File

@ -1,5 +1,5 @@
{% extends "base.jinja2" %} {% extends "base.jinja2" %}
{% from "_formhelpers.jinja2" import render_field %} {% from "_formhelpers.jinja2" import render_field, render_label, render_input %}
{% block title %}UnderCover{% endblock %} {% block title %}UnderCover{% endblock %}
@ -38,7 +38,7 @@
<div class="user logged-in"> <div class="user logged-in">
<p style="margin: 0 1em 0 0;">{{ username }}</p> <p style="margin: 0 1em 0 0;">{{ username }}</p>
<form action="/logout"> <form action="/logout">
<input class="black-white-button" style="margin: 0;" type="submit" value="Logout"> <input class="black-white-button" style="margin: 0; padding: 0.4em;" type="submit" value="Logout">
</form> </form>
</div> </div>
{% else %} {% else %}
@ -62,8 +62,17 @@
<form method=post id="letter-form"> <form method=post id="letter-form">
<dl> <dl>
{% if username %} {% if username %}
{{ render_field(form.letterName, onchange="window.location = '/?letter_name=' + this.options[this.value - 1].label") }} <div class="field">
<span style="background-color: green; color: white;">+</span> {{ render_label(form.letterName) }}
<div style="display: flex; flex-direction: row;">
{{ render_input(
form.letterName,
onchange="window.location = '/?letter_name=' + this.options[this.value - 1].label"
)
}}
<a href="/add_letter" class="black-white-button" style="aspect-ratio: 1 / 1; text-decoration: none; margin-left: 1em; text-align: center;">+</a>
</div>
</div>
{% endif %} {% endif %}
{{ render_field(form.username) }} {{ render_field(form.username) }}
{{ render_field(form.company) }} {{ render_field(form.company) }}