speakmore-2.0/templates/settings.html
Olai 0ac1f2795b Added profile pictures
Added profile pictures and fixed some bugs
2024-06-24 23:06:46 +02:00

84 lines
4.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Settings</title>
{% include 'head.html' %}
</head>
<body class="login-body">
<div class="login-div !h-[465px]">
<form class="login-form" id="settings-form">
<img class="login-img" src="{{ url_for('static', filename='images/ms-style-logo.svg') }}" alt="Image">
<h2 class="login-h2">Settings</h2>
<div class="login-input-div-first">
<label for="theme" class="login-label">Select Theme:</label>
<select class="login-input" id="theme" name="theme">
<option value="automatic" {% if current_theme == 'automatic' %}selected{% endif %}>Automatic</option>
<option value="light" {% if current_theme == 'light' %}selected{% endif %}>Light</option>
<option value="dark" {% if current_theme == 'dark' %}selected{% endif %}>Dark</option>
</select>
</div>
<div class="login-input-div-first items-end">
<button class="ms-button-signin" type="submit" class="btn btn-primary">Save Settings</button>
</div>
</form>
<form class="login-form" id="upload-profile-picture-form" action="{{ url_for('upload_profile_picture') }}" method="POST" enctype="multipart/form-data">
<h2 class="login-h2">Upload Profile Picture</h2>
<div class="login-input-div-first">
<label for="profile_picture" class="login-label">Choose a profile picture:</label>
<input class="login-input" type="file" name="profile_picture" id="profile_picture" accept=".png, .jpg, .jpeg, .gif, .webp">
</div>
<div class="login-input-div-first items-end">
<button class="ms-button-signin" type="submit" class="btn btn-primary">Upload</button>
</div>
<div class="login-input-div-first !flex-row">
<a class="no-account no-account-button" href="{{ url_for('dashboard') }}"> Go Back</a>
</div>
</form>
<div id="message" class="mt-3"></div>
</div>
<script>
// Function to apply the theme based on user selection or system preference
function applyTheme(theme) {
const root = document.documentElement;
if (theme === 'dark' || (theme === 'automatic' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
root.classList.add('dark');
} else {
root.classList.remove('dark');
}
}
// Apply the theme on page load based on the current theme setting
document.addEventListener('DOMContentLoaded', (event) => {
const currentTheme = localStorage.getItem('theme') || 'automatic';
document.getElementById('theme').value = currentTheme;
applyTheme(currentTheme);
// Listen for changes to the system theme and apply if the user selected 'automatic'
if (currentTheme === 'automatic') {
window.matchMedia('(prefers-color-scheme: dark)').addListener(e => {
applyTheme('automatic');
});
}
});
// Save the theme setting to local storage and apply it
document.querySelector('#settings-form').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
const selectedTheme = formData.get('theme');
localStorage.setItem('theme', selectedTheme);
applyTheme(selectedTheme);
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = '<div class="alert alert-success">Settings saved successfully!</div>';
});
// Handle the profile picture upload
document.querySelector('#upload-profile-picture-form').addEventListener('submit', function(event) {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = ''; // Clear any previous messages
});
</script>
</body>
</html>