Make dark theme a user level property, lazy load dark CSS

- Also now respects the colour-scheme media query
- Added meta tag to tell the browser we support dark theme, allowing dark UA stylesheet if the user sends said media query
- Means you only have to set it once per account rather than once per machine
- Dark themed embeds!
This commit is contained in:
2021-02-06 16:40:22 +00:00
parent 0598612c15
commit 4f912932ca
13 changed files with 90 additions and 71 deletions

View File

@@ -3,22 +3,17 @@
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Hi {{ user.first_name }}
</a>
<ul class="dropdown-menu p-3 clearfix" id="userdropdown">
<ul class="dropdown-menu clearfix" id="userdropdown">
<li class="media">
<a href="{% url 'profile_detail' %}">
<img src="{{ request.user.profile_picture }}" class="media-object"/>
<img src="{{ request.user.profile_picture }}" class="media-object float-left pr-2"/>
<div class="media-body">
<b>{{ request.user.first_name }} {{ request.user.last_name }}</b>
<p class="muted">{{ request.user.email }}</p>
<b>{{ request.user.first_name }} {{ request.user.last_name }}</b>
<p class="text-muted">{{ request.user.email }}</p>
</div>
</a>
</li>
<li class="mb-2">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="darkSwitch" />
<label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
</li>
<div class="dropdown-divider"></div>
<li class="float-right"><a href="{% url 'logout' %}" class="btn btn-primary"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
{% else %}

View File

@@ -5,47 +5,47 @@
{% block content %}
<div class="row">
<div class="col">
<div class="col-md-6 offset-md-3">
{% include 'form_errors.html' %}
<h3>Update Profile {{object.name}}</h3>
<div class="row">
<div class="col-md-6">
<form action="{{form.action|default:request.path}}" method="post">{% csrf_token %}
<div class="form-group">
{% include 'partials/form_field.html' with field=form.first_name %}
</div>
<div class="form-group">
{% include 'partials/form_field.html' with field=form.last_name %}
</div>
<div class="form-group">
<label for="{{form.email.id_for_label}}" class="col-form-label">{{form.email.label}}</label>
{% render_field form.email type="email" class+="form-control" placeholder=form.email.label %}
</div>
<div class="form-group">
{% include 'partials/form_field.html' with field=form.initials %}
</div>
<div class="form-group">
<label for="{{form.phone.id_for_label}}" class="col-form-label">{{form.phone.label}}</label>
{% render_field form.phone type="tel" class+="form-control" placeholder=form.phone.label %}
</div>
<div class="form-group">
<input class="btn btn-primary float-right" type="submit"/>
</div>
</form>
</div>
<div class="col">
<a href="https://gravatar.com/">
<img src="{{object.profile_picture}}" class="img-fluid rounded" />
<div class="text-center">
Images hosted by Gravatar
</div>
</a>
</div>
<div class="col-md-6">
<a href="https://gravatar.com/">
<img src="{{object.profile_picture}}" class="img-fluid rounded" />
<div class="text-center">
Images hosted by Gravatar
</div>
</a>
</div>
<div class="col-md-6">
<form action="{{form.action|default:request.path}}" method="post">{% csrf_token %}
<div class="form-group">
{% include 'partials/form_field.html' with field=form.first_name %}
</div>
<div class="form-group">
{% include 'partials/form_field.html' with field=form.last_name %}
</div>
<div class="form-group">
<label for="{{form.email.id_for_label}}" class="col-form-label">{{form.email.label}}</label>
{% render_field form.email type="email" class+="form-control" placeholder=form.email.label %}
</div>
<div class="form-group">
{% include 'partials/form_field.html' with field=form.initials %}
</div>
<div class="form-group">
<label for="{{form.phone.id_for_label}}" class="col-form-label">{{form.phone.label}}</label>
{% render_field form.phone type="tel" class+="form-control" placeholder=form.phone.label %}
</div>
<div class="form-group">
<label for="{{ form.dark_theme.id_for_label }}">Enable Dark Theme?</label>
{% render_field form.dark_theme %}
</div>
<div class="form-group">
<input class="btn btn-primary float-right" type="submit"/>
</div>
</form>
</div>
</div>
</div>
</div>
</div>