Add dark mode for PWA frontend
Run Tests on Branches / Detect Changes (push) Successful in 12s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Successful in 1m47s
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped

This commit is contained in:
Antoni Nuñez Romeu
2026-07-09 13:18:25 +02:00
parent 2e9b2f2c1f
commit e9a1d7c53d
11 changed files with 289 additions and 33 deletions
+4 -4
View File
@@ -192,9 +192,9 @@
.home-card--scan {
/* Keep the scan button vivid and easy to find (intentionally prominent) */
background: #2b5bb5; /* vivid blue to stand out */
color: #ffffff;
box-shadow: 0 8px 28px rgba(43, 91, 181, 0.28);
background: var(--fab-bg);
color: var(--fab-text);
box-shadow: 0 8px 28px var(--fab-shadow);
transform: translateY(0);
}
@@ -204,7 +204,7 @@
.home-card--scan:focus {
outline: none;
box-shadow: 0 0 0 6px rgba(43,91,181,0.12), 0 8px 28px rgba(43,91,181,0.28);
box-shadow: 0 0 0 6px rgba(43,91,181,0.12), 0 8px 28px var(--fab-shadow);
}
.home-card-icon {
+60
View File
@@ -845,3 +845,63 @@
align-self: flex-end;
}
}
/* Theme Toggle */
.menu-item-theme-label {
font-size: 0.8rem;
font-weight: 500;
color: var(--on-surface-variant);
}
.profile-theme-options {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.profile-theme-btn {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.85rem 1rem;
background: var(--surface);
border: 2px solid var(--outline-variant);
border-radius: var(--radius);
cursor: pointer;
color: var(--on-surface-variant);
font-family: inherit;
text-align: left;
transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.profile-theme-btn:hover {
border-color: var(--primary);
color: var(--on-surface);
}
.profile-theme-btn--active {
border-color: var(--primary);
background: var(--primary-faint);
color: var(--primary);
}
.profile-theme-btn--active .profile-theme-btn-label {
color: var(--primary);
font-weight: 700;
}
.profile-theme-btn-label {
flex: 1;
font-size: 1rem;
font-weight: 600;
color: var(--on-surface);
}
.profile-theme-btn-desc {
font-size: 0.8rem;
color: var(--on-surface-variant);
}
.profile-modal-theme {
max-width: 24rem;
}
+57 -1
View File
@@ -34,7 +34,7 @@ function resolveAvatarUrl(url) {
return url;
}
function ProfileView({ currentUser, onProfileSaved, onLogout, onAdminClick }) {
function ProfileView({ currentUser, onProfileSaved, onLogout, onAdminClick, theme, onThemeChange }) {
const [firstName, setFirstName] = useState(currentUser?.first_name || '');
const [lastName, setLastName] = useState(currentUser?.last_name || '');
const [avatarUrl, setAvatarUrl] = useState(resolveAvatarUrl(currentUser?.avatar_url));
@@ -57,6 +57,9 @@ function ProfileView({ currentUser, onProfileSaved, onLogout, onAdminClick }) {
const [configSaving, setConfigSaving] = useState(false);
const [configFeedback, setConfigFeedback] = useState(null);
// Theme modal state
const [showTheme, setShowTheme] = useState(false);
// Addresses modal state
const [showAddresses, setShowAddresses] = useState(false);
const [addresses, setAddresses] = useState([]);
@@ -410,6 +413,21 @@ function ProfileView({ currentUser, onProfileSaved, onLogout, onAdminClick }) {
</svg>
</button>
<button className="profile-menu-item" onClick={() => setShowTheme(true)}>
<div className="menu-item-icon menu-item-icon--tertiary">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z" />
</svg>
</div>
<span className="menu-item-label">Tema</span>
<span className="menu-item-theme-label">
{theme === 'auto' ? 'Automático' : theme === 'light' ? 'Claro' : 'Oscuro'}
</span>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="menu-item-chevron">
<polyline points="9 18 15 12 9 6" />
</svg>
</button>
{searchHistory.length > 0 && (
<div className="profile-search-history">
<p className="profile-section-sub">Tus búsquedas recientes:</p>
@@ -718,6 +736,44 @@ function ProfileView({ currentUser, onProfileSaved, onLogout, onAdminClick }) {
</div>
</div>
)}
{/* Theme Modal */}
{showTheme && (
<div className="profile-modal-backdrop" onClick={() => setShowTheme(false)}>
<div className="profile-modal profile-modal-theme" onClick={(e) => e.stopPropagation()}>
<div className="profile-modal-header">
<h3>Tema de visualización</h3>
<button className="profile-modal-close" onClick={() => setShowTheme(false)}>×</button>
</div>
<div className="profile-modal-body">
<p className="profile-section-sub">Elige cómo se ve la aplicación. En modo automático, se adapta al tema de tu dispositivo.</p>
<div className="profile-theme-options">
{[
{ value: 'auto', label: 'Automático', desc: 'Seguir sistema', icon: 'M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z' },
{ value: 'light', label: 'Claro', desc: 'Siempre claro', icon: 'M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zM2 13h2c.55 0 1-.45 1-1s-.45-1-1-1H2c-.55 0-1 .45-1 1s.45 1 1 1zm18 0h2c.55 0 1-.45 1-1s-.45-1-1-1h-2c-.55 0-1 .45-1 1s.45 1 1 1zM11 2v2c0 .55.45 1 1 1s1-.45 1-1V2c0-.55-.45-1-1-1s-1 .45-1 1zm0 18v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zM5.99 4.58c-.39-.39-1.03-.39-1.42 0-.39.39-.39 1.03 0 1.42l1.06 1.06c.39.39 1.03.39 1.42 0s.39-1.03 0-1.42L5.99 4.58zm12.37 12.37c-.39-.39-1.03-.39-1.42 0-.39.39-.39 1.03 0 1.42l1.06 1.06c.39.39 1.03.39 1.42 0 .39-.39.39-1.03 0-1.42l-1.06-1.06zm1.06-10.96c.39-.39.39-1.03 0-1.42-.39-.39-1.03-.39-1.42 0l-1.06 1.06c-.39.39-.39 1.03 0 1.42s1.03.39 1.42 0l1.06-1.06zM7.05 18.36c.39-.39.39-1.03 0-1.42-.39-.39-1.03-.39-1.42 0l-1.06 1.06c-.39.39-.39 1.03 0 1.42s1.03.39 1.42 0l1.06-1.06z' },
{ value: 'dark', label: 'Oscuro', desc: 'Siempre oscuro', icon: 'M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z' },
].map(({ value, label, desc, icon }) => (
<button
key={value}
type="button"
className={`profile-theme-btn ${theme === value ? 'profile-theme-btn--active' : ''}`}
onClick={() => {
onThemeChange(value);
setShowTheme(false);
}}
>
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d={icon} />
</svg>
<span className="profile-theme-btn-label">{label}</span>
<span className="profile-theme-btn-desc">{desc}</span>
</button>
))}
</div>
</div>
</div>
</div>
)}
</div>
);
}
+15 -15
View File
@@ -58,35 +58,35 @@
}
.suggestion-btn--neutral-1 {
background: #ffffff;
color: #1e293b;
border: 1px solid #e2e8f0;
background: var(--suggestion-1);
color: var(--suggestion-text);
border: 1px solid var(--suggestion-border-1);
}
.suggestion-btn--neutral-2 {
background: #f0f7ff;
color: #1e293b;
border: 1px solid #dbeafe;
background: var(--suggestion-2);
color: var(--suggestion-text);
border: 1px solid var(--suggestion-border-2);
}
.suggestion-btn--neutral-3 {
background: #e0f0ff;
color: #1e293b;
border: 1px solid #bfdbfe;
background: var(--suggestion-3);
color: var(--suggestion-text);
border: 1px solid var(--suggestion-border-3);
}
.suggestion-btn--neutral-4 {
background: #d4ebff;
color: #1e293b;
border: 1px solid #93c5fd;
background: var(--suggestion-4);
color: var(--suggestion-text);
border: 1px solid var(--suggestion-border-4);
}
.suggestion-icon {
width: 2.5rem;
height: 2.5rem;
border-radius: var(--radius);
background: rgba(59, 130, 246, 0.08);
color: #3b82f6;
background: var(--suggestion-icon-bg);
color: var(--suggestion-icon-color);
display: flex;
align-items: center;
justify-content: center;
@@ -321,7 +321,7 @@
.retry-location-btn {
background: var(--error);
color: white;
color: var(--on-error);
border: none;
padding: 0.25rem 0.6rem;
border-radius: var(--radius);