-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistory.html
More file actions
346 lines (320 loc) · 12.1 KB
/
history.html
File metadata and controls
346 lines (320 loc) · 12.1 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Scan History — Sustainable Food Tracker</title>
<style>
:root{
--page-bg:#fbf9f7;
--hero-start:#2bc07c;
--hero-end:#20b38c;
--card:#ffffff;
--muted:#7a8a85;
--accent:#11a0f2;
--gold:#f6a623;
--green:#12b07a;
--radius:14px;
--soft-shadow: 0 10px 30px rgba(16,40,30,0.06);
font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
background:var(--page-bg);
color:#16302f;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
}
/* HERO */
.hero{
background: linear-gradient(135deg, var(--hero-start), var(--hero-end));
padding:32px 20px 36px;
color:#fff;
border-bottom-left-radius:24px;
border-bottom-right-radius:24px;
}
.container{
width:100%;
max-width:980px;
margin:0 auto;
}
.hero-head{
display:flex;
align-items:center;
gap:12px;
}
.hero-head h1{
margin:0;font-size:22px;font-weight:700;
}
.hero-sub{margin:6px 0 0;color:rgba(255,255,255,0.95);font-size:13px}
.stats-row{
display:flex;
gap:12px;
margin-top:20px;
align-items:stretch;
flex-wrap:wrap;
}
.stat{
background:rgba(255,255,255,0.12);
padding:18px 16px;
border-radius:12px;
min-width:120px;
width:calc(33.333% - 8px);
box-shadow: 0 6px 18px rgba(10,20,18,0.04);
text-align:center;
}
.stat .big{font-size:20px;font-weight:800;color:#fff;margin-top:6px}
.stat .label{font-size:13px;color:rgba(255,255,255,0.9);margin-top:6px}
@media (max-width:720px){
.stat{width:48%}
}
@media (max-width:420px){
.stat{width:100%}
}
/* MAIN CONTENT */
main{
max-width:980px;
margin:22px auto 120px;
padding:0 18px;
}
h2.section-title{
font-size:18px;
margin:6px 6px 18px;
font-weight:700;
}
/* activity list */
.activity-list{
display:flex;
flex-direction:column;
gap:14px;
max-width:720px;
margin:0 auto;
}
.activity-card{
display:flex;
align-items:flex-start;
justify-content:space-between;
gap:12px;
background:var(--card);
border-radius:12px;
padding:16px;
box-shadow:var(--soft-shadow);
border:1px solid rgba(10,20,18,0.03);
}
.left{
display:flex;
flex-direction:column;
gap:8px;
}
.title{font-weight:700;font-size:16px}
.meta{display:flex;align-items:center;gap:8px;color:var(--muted);font-size:13px}
.meta svg{opacity:0.9}
.badges{display:flex;gap:8px;margin-top:6px;flex-wrap:wrap}
.badge{
padding:6px 10px;border-radius:999px;font-weight:700;font-size:13px;
display:inline-flex;align-items:center;gap:8px;
}
.badge.nutri{background:#e9fff4;color:var(--green)}
.badge.eco{background:#e8f6ff;color:var(--accent)}
.right{
display:flex;
flex-direction:column;
align-items:flex-end;
gap:8px;
min-width:64px;
}
.points{
color:var(--gold);
font-weight:800;
display:flex;
align-items:center;
gap:6px;
font-size:16px;
}
.points .icon{
width:20px;height:20px;border-radius:6px;background:rgba(246,166,35,0.08);display:inline-flex;align-items:center;justify-content:center;color:var(--gold);
font-weight:700;font-size:13px;
}
/* bottom nav */
.bottom-nav{
position:fixed;
left:50%;
transform:translateX(-50%);
bottom:12px;
width:96%;
max-width:980px;
background:rgba(255,255,255,1);
border-radius:16px;
padding:8px 18px;
box-shadow:0 18px 40px rgba(12,30,25,0.06);
display:flex;
justify-content:space-around;
align-items:center;
gap:10px;
border:1px solid rgba(10,20,18,0.04);
}
.nav-item{display:flex;flex-direction:column;align-items:center;gap:6px;color:var(--muted);font-size:12px;text-decoration:none}
.nav-item.active{background:#e9fff4;padding:8px 12px;border-radius:12px;color:var(--green)}
/* small helpers */
.center{display:flex;align-items:center;justify-content:center}
@media (max-width:520px){
main{padding:0 12px}
}
</style>
</head>
<body>
<header class="hero" role="banner" aria-label="Page header">
<div class="container">
<div class="hero-head">
<div style="display:flex;align-items:center;gap:12px;">
<div style="width:44px;height:44px;border-radius:10px;background:rgba(255,255,255,0.14);display:flex;align-items:center;justify-content:center;font-weight:700;">📅</div>
<div>
<h1>Scan History</h1>
<div class="hero-sub">Track your sustainable choices</div>
</div>
</div>
</div>
<div class="stats-row" role="list" aria-label="Statistics">
<div class="stat" role="listitem" aria-label="Total scans">
<div style="font-size:18px;opacity:0.95">📈</div>
<div class="big" id="totalScans">47</div>
<div class="label">Total Scans</div>
</div>
<div class="stat" role="listitem" aria-label="Average carbon">
<div style="font-size:18px;opacity:0.95">🍃</div>
<div class="big" id="avgCarbon">--</div>
<div class="label">Avg CO2e</div>
</div>
<div class="stat" role="listitem" aria-label="Low-Carbon percentage">
<div style="font-size:18px;opacity:0.95">🏅</div>
<div class="big" id="lowCarbonPercent">--</div>
<div class="label">Low-Carbon</div>
</div>
</div>
</div>
</header>
<main role="main" class="container">
<h2 class="section-title">Recent Activity</h2>
<div class="activity-list" id="activityList" aria-live="polite">
<!-- JS will render cards here -->
</div>
</main>
<nav class="bottom-nav" role="navigation" aria-label="Main navigation">
<a href="Index.html" class="nav-item" aria-label="Home">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden><path d="M3 11.5L12 4l9 7.5" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path d="M5 21h14V11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span>Home</span>
</a>
<a href="scan.html" class="nav-item" aria-label="Scan">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden><rect x="3" y="3" width="7" height="7" rx="1.5" stroke="currentColor" stroke-width="1.4"/><rect x="14" y="14" width="7" height="7" rx="1.5" stroke="currentColor" stroke-width="1.4"/><path d="M21 3v7M3 21v-7" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>
<span>Scan</span>
</a>
<a href="history.html" class="nav-item active" aria-current="page" aria-label="History">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden><path d="M3 12a9 9 0 1 0 9-9" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 7v6l4 2" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span>History</span>
</a>
<a href="rewards.html" class="nav-item" aria-label="Rewards">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden><path d="M12 2l2.5 6L20 9l-5 3.8L16 20l-4-2.5L8 20l1-7.2L4 9l5.5-1L12 2z" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span>Rewards</span>
</a>
</nav>
<script>
const listEl = document.getElementById('activityList');
function createActivityCard(item, index){
const card = document.createElement('article');
card.className = 'activity-card';
card.tabIndex = 0;
// left
const left = document.createElement('div');
left.className = 'left';
const title = document.createElement('div');
title.className = 'title';
title.textContent = item.title;
const meta = document.createElement('div');
meta.className = 'meta';
meta.innerHTML = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" aria-hidden><path d="M7 10v6" stroke="#7a8a85" stroke-width="1.6" stroke-linecap="round"/><path d="M17 10v6" stroke="#7a8a85" stroke-width="1.6" stroke-linecap="round"/><path d="M12 3v4" stroke="#7a8a85" stroke-width="1.6" stroke-linecap="round"/></svg> ${item.time}`;
left.appendChild(title);
left.appendChild(meta);
// badges row
const badges = document.createElement('div');
badges.className = 'badges';
const nutri = document.createElement('span');
nutri.className = 'badge nutri';
nutri.textContent = 'Nutri ' + item.nutri;
const eco = document.createElement('span');
eco.className = 'badge eco';
eco.textContent = item.eco;
badges.appendChild(nutri);
badges.appendChild(eco);
if (typeof item.carbon === 'number'){
const c = document.createElement('span');
c.className = 'badge';
c.style.background = '#fff5e6';
c.style.color = '#9a6b00';
c.textContent = `${item.carbon.toFixed(2)} kg CO2e`;
badges.appendChild(c);
}
left.appendChild(badges);
// right
const right = document.createElement('div');
right.className = 'right';
const points = document.createElement('div');
points.className = 'points';
points.innerHTML = `<span class="icon">🏅</span> +${item.points}`;
right.appendChild(points);
const delBtn = document.createElement('button');
delBtn.textContent = 'Delete';
delBtn.setAttribute('aria-label','Delete');
delBtn.style.cssText = 'border:0;background:#f7f7f7;color:#666;border-radius:8px;padding:6px 10px;cursor:pointer;';
delBtn.addEventListener('click', (ev) => { ev.stopPropagation(); deleteHistory(index); });
right.appendChild(delBtn);
card.appendChild(left);
card.appendChild(right);
// click handler to view detail (demo)
card.addEventListener('click', () => {
alert(item.title + "\\n\\n" + "Nutrition: " + item.nutri + "\\nEco: " + item.eco + "\\nPoints: +" + item.points + "\\n\\n(Detail view demo)");
});
return card;
}
function renderList(){
listEl.innerHTML = '';
let items = [];
try{
items = JSON.parse(localStorage.getItem('historyScans')||'[]');
}catch(e){ items = []; }
if (!items.length) {
// fallback to small demo list for first load
items = [
{ title: "Organic Apples", time: "Today, 14:30", nutri: "A", eco: "Eco A", points: 15 },
{ title: "Almond Milk", time: "Yesterday, 18:45", nutri: "A", eco: "Eco C", points: 10 }
];
}
items.forEach((a, i) => listEl.appendChild(createActivityCard(a, i)));
// update totals
document.getElementById('totalScans').textContent = items.length;
const withCarbon = items.filter(i => typeof i.carbon === 'number');
if (withCarbon.length){
const avg = withCarbon.reduce((s,i)=>s + i.carbon, 0) / withCarbon.length;
document.getElementById('avgCarbon').textContent = avg.toFixed(2) + ' kg';
const low = withCarbon.filter(i => i.carbon <= 0.7).length;
const pct = Math.round((low/withCarbon.length)*100);
document.getElementById('lowCarbonPercent').textContent = pct + '%';
} else {
document.getElementById('avgCarbon').textContent = '--';
document.getElementById('lowCarbonPercent').textContent = '--';
}
}
function deleteHistory(index){
const items = JSON.parse(localStorage.getItem('historyScans')||'[]');
if (index>=0 && index<items.length) {
items.splice(index,1);
localStorage.setItem('historyScans', JSON.stringify(items));
renderList();
}
}
// init
renderList();
</script>
</body>
</html>