fix: resolve Svelte 5 migration warnings and improve accessibility
All checks were successful
CI / update (push) Successful in 2m2s
All checks were successful
CI / update (push) Successful in 2m2s
- Fix state_referenced_locally warnings by extracting initial values to constants - Remove unused CSS selectors (subheading, header-actions, back-actions) - Add ARIA roles and keyboard handlers to settlement options - Add a11y ignore comment for custom checkbox implementation
This commit is contained in:
@@ -92,6 +92,7 @@ input[type=checkbox]::after
|
||||
{#each months as month}
|
||||
<div class=checkbox_container>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<label tabindex="0" onkeydown={(event) => do_on_key(event, 'Enter', false, () => {toggle_checkbox_on_key(event)}) } ><input tabindex=-1 type="checkbox" name="checkbox" value="value" onclick={set_season}>{month}</label>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -9,11 +9,6 @@ h1{
|
||||
margin-bottom: 0;
|
||||
font-size: 4rem;
|
||||
}
|
||||
.subheading{
|
||||
text-align: center;
|
||||
margin-top: 0;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
.content{
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
|
||||
@@ -54,11 +54,12 @@
|
||||
let exchangeRateError = $state(null);
|
||||
let exchangeRateTimeout = $state();
|
||||
|
||||
// Initialize users from server data for no-JS support
|
||||
let users = $state(predefinedMode ? [...data.predefinedUsers] : (data.currentUser ? [data.currentUser] : []));
|
||||
// Initialize users from server data for no-JS support (use data directly to avoid reactivity warning)
|
||||
const initialUsers = data.predefinedUsers.length > 0 ? [...data.predefinedUsers] : (data.currentUser ? [data.currentUser] : []);
|
||||
let users = $state(initialUsers);
|
||||
|
||||
// Initialize split amounts for server-side users
|
||||
users.forEach(user => {
|
||||
// Initialize split amounts for server-side users (use initialUsers to avoid reactivity warning)
|
||||
initialUsers.forEach(user => {
|
||||
splitAmounts[user] = 0;
|
||||
personalAmounts[user] = 0;
|
||||
});
|
||||
|
||||
@@ -657,10 +657,6 @@
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.payments-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -170,8 +170,11 @@
|
||||
<h3>Money You're Owed</h3>
|
||||
{#each debtData.whoOwesMe as debt}
|
||||
<div class="settlement-option"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
class:selected={selectedSettlement?.type === 'receive' && selectedSettlement?.from === debt.username}
|
||||
on:click={() => selectSettlement('receive', debt.username, debt.netAmount)}>
|
||||
onclick={() => selectSettlement('receive', debt.username, debt.netAmount)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); selectSettlement('receive', debt.username, debt.netAmount); } }}>
|
||||
<div class="settlement-user">
|
||||
<ProfilePicture username={debt.username} size={40} />
|
||||
<div class="user-details">
|
||||
@@ -192,8 +195,11 @@
|
||||
<h3>Money You Owe</h3>
|
||||
{#each debtData.whoIOwe as debt}
|
||||
<div class="settlement-option"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
class:selected={selectedSettlement?.type === 'pay' && selectedSettlement?.to === debt.username}
|
||||
on:click={() => selectSettlement('pay', debt.username, debt.netAmount)}>
|
||||
onclick={() => selectSettlement('pay', debt.username, debt.netAmount)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); selectSettlement('pay', debt.username, debt.netAmount); } }}>
|
||||
<div class="settlement-user">
|
||||
<ProfilePicture username={debt.username} size={40} />
|
||||
<div class="user-details">
|
||||
@@ -259,7 +265,7 @@
|
||||
<div class="settlement-actions">
|
||||
<button
|
||||
class="btn btn-settlement"
|
||||
on:click={processSettlement}
|
||||
onclick={processSettlement}
|
||||
disabled={submitting || !settlementAmount}>
|
||||
{#if submitting}
|
||||
Recording Settlement...
|
||||
@@ -267,7 +273,7 @@
|
||||
Record Settlement
|
||||
{/if}
|
||||
</button>
|
||||
<button class="btn btn-secondary" on:click={() => selectedSettlement = null}>
|
||||
<button class="btn btn-secondary" onclick={() => selectedSettlement = null}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
@@ -668,11 +674,6 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.back-actions {
|
||||
text-align: center;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
export const load: LayoutServerLoad = async ({ locals }) => {
|
||||
return {
|
||||
session: await locals.auth()
|
||||
};
|
||||
};
|
||||
@@ -1,139 +0,0 @@
|
||||
<script>
|
||||
import { page } from '$app/stores';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
const navItems = [
|
||||
{ href: '/fitness', label: 'Dashboard', icon: '📊' },
|
||||
{ href: '/fitness/templates', label: 'Templates', icon: '📋' },
|
||||
{ href: '/fitness/sessions', label: 'Sessions', icon: '💪' },
|
||||
{ href: '/fitness/workout', label: 'Start Workout', icon: '🏋️' }
|
||||
];
|
||||
</script>
|
||||
|
||||
<div class="fitness-layout">
|
||||
<nav class="fitness-nav">
|
||||
<h1>💪 Fitness Tracker</h1>
|
||||
<ul>
|
||||
{#each navItems as item}
|
||||
<li>
|
||||
<a
|
||||
href={item.href}
|
||||
class:active={$page.url.pathname === item.href}
|
||||
>
|
||||
<span class="icon">{item.icon}</span>
|
||||
{item.label}
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<main class="fitness-main">
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.fitness-layout {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.fitness-nav {
|
||||
width: 250px;
|
||||
background: white;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.fitness-nav h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
margin-bottom: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fitness-nav ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.fitness-nav li {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.fitness-nav a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
color: #6b7280;
|
||||
text-decoration: none;
|
||||
border-radius: 0.5rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.fitness-nav a:hover {
|
||||
background: #f3f4f6;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.fitness-nav a.active {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.fitness-nav .icon {
|
||||
margin-right: 0.75rem;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.fitness-main {
|
||||
flex: 1;
|
||||
padding: 2rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.fitness-layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.fitness-nav {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.fitness-nav ul {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.fitness-nav li {
|
||||
margin-bottom: 0;
|
||||
margin-right: 0.5rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.fitness-nav a {
|
||||
padding: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
text-align: left;
|
||||
word-wrap: break-word;
|
||||
hyphens: auto;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.fitness-main {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,432 +0,0 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let recentSessions = $state([]);
|
||||
let templates = $state([]);
|
||||
let stats = $state({
|
||||
totalSessions: 0,
|
||||
totalTemplates: 0,
|
||||
thisWeek: 0
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
await Promise.all([
|
||||
loadRecentSessions(),
|
||||
loadTemplates(),
|
||||
loadStats()
|
||||
]);
|
||||
});
|
||||
|
||||
async function loadRecentSessions() {
|
||||
try {
|
||||
const response = await fetch('/api/fitness/sessions?limit=5');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
recentSessions = data.sessions;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load recent sessions:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTemplates() {
|
||||
try {
|
||||
const response = await fetch('/api/fitness/templates');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
templates = data.templates.slice(0, 3); // Show only 3 most recent
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load templates:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStats() {
|
||||
try {
|
||||
const [sessionsResponse, templatesResponse] = await Promise.all([
|
||||
fetch('/api/fitness/sessions'),
|
||||
fetch('/api/fitness/templates')
|
||||
]);
|
||||
|
||||
if (sessionsResponse.ok && templatesResponse.ok) {
|
||||
const sessionsData = await sessionsResponse.json();
|
||||
const templatesData = await templatesResponse.json();
|
||||
|
||||
const oneWeekAgo = new Date();
|
||||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
|
||||
|
||||
const thisWeekSessions = sessionsData.sessions.filter(session =>
|
||||
new Date(session.startTime) > oneWeekAgo
|
||||
);
|
||||
|
||||
stats = {
|
||||
totalSessions: sessionsData.total,
|
||||
totalTemplates: templatesData.templates.length,
|
||||
thisWeek: thisWeekSessions.length
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load stats:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
return new Date(dateString).toLocaleDateString();
|
||||
}
|
||||
|
||||
function formatDuration(minutes) {
|
||||
if (!minutes) return 'N/A';
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${mins}m`;
|
||||
}
|
||||
return `${mins}m`;
|
||||
}
|
||||
|
||||
async function createExampleTemplate() {
|
||||
try {
|
||||
const response = await fetch('/api/fitness/seed-example', {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
await loadTemplates();
|
||||
alert('Example template created successfully!');
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to create example template');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create example template:', error);
|
||||
alert('Failed to create example template');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="dashboard">
|
||||
<div class="dashboard-header">
|
||||
<h1>Fitness Dashboard</h1>
|
||||
<p>Track your progress and stay motivated!</p>
|
||||
</div>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">💪</div>
|
||||
<div class="stat-content">
|
||||
<div class="stat-number">{stats.totalSessions}</div>
|
||||
<div class="stat-label">Total Workouts</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📋</div>
|
||||
<div class="stat-content">
|
||||
<div class="stat-number">{stats.totalTemplates}</div>
|
||||
<div class="stat-label">Templates</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">🔥</div>
|
||||
<div class="stat-content">
|
||||
<div class="stat-number">{stats.thisWeek}</div>
|
||||
<div class="stat-label">This Week</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-content">
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<h2>Recent Workouts</h2>
|
||||
<a href="/fitness/sessions" class="view-all">View All</a>
|
||||
</div>
|
||||
|
||||
{#if recentSessions.length === 0}
|
||||
<div class="empty-state">
|
||||
<p>No workouts yet. <a href="/fitness/workout">Start your first workout!</a></p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="sessions-list">
|
||||
{#each recentSessions as session}
|
||||
<div class="session-card">
|
||||
<div class="session-info">
|
||||
<h3>{session.name}</h3>
|
||||
<p class="session-date">{formatDate(session.startTime)}</p>
|
||||
</div>
|
||||
<div class="session-stats">
|
||||
<span class="duration">{formatDuration(session.duration)}</span>
|
||||
<span class="exercises">{session.exercises.length} exercises</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<h2>Workout Templates</h2>
|
||||
<a href="/fitness/templates" class="view-all">View All</a>
|
||||
</div>
|
||||
|
||||
{#if templates.length === 0}
|
||||
<div class="empty-state">
|
||||
<p>No templates yet.</p>
|
||||
<div class="empty-actions">
|
||||
<a href="/fitness/templates">Create your first template!</a>
|
||||
<button class="example-btn" onclick={createExampleTemplate}>
|
||||
Create Example Template
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="templates-list">
|
||||
{#each templates as template}
|
||||
<div class="template-card">
|
||||
<h3>{template.name}</h3>
|
||||
{#if template.description}
|
||||
<p class="template-description">{template.description}</p>
|
||||
{/if}
|
||||
<div class="template-stats">
|
||||
<span>{template.exercises.length} exercises</span>
|
||||
</div>
|
||||
<div class="template-actions">
|
||||
<a href="/fitness/workout?template={template._id}" class="start-btn">Start Workout</a>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.dashboard {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.dashboard-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.dashboard-header h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 800;
|
||||
color: #1f2937;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.dashboard-header p {
|
||||
color: #6b7280;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 1.5rem;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 1.5rem;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
font-size: 2.5rem;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.dashboard-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: white;
|
||||
border-radius: 1rem;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-header h2 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.view-all {
|
||||
color: #3b82f6;
|
||||
text-decoration: none;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.view-all:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.empty-state a {
|
||||
color: #3b82f6;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.empty-state a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.empty-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.example-btn {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.example-btn:hover {
|
||||
background: #059669;
|
||||
}
|
||||
|
||||
.sessions-list, .templates-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.session-card {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
padding: 1rem;
|
||||
background: #f9fafb;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.session-info h3 {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 0 0 0.25rem 0;
|
||||
}
|
||||
|
||||
.session-date {
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.session-stats {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.template-card {
|
||||
padding: 1rem;
|
||||
background: #f9fafb;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.template-card h3 {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.template-description {
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.template-stats {
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.template-actions {
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
}
|
||||
|
||||
.start-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
text-decoration: none;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.start-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.session-card {
|
||||
flex-direction: column;
|
||||
align-items: start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.session-stats {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,457 +0,0 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let sessions = $state([]);
|
||||
let loading = $state(true);
|
||||
|
||||
onMount(async () => {
|
||||
await loadSessions();
|
||||
});
|
||||
|
||||
async function loadSessions() {
|
||||
loading = true;
|
||||
try {
|
||||
const response = await fetch('/api/fitness/sessions?limit=50');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
sessions = data.sessions;
|
||||
} else {
|
||||
console.error('Failed to load sessions');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load sessions:', error);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteSession(sessionId) {
|
||||
if (!confirm('Are you sure you want to delete this workout session?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/fitness/sessions/${sessionId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
await loadSessions();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to delete session');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete session:', error);
|
||||
alert('Failed to delete session');
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
function formatTime(dateString) {
|
||||
return new Date(dateString).toLocaleTimeString('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
|
||||
function formatDuration(minutes) {
|
||||
if (!minutes) return 'N/A';
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${mins}m`;
|
||||
}
|
||||
return `${mins}m`;
|
||||
}
|
||||
|
||||
function getTotalSets(session) {
|
||||
return session.exercises.reduce((total, exercise) => total + exercise.sets.length, 0);
|
||||
}
|
||||
|
||||
function getCompletedSets(session) {
|
||||
return session.exercises.reduce((total, exercise) =>
|
||||
total + exercise.sets.filter(set => set.completed).length, 0
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="sessions-page">
|
||||
<div class="page-header">
|
||||
<h1>Workout Sessions</h1>
|
||||
<a href="/fitness/workout" class="start-workout-btn">
|
||||
🏋️ Start New Workout
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="loading">Loading sessions...</div>
|
||||
{:else if sessions.length === 0}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">💪</div>
|
||||
<h2>No workout sessions yet</h2>
|
||||
<p>Start your fitness journey by creating your first workout!</p>
|
||||
<a href="/fitness/workout" class="cta-btn">Start Your First Workout</a>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="sessions-grid">
|
||||
{#each sessions as session}
|
||||
<div class="session-card">
|
||||
<div class="session-header">
|
||||
<h3>{session.name}</h3>
|
||||
<div class="session-date">
|
||||
<div class="date">{formatDate(session.startTime)}</div>
|
||||
<div class="time">{formatTime(session.startTime)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="session-stats">
|
||||
<div class="stat">
|
||||
<span class="stat-label">Duration</span>
|
||||
<span class="stat-value">{formatDuration(session.duration)}</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">Exercises</span>
|
||||
<span class="stat-value">{session.exercises.length}</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">Sets</span>
|
||||
<span class="stat-value">{getCompletedSets(session)}/{getTotalSets(session)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="session-exercises">
|
||||
<h4>Exercises:</h4>
|
||||
<ul class="exercise-list">
|
||||
{#each session.exercises as exercise}
|
||||
<li class="exercise-item">
|
||||
<span class="exercise-name">{exercise.name}</span>
|
||||
<span class="exercise-sets">{exercise.sets.filter(s => s.completed).length}/{exercise.sets.length} sets</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{#if session.notes}
|
||||
<div class="session-notes">
|
||||
<h4>Notes:</h4>
|
||||
<p>{session.notes}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="session-actions">
|
||||
{#if session.templateId}
|
||||
<a href="/fitness/workout?template={session.templateId}" class="repeat-btn">
|
||||
🔄 Repeat Workout
|
||||
</a>
|
||||
{/if}
|
||||
<button
|
||||
class="delete-btn"
|
||||
onclick={() => deleteSession(session._id)}
|
||||
title="Delete session"
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.sessions-page {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.start-workout-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.start-workout-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 3rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
background: white;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 4rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.empty-state h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
color: #6b7280;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.cta-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.cta-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.sessions-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.session-card {
|
||||
background: white;
|
||||
border-radius: 0.75rem;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.session-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: start;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.session-header h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.session-date {
|
||||
text-align: right;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.date {
|
||||
color: #1f2937;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.time {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.session-stats {
|
||||
display: flex;
|
||||
justify-content: around;
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1rem;
|
||||
background: #f9fafb;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.stat {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
display: block;
|
||||
font-size: 0.75rem;
|
||||
color: #6b7280;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
display: block;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.session-exercises {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.session-exercises h4 {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.exercise-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.exercise-item {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
padding: 0.5rem 0;
|
||||
border-bottom: 1px solid #f3f4f6;
|
||||
}
|
||||
|
||||
.exercise-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.exercise-name {
|
||||
font-weight: 500;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.exercise-sets {
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.session-notes {
|
||||
margin-bottom: 1rem;
|
||||
padding: 1rem;
|
||||
background: #fef3c7;
|
||||
border-radius: 0.5rem;
|
||||
border-left: 4px solid #f59e0b;
|
||||
}
|
||||
|
||||
.session-notes h4 {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: #92400e;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.session-notes p {
|
||||
margin: 0;
|
||||
color: #92400e;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.session-actions {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.repeat-btn {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
text-decoration: none;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.repeat-btn:hover {
|
||||
background: #059669;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.delete-btn:hover {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.sessions-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.session-header {
|
||||
flex-direction: column;
|
||||
align-items: start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.session-date {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.session-stats {
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.session-actions {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.repeat-btn {
|
||||
align-self: stretch;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,765 +0,0 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let templates = $state([]);
|
||||
let showCreateForm = $state(false);
|
||||
let newTemplate = $state({
|
||||
name: '',
|
||||
description: '',
|
||||
exercises: [
|
||||
{
|
||||
name: '',
|
||||
sets: [{ reps: 10, weight: 0, rpe: null }],
|
||||
restTime: 120
|
||||
}
|
||||
],
|
||||
isPublic: false
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
await loadTemplates();
|
||||
});
|
||||
|
||||
async function loadTemplates() {
|
||||
try {
|
||||
const response = await fetch('/api/fitness/templates?include_public=true');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
templates = data.templates;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load templates:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function createTemplate(event) {
|
||||
event.preventDefault();
|
||||
try {
|
||||
const response = await fetch('/api/fitness/templates', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(newTemplate)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
showCreateForm = false;
|
||||
resetForm();
|
||||
await loadTemplates();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to create template');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create template:', error);
|
||||
alert('Failed to create template');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTemplate(templateId) {
|
||||
if (!confirm('Are you sure you want to delete this template?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/fitness/templates/${templateId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
await loadTemplates();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to delete template');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete template:', error);
|
||||
alert('Failed to delete template');
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
newTemplate = {
|
||||
name: '',
|
||||
description: '',
|
||||
exercises: [
|
||||
{
|
||||
name: '',
|
||||
sets: [{ reps: 10, weight: 0, rpe: null }],
|
||||
restTime: 120
|
||||
}
|
||||
],
|
||||
isPublic: false
|
||||
};
|
||||
}
|
||||
|
||||
function addExercise() {
|
||||
newTemplate.exercises = [
|
||||
...newTemplate.exercises,
|
||||
{
|
||||
name: '',
|
||||
sets: [{ reps: 10, weight: 0, rpe: null }],
|
||||
restTime: 120
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function removeExercise(index) {
|
||||
newTemplate.exercises = newTemplate.exercises.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function addSet(exerciseIndex) {
|
||||
newTemplate.exercises[exerciseIndex].sets = [
|
||||
...newTemplate.exercises[exerciseIndex].sets,
|
||||
{ reps: 10, weight: 0, rpe: null }
|
||||
];
|
||||
}
|
||||
|
||||
function removeSet(exerciseIndex, setIndex) {
|
||||
newTemplate.exercises[exerciseIndex].sets = newTemplate.exercises[exerciseIndex].sets.filter((_, i) => i !== setIndex);
|
||||
}
|
||||
|
||||
function formatRestTime(seconds) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
if (remainingSeconds === 0) {
|
||||
return `${minutes}:00`;
|
||||
}
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="templates-page">
|
||||
<div class="page-header">
|
||||
<h1>Workout Templates</h1>
|
||||
<button class="create-btn" onclick={() => showCreateForm = true}>
|
||||
<span class="icon">➕</span>
|
||||
Create Template
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showCreateForm}
|
||||
<div class="create-form-overlay">
|
||||
<div class="create-form">
|
||||
<div class="form-header">
|
||||
<h2>Create New Template</h2>
|
||||
<button class="close-btn" onclick={() => showCreateForm = false}>✕</button>
|
||||
</div>
|
||||
|
||||
<form onsubmit={createTemplate}>
|
||||
<div class="form-group">
|
||||
<label for="name">Template Name</label>
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
bind:value={newTemplate.name}
|
||||
required
|
||||
placeholder="e.g., Push Day"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="description">Description (optional)</label>
|
||||
<textarea
|
||||
id="description"
|
||||
bind:value={newTemplate.description}
|
||||
placeholder="Brief description of this workout..."
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="exercises-section">
|
||||
<h3>Exercises</h3>
|
||||
|
||||
{#each newTemplate.exercises as exercise, exerciseIndex}
|
||||
<div class="exercise-form">
|
||||
<div class="exercise-header">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={exercise.name}
|
||||
placeholder="Exercise name (e.g., Barbell Squat)"
|
||||
class="exercise-name-input"
|
||||
required
|
||||
/>
|
||||
<div class="rest-time-input">
|
||||
<label>Rest: </label>
|
||||
<input
|
||||
type="number"
|
||||
bind:value={exercise.restTime}
|
||||
min="10"
|
||||
max="600"
|
||||
class="rest-input"
|
||||
/>
|
||||
<span>sec</span>
|
||||
</div>
|
||||
{#if newTemplate.exercises.length > 1}
|
||||
<button
|
||||
type="button"
|
||||
class="remove-exercise-btn"
|
||||
onclick={() => removeExercise(exerciseIndex)}
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="sets-section">
|
||||
<div class="sets-header">
|
||||
<span>Sets</span>
|
||||
<button
|
||||
type="button"
|
||||
class="add-set-btn"
|
||||
onclick={() => addSet(exerciseIndex)}
|
||||
>
|
||||
+ Add Set
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#each exercise.sets as set, setIndex}
|
||||
<div class="set-form">
|
||||
<span class="set-number">Set {setIndex + 1}</span>
|
||||
<div class="set-inputs">
|
||||
<label>
|
||||
Reps:
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.reps}
|
||||
min="1"
|
||||
required
|
||||
class="reps-input"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Weight (kg):
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.weight}
|
||||
min="0"
|
||||
step="0.5"
|
||||
class="weight-input"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
RPE:
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.rpe}
|
||||
min="1"
|
||||
max="10"
|
||||
step="0.5"
|
||||
class="rpe-input"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{#if exercise.sets.length > 1}
|
||||
<button
|
||||
type="button"
|
||||
class="remove-set-btn"
|
||||
onclick={() => removeSet(exerciseIndex, setIndex)}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<button type="button" class="add-exercise-btn" onclick={addExercise}>
|
||||
➕ Add Exercise
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" bind:checked={newTemplate.isPublic} />
|
||||
Make this template public (other users can see and use it)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="cancel-btn" onclick={() => showCreateForm = false}>
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="submit-btn">Create Template</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="templates-grid">
|
||||
{#if templates.length === 0}
|
||||
<div class="empty-state">
|
||||
<p>No templates found. Create your first template to get started!</p>
|
||||
</div>
|
||||
{:else}
|
||||
{#each templates as template}
|
||||
<div class="template-card">
|
||||
<div class="template-header">
|
||||
<h3>{template.name}</h3>
|
||||
{#if template.isPublic}
|
||||
<span class="public-badge">Public</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if template.description}
|
||||
<p class="template-description">{template.description}</p>
|
||||
{/if}
|
||||
|
||||
<div class="template-exercises">
|
||||
<h4>Exercises ({template.exercises.length}):</h4>
|
||||
<ul>
|
||||
{#each template.exercises as exercise}
|
||||
<li>
|
||||
<strong>{exercise.name}</strong> - {exercise.sets.length} sets
|
||||
<small>(Rest: {formatRestTime(exercise.restTime || 120)})</small>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="template-meta">
|
||||
<small>Created: {new Date(template.createdAt).toLocaleDateString()}</small>
|
||||
</div>
|
||||
|
||||
<div class="template-actions">
|
||||
<a href="/fitness/workout?template={template._id}" class="start-workout-btn">
|
||||
🏋️ Start Workout
|
||||
</a>
|
||||
<button
|
||||
class="delete-btn"
|
||||
onclick={() => deleteTemplate(template._id)}
|
||||
title="Delete template"
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.templates-page {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.create-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.create-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.create-form-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.create-form {
|
||||
background: white;
|
||||
border-radius: 1rem;
|
||||
padding: 2rem;
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.form-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.form-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
cursor: pointer;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.375rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.exercises-section {
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
.exercises-section h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.exercise-form {
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
background: #f9fafb;
|
||||
}
|
||||
|
||||
.exercise-header {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.exercise-name-input {
|
||||
flex: 1;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.375rem;
|
||||
}
|
||||
|
||||
.rest-time-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.rest-input {
|
||||
width: 60px;
|
||||
padding: 0.25rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.remove-exercise-btn {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sets-section {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.sets-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.add-set-btn {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.set-form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background: white;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.set-number {
|
||||
font-weight: 500;
|
||||
min-width: 40px;
|
||||
}
|
||||
|
||||
.set-inputs {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.set-inputs label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.reps-input,
|
||||
.weight-input,
|
||||
.rpe-input {
|
||||
width: 60px;
|
||||
padding: 0.25rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.remove-set-btn {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.add-exercise-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
margin: 1rem auto 0;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
gap: 1rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background: #6b7280;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.templates-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 3rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.template-card {
|
||||
background: white;
|
||||
border-radius: 0.75rem;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.template-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.template-header h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.public-badge {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.template-description {
|
||||
color: #6b7280;
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.template-exercises h4 {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.template-exercises ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.template-exercises li {
|
||||
padding: 0.25rem 0;
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.template-exercises li strong {
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.template-exercises small {
|
||||
display: block;
|
||||
margin-top: 0.125rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.template-meta {
|
||||
margin: 1rem 0;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.template-meta small {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.template-actions {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.start-workout-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.start-workout-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.delete-btn:hover {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.templates-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.create-form {
|
||||
margin: 0;
|
||||
border-radius: 0;
|
||||
max-height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.exercise-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.set-inputs {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,808 +0,0 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
let templateId = $state(null);
|
||||
let template = $state(null);
|
||||
let currentSession = $state({
|
||||
name: '',
|
||||
exercises: [],
|
||||
startTime: new Date(),
|
||||
notes: ''
|
||||
});
|
||||
let currentExerciseIndex = $state(0);
|
||||
let currentSetIndex = $state(0);
|
||||
let restTimer = $state({
|
||||
active: false,
|
||||
timeLeft: 0,
|
||||
totalTime: 120
|
||||
});
|
||||
let restTimerInterval = null;
|
||||
|
||||
onMount(async () => {
|
||||
templateId = $page.url.searchParams.get('template');
|
||||
|
||||
if (templateId) {
|
||||
await loadTemplate();
|
||||
} else {
|
||||
// Create a blank workout
|
||||
currentSession = {
|
||||
name: 'Quick Workout',
|
||||
exercises: [
|
||||
{
|
||||
name: '',
|
||||
sets: [{ reps: 0, weight: 0, rpe: null, completed: false }],
|
||||
restTime: 120,
|
||||
notes: ''
|
||||
}
|
||||
],
|
||||
startTime: new Date(),
|
||||
notes: ''
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
async function loadTemplate() {
|
||||
try {
|
||||
const response = await fetch(`/api/fitness/templates/${templateId}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
template = data.template;
|
||||
|
||||
// Convert template to workout session format
|
||||
currentSession = {
|
||||
name: template.name,
|
||||
exercises: template.exercises.map(exercise => ({
|
||||
...exercise,
|
||||
sets: exercise.sets.map(set => ({
|
||||
...set,
|
||||
completed: false,
|
||||
notes: ''
|
||||
})),
|
||||
notes: ''
|
||||
})),
|
||||
startTime: new Date(),
|
||||
notes: ''
|
||||
};
|
||||
} else {
|
||||
alert('Template not found');
|
||||
goto('/fitness/templates');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load template:', error);
|
||||
alert('Failed to load template');
|
||||
goto('/fitness/templates');
|
||||
}
|
||||
}
|
||||
|
||||
function startRestTimer(seconds = null) {
|
||||
const restTime = seconds || currentSession.exercises[currentExerciseIndex]?.restTime || 120;
|
||||
|
||||
restTimer = {
|
||||
active: true,
|
||||
timeLeft: restTime,
|
||||
totalTime: restTime
|
||||
};
|
||||
|
||||
if (restTimerInterval) {
|
||||
clearInterval(restTimerInterval);
|
||||
}
|
||||
|
||||
restTimerInterval = setInterval(() => {
|
||||
if (restTimer.timeLeft > 0) {
|
||||
restTimer.timeLeft--;
|
||||
} else {
|
||||
stopRestTimer();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function stopRestTimer() {
|
||||
restTimer.active = false;
|
||||
if (restTimerInterval) {
|
||||
clearInterval(restTimerInterval);
|
||||
restTimerInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(seconds) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function markSetCompleted(exerciseIndex, setIndex) {
|
||||
currentSession.exercises[exerciseIndex].sets[setIndex].completed = true;
|
||||
|
||||
// Auto-start rest timer
|
||||
const exercise = currentSession.exercises[exerciseIndex];
|
||||
if (exercise.restTime > 0) {
|
||||
startRestTimer(exercise.restTime);
|
||||
}
|
||||
}
|
||||
|
||||
function addExercise() {
|
||||
currentSession.exercises = [
|
||||
...currentSession.exercises,
|
||||
{
|
||||
name: '',
|
||||
sets: [{ reps: 0, weight: 0, rpe: null, completed: false }],
|
||||
restTime: 120,
|
||||
notes: ''
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function addSet(exerciseIndex) {
|
||||
const lastSet = currentSession.exercises[exerciseIndex].sets.slice(-1)[0];
|
||||
currentSession.exercises[exerciseIndex].sets = [
|
||||
...currentSession.exercises[exerciseIndex].sets,
|
||||
{
|
||||
reps: lastSet?.reps || 0,
|
||||
weight: lastSet?.weight || 0,
|
||||
rpe: null,
|
||||
completed: false,
|
||||
notes: ''
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function removeSet(exerciseIndex, setIndex) {
|
||||
if (currentSession.exercises[exerciseIndex].sets.length > 1) {
|
||||
currentSession.exercises[exerciseIndex].sets =
|
||||
currentSession.exercises[exerciseIndex].sets.filter((_, i) => i !== setIndex);
|
||||
}
|
||||
}
|
||||
|
||||
async function finishWorkout() {
|
||||
if (!confirm('Are you sure you want to finish this workout?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopRestTimer();
|
||||
|
||||
try {
|
||||
const endTime = new Date();
|
||||
const sessionData = {
|
||||
templateId: template?._id,
|
||||
name: currentSession.name,
|
||||
exercises: currentSession.exercises,
|
||||
startTime: currentSession.startTime.toISOString(),
|
||||
endTime: endTime.toISOString(),
|
||||
notes: currentSession.notes
|
||||
};
|
||||
|
||||
const response = await fetch('/api/fitness/sessions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(sessionData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Workout saved successfully!');
|
||||
goto('/fitness/sessions');
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to save workout');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to save workout:', error);
|
||||
alert('Failed to save workout');
|
||||
}
|
||||
}
|
||||
|
||||
function cancelWorkout() {
|
||||
if (confirm('Are you sure you want to cancel this workout? All progress will be lost.')) {
|
||||
stopRestTimer();
|
||||
goto('/fitness');
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up timer on component destroy
|
||||
$effect(() => {
|
||||
return () => {
|
||||
if (restTimerInterval) {
|
||||
clearInterval(restTimerInterval);
|
||||
}
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="workout-page">
|
||||
{#if restTimer.active}
|
||||
<div class="rest-timer-overlay">
|
||||
<div class="rest-timer">
|
||||
<h2>Rest Time</h2>
|
||||
<div class="timer-display">
|
||||
<div class="time">{formatTime(restTimer.timeLeft)}</div>
|
||||
<div class="progress-bar">
|
||||
<div
|
||||
class="progress-fill"
|
||||
style="width: {((restTimer.totalTime - restTimer.timeLeft) / restTimer.totalTime) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="timer-controls">
|
||||
<button class="timer-btn" onclick={() => restTimer.timeLeft += 30}>+30s</button>
|
||||
<button class="timer-btn" onclick={() => restTimer.timeLeft = Math.max(0, restTimer.timeLeft - 30)}>-30s</button>
|
||||
<button class="timer-btn skip" onclick={stopRestTimer}>Skip</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="workout-header">
|
||||
<div class="workout-info">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={currentSession.name}
|
||||
class="workout-name-input"
|
||||
placeholder="Workout Name"
|
||||
/>
|
||||
<div class="workout-time">
|
||||
Started: {currentSession.startTime.toLocaleTimeString()}
|
||||
</div>
|
||||
</div>
|
||||
<div class="workout-actions">
|
||||
<button class="cancel-btn" onclick={cancelWorkout}>Cancel</button>
|
||||
<button class="finish-btn" onclick={finishWorkout}>Finish Workout</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="exercises-container">
|
||||
{#each currentSession.exercises as exercise, exerciseIndex}
|
||||
<div class="exercise-card">
|
||||
<div class="exercise-header">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={exercise.name}
|
||||
placeholder="Exercise name"
|
||||
class="exercise-name-input"
|
||||
/>
|
||||
<div class="exercise-meta">
|
||||
<label>
|
||||
Rest:
|
||||
<input
|
||||
type="number"
|
||||
bind:value={exercise.restTime}
|
||||
min="10"
|
||||
max="600"
|
||||
class="rest-input"
|
||||
/>s
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sets-container">
|
||||
<div class="sets-header">
|
||||
<span>Set</span>
|
||||
<span>Previous</span>
|
||||
<span>Weight (kg)</span>
|
||||
<span>Reps</span>
|
||||
<span>RPE</span>
|
||||
<span>Actions</span>
|
||||
</div>
|
||||
|
||||
{#each exercise.sets as set, setIndex}
|
||||
<div class="set-row" class:completed={set.completed}>
|
||||
<div class="set-number">{setIndex + 1}</div>
|
||||
<div class="previous-data">
|
||||
{#if template?.exercises[exerciseIndex]?.sets[setIndex]}
|
||||
{@const prevSet = template.exercises[exerciseIndex].sets[setIndex]}
|
||||
{prevSet.weight || 0}kg × {prevSet.reps}
|
||||
{#if prevSet.rpe}@ {prevSet.rpe}{/if}
|
||||
{:else}
|
||||
-
|
||||
{/if}
|
||||
</div>
|
||||
<div class="set-input">
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.weight}
|
||||
min="0"
|
||||
step="0.5"
|
||||
disabled={set.completed}
|
||||
class="weight-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="set-input">
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.reps}
|
||||
min="0"
|
||||
disabled={set.completed}
|
||||
class="reps-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="set-input">
|
||||
<input
|
||||
type="number"
|
||||
bind:value={set.rpe}
|
||||
min="1"
|
||||
max="10"
|
||||
step="0.5"
|
||||
disabled={set.completed}
|
||||
class="rpe-input"
|
||||
placeholder="1-10"
|
||||
/>
|
||||
</div>
|
||||
<div class="set-actions">
|
||||
{#if !set.completed}
|
||||
<button
|
||||
class="complete-btn"
|
||||
onclick={() => markSetCompleted(exerciseIndex, setIndex)}
|
||||
disabled={!set.reps}
|
||||
>
|
||||
✓
|
||||
</button>
|
||||
{:else}
|
||||
<span class="completed-marker">✅</span>
|
||||
{/if}
|
||||
{#if exercise.sets.length > 1}
|
||||
<button
|
||||
class="remove-set-btn"
|
||||
onclick={() => removeSet(exerciseIndex, setIndex)}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<div class="set-controls">
|
||||
<button class="add-set-btn" onclick={() => addSet(exerciseIndex)}>
|
||||
+ Add Set
|
||||
</button>
|
||||
<button
|
||||
class="start-timer-btn"
|
||||
onclick={() => startRestTimer(exercise.restTime)}
|
||||
disabled={restTimer.active}
|
||||
>
|
||||
⏱️ Start Timer ({formatTime(exercise.restTime)})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="exercise-notes">
|
||||
<textarea
|
||||
bind:value={exercise.notes}
|
||||
placeholder="Exercise notes..."
|
||||
class="notes-input"
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<div class="add-exercise-section">
|
||||
<button class="add-exercise-btn" onclick={addExercise}>
|
||||
➕ Add Exercise
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="workout-notes">
|
||||
<label for="workout-notes">Workout Notes:</label>
|
||||
<textarea
|
||||
id="workout-notes"
|
||||
bind:value={currentSession.notes}
|
||||
placeholder="How did the workout feel? Any observations?"
|
||||
class="workout-notes-input"
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.workout-page {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.rest-timer-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.rest-timer {
|
||||
background: white;
|
||||
padding: 3rem;
|
||||
border-radius: 1rem;
|
||||
text-align: center;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.rest-timer h2 {
|
||||
color: #1f2937;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.timer-display {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 4rem;
|
||||
font-weight: 700;
|
||||
color: #3b82f6;
|
||||
margin-bottom: 1rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 8px;
|
||||
background: #e5e7eb;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: #3b82f6;
|
||||
transition: width 1s ease;
|
||||
}
|
||||
|
||||
.timer-controls {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.timer-btn {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: 0.5rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
background: #6b7280;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.timer-btn.skip {
|
||||
background: #3b82f6;
|
||||
}
|
||||
|
||||
.timer-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.workout-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
padding: 1.5rem;
|
||||
background: white;
|
||||
border-radius: 0.75rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.workout-name-input {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: #1f2937;
|
||||
padding: 0.5rem;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
|
||||
.workout-name-input:focus {
|
||||
outline: none;
|
||||
border-bottom-color: #3b82f6;
|
||||
}
|
||||
|
||||
.workout-time {
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.workout-actions {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background: #6b7280;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.finish-btn {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.exercises-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.exercise-card {
|
||||
background: white;
|
||||
border-radius: 0.75rem;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.exercise-header {
|
||||
display: flex;
|
||||
justify-content: between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.exercise-name-input {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: #1f2937;
|
||||
padding: 0.5rem;
|
||||
border-bottom: 2px solid transparent;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.exercise-name-input:focus {
|
||||
outline: none;
|
||||
border-bottom-color: #3b82f6;
|
||||
}
|
||||
|
||||
.exercise-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.rest-input {
|
||||
width: 60px;
|
||||
padding: 0.25rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sets-container {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.sets-header {
|
||||
display: grid;
|
||||
grid-template-columns: 40px 120px 100px 80px 80px 120px;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem;
|
||||
font-weight: 600;
|
||||
color: #6b7280;
|
||||
font-size: 0.875rem;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.set-row {
|
||||
display: grid;
|
||||
grid-template-columns: 40px 120px 100px 80px 80px 120px;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 0.5rem;
|
||||
align-items: center;
|
||||
border-radius: 0.375rem;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.set-row:hover {
|
||||
background: #f9fafb;
|
||||
}
|
||||
|
||||
.set-row.completed {
|
||||
background: #f0f9ff;
|
||||
border: 1px solid #bfdbfe;
|
||||
}
|
||||
|
||||
.set-number {
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.previous-data {
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.set-input input {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.375rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.set-input input:disabled {
|
||||
background: #f9fafb;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.set-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.complete-btn {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.complete-btn:disabled {
|
||||
background: #d1d5db;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.remove-set-btn {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.completed-marker {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.set-controls {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.add-set-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.start-timer-btn {
|
||||
background: #f59e0b;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.start-timer-btn:disabled {
|
||||
background: #d1d5db;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.exercise-notes {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.notes-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.375rem;
|
||||
resize: vertical;
|
||||
min-height: 60px;
|
||||
}
|
||||
|
||||
.add-exercise-section {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.add-exercise-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 1rem 2rem;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.workout-notes {
|
||||
margin-top: 2rem;
|
||||
background: white;
|
||||
padding: 1.5rem;
|
||||
border-radius: 0.75rem;
|
||||
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.workout-notes label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.workout-notes-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.375rem;
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.workout-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.workout-actions {
|
||||
justify-content: stretch;
|
||||
}
|
||||
|
||||
.workout-actions button {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.sets-header,
|
||||
.set-row {
|
||||
grid-template-columns: 30px 80px 70px 60px 60px 80px;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.exercise-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.set-controls {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.rest-timer {
|
||||
margin: 1rem;
|
||||
padding: 2rem;
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
.timer-controls {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -162,20 +162,19 @@ function getMysteryForWeekday(date, includeLuminous) {
|
||||
}
|
||||
|
||||
// Determine which mystery to use based on current weekday
|
||||
let selectedMystery = $state(getMysteryForWeekday(new Date(), includeLuminous));
|
||||
let todaysMystery = $state(selectedMystery); // Track today's auto-selected mystery
|
||||
let currentMysteries = $state(mysteries[selectedMystery]);
|
||||
let currentMysteriesLatin = $state(mysteriesLatin[selectedMystery]);
|
||||
let currentMysteryTitles = $state(mysteryTitles[selectedMystery]);
|
||||
// Reactive statement to update mystery descriptions when selectedMystery changes
|
||||
const initialMystery = getMysteryForWeekday(new Date(), true); // Use literal true to avoid capturing reactive state
|
||||
let selectedMystery = $state(initialMystery);
|
||||
let todaysMystery = $state(initialMystery); // Track today's auto-selected mystery
|
||||
|
||||
// Derive these values from selectedMystery so they update automatically
|
||||
let currentMysteries = $derived(mysteries[selectedMystery]);
|
||||
let currentMysteriesLatin = $derived(mysteriesLatin[selectedMystery]);
|
||||
let currentMysteryTitles = $derived(mysteryTitles[selectedMystery]);
|
||||
let currentMysteryDescriptions = $derived(data.mysteryDescriptions[selectedMystery] || []);
|
||||
|
||||
// Function to switch mysteries
|
||||
function selectMystery(mysteryType) {
|
||||
selectedMystery = mysteryType;
|
||||
currentMysteries = mysteries[mysteryType];
|
||||
currentMysteriesLatin = mysteriesLatin[mysteryType];
|
||||
currentMysteryTitles = mysteryTitles[mysteryType];
|
||||
}
|
||||
|
||||
// Function to handle toggle change
|
||||
|
||||
Reference in New Issue
Block a user