summaryrefslogtreecommitdiff
path: root/web/templates.templ
blob: 85ee03d852de83a761e23eadac1b0f2f8b4e5824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package web

templ Layout(title string, content templ.Component) {
	<!doctype html>
	<html lang="en">
		<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1"/>
		<title>{ title } · biking_home</title>
		<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
		<style>
				:root { color-scheme: light; font-family: system-ui, sans-serif; background: #f5f3ee; color: #1d2a22; }
				* { box-sizing: border-box; }
				body { margin: 0; }
				a { color: #18794e; }
				.site-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem max(1rem, calc((100vw - 70rem) / 2)); background: #173b2a; color: #fff; }
				.site-header a { color: #fff; text-decoration: none; }
				.brand { font-weight: 750; letter-spacing: .02em; }
				.nav { display: flex; gap: 1rem; font-size: .95rem; }
				.container { width: min(70rem, calc(100% - 2rem)); margin: 0 auto; padding: 2.5rem 0 4rem; }
				.eyebrow { margin: 0 0 .4rem; color: #18794e; font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
				h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1; }
				.lead { max-width: 42rem; color: #5b675f; }
				.panel { margin-top: 2rem; padding: 1.25rem; border: 1px solid #d9ded8; border-radius: 1rem; background: #fff; box-shadow: 0 1rem 2.5rem #173b2a0d; }
				.toolbar { display: flex; align-items: end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
				.button { display: inline-block; border: 0; border-radius: .65rem; padding: .7rem 1rem; background: #d96932; color: #fff; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
				.button.secondary { background: #e8eee9; color: #173b2a; }
				label { display: grid; gap: .35rem; color: #5b675f; font-size: .85rem; font-weight: 650; }
				input { border: 1px solid #c8d0c9; border-radius: .55rem; padding: .65rem .7rem; font: inherit; color: inherit; background: #fff; }
				.form-row { display: flex; align-items: end; gap: .75rem; flex-wrap: wrap; }
				.notice { margin: 1rem 0 0; border-radius: .6rem; padding: .75rem 1rem; background: #e5f3e9; color: #17633f; }
				.error { margin: 1rem 0 0; border-radius: .6rem; padding: .75rem 1rem; background: #fbe8df; color: #8c3517; }
				table { width: 100%; border-collapse: collapse; }
				th, td { padding: .85rem .5rem; border-bottom: 1px solid #e5e9e5; text-align: left; }
				th { color: #68746c; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
				.sort-link { color: inherit; text-decoration: none; }
				.sort-link:hover, .sort-link:focus-visible, th.active .sort-link { color: #d96932; }
				.sort-indicator { display: inline-block; margin-left: .2rem; }
				.numeric { text-align: right; white-space: nowrap; }
				.empty { padding: 2.5rem 1rem; text-align: center; color: #68746c; }
				.map-panel { padding: 0; overflow: hidden; }
				.ride-map { min-height: 24rem; height: min(65vh, 40rem); }
				dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 0; }
				dt { color: #68746c; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
				dd { margin: .25rem 0 0; font-size: 1.2rem; font-weight: 700; }
				@media (max-width: 700px) { .container { width: min(100% - 1rem, 70rem); padding-top: 1.5rem; } .site-header { padding-inline: 1rem; } th:nth-child(n+4), td:nth-child(n+4) { display: none; } .panel { padding: .8rem; } }
				@media (max-width: 500px) { dl { grid-template-columns: repeat(2, 1fr); } }
			</style>
		</head>
		<body>
			<header class="site-header">
				<a class="brand" href="/">biking_home</a>
				<nav class="nav"><a href="/">Rides</a><a href="/sync">Sync Strava</a></nav>
			</header>
			<main class="container">
				@content
			</main>
		</body>
	</html>
}

templ RidesPage(items []RideView, headers []RideSortHeader) {
	@Layout("Rides", RidesContent(items, headers))
}

templ RidesContent(items []RideView, headers []RideSortHeader) {
	<p class="eyebrow">Ride library</p>
	<div class="toolbar">
		<div><h1>All rides</h1><p class="lead">Your imported rides, ready for climb analysis.</p></div>
		<a class="button" href="/sync">Sync Strava</a>
	</div>
	<section class="panel">
		if len(items) == 0 {
			<div class="empty">No rides stored yet. <a href="/sync">Import your first Strava rides.</a></div>
		} else {
			<table>
				<thead><tr>
					for _, header := range headers {
						<th class={ header.Class } scope="col" aria-sort={ header.AriaSort }><a class="sort-link" href={ templ.URL(header.URL) }>{ header.Label }<span class="sort-indicator" aria-hidden="true">{ header.Indicator }</span></a></th>
					}
				</tr></thead>
				<tbody>
					for _, item := range items {
						<tr><td><strong><a href={ templ.URL(rideDetailURL(item.ID)) }>{ item.Name }</a></strong><br/><small>{ item.Type }</small></td><td>{ formatRideDate(item.StartDate) }</td><td class="numeric">{ formatDistance(item.DistanceM) }</td><td class="numeric">{ formatDuration(item.MovingTimeS) }</td><td class="numeric">{ formatElevation(item.TotalElevationGainM) }</td><td class="numeric">{ item.Cotacol }</td><td class="numeric">{ item.CotacolPer100Km }</td></tr>
					}
				</tbody>
			</table>
		}
	</section>
}

templ RideDetailPage(data RideDetailView) {
	@Layout("Ride detail", RideDetailContent(data))
}

templ RideDetailContent(data RideDetailView) {
	<p class="eyebrow">Ride detail</p>
	<div class="toolbar">
		<div><h1>{ data.Ride.Name }</h1><p class="lead">{ data.Ride.Type } · { formatRideDate(data.Ride.StartDate) }</p></div>
		<a class="button secondary" href="/">Back to rides</a>
	</div>
	<section class="panel">
		<dl>
			<div><dt>Distance</dt><dd>{ formatDistance(data.Ride.DistanceM) }</dd></div>
			<div><dt>Moving time</dt><dd>{ formatDuration(data.Ride.MovingTimeS) }</dd></div>
			<div><dt>Elevation</dt><dd>{ formatElevation(data.Ride.TotalElevationGainM) }</dd></div>
		</dl>
	</section>
	if data.RouteError != "" {
		<div class="error">{ data.RouteError }</div>
	}
	if data.HasRoute {
		<section class="panel map-panel">
			<div id="ride-map" class="ride-map" role="img" aria-label="Recorded ride route map"></div>
		</section>
		@templ.JSONScript("ride-route", data.Route)
		<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
		<script>
			(() => {
				const mapElement = document.getElementById("ride-map");
				const routeElement = document.getElementById("ride-route");
				const route = JSON.parse(routeElement.textContent);
				const map = L.map(mapElement);
				const tiles = L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
					maxZoom: 19,
					attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
				});
				tiles.addTo(map);
				const routeLayer = L.geoJSON(route, {
					style: { color: "#d96932", weight: 4, opacity: 0.9 },
				}).addTo(map);
				const bounds = routeLayer.getBounds();
				if (bounds.isValid()) {
					map.fitBounds(bounds, { padding: [24, 24], maxZoom: 15 });
				}
			})();
		</script>
	}
}

templ SyncPage(data SyncPageData) {
	@Layout("Sync Strava", SyncContent(data))
}

templ SyncContent(data SyncPageData) {
	<p class="eyebrow">Data import</p>
	<h1>Sync Strava rides</h1>
	<p class="lead">Choose a date range. New rides are downloaded as GPX files and recorded in the local library.</p>
	if data.Notice != "" {
		<div class="notice">{ data.Notice }</div>
	}
	if data.Error != "" {
		<div class="error">{ data.Error }</div>
	}
	<section class="panel">
		if !data.HasAuth {
			<p>Strava authorization is required before the first sync.</p>
			<a class="button secondary" href={ templ.URL("/strava/login?return_to=/sync") }>Authorize Strava</a>
		} else {
			<form method="post" action="/sync">
				<div class="form-row">
					<label>From<input type="date" name="from" value={ data.From } required/></label>
					<label>To<input type="date" name="to" value={ data.To } required/></label>
					<button class="button" type="submit">Sync rides</button>
				</div>
			</form>
		}
	</section>
}