-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
339 lines (308 loc) · 9.62 KB
/
index.html
File metadata and controls
339 lines (308 loc) · 9.62 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>BeanVault ☕</title>
<style>
:root {
--bg: #1e1e1e;
--fg: #f5f5f5;
--accent: #c28f42;
}
* {
box-sizing: border-box;
}
body {
background: var(--bg);
color: var(--fg);
font-family: 'Arial', sans-serif;
margin: 0;
padding: 1rem;
}
header {
text-align: center;
margin-bottom: 1rem;
}
.logo {
width: 60px;
height: 60px;
border-radius: 50%;
background: var(--accent);
display: inline-block;
margin-bottom: 0.5rem;
}
h1 {
margin: 0;
color: var(--accent);
}
form, .edit-form {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-bottom: 2rem;
}
input, textarea, select, button {
padding: 0.75rem;
border: none;
border-radius: 5px;
font-size: 1rem;
}
input, textarea, select {
background: #2a2a2a;
color: white;
}
button {
background: var(--accent);
color: #000;
font-weight: bold;
cursor: pointer;
}
.preview-img {
max-width: 100%;
max-height: 200px;
margin-top: 0.5rem;
border-radius: 8px;
}
.log-container {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
}
@media (min-width: 600px) {
.log-container {
grid-template-columns: 1fr 1fr;
}
}
.card-wrapper {
display: flex;
justify-content: center;
}
.card {
width: 225px;
height: 300px;
background: #000;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 0 10px rgba(0,0,0,0.4);
}
.bean-card {
width: 100%;
height: 100%;
object-fit: cover;
}
.card-details {
padding: 1rem 0.5rem 0.5rem;
text-align: center;
}
.card-details h3 {
margin: 0;
font-size: 1rem;
color: var(--accent);
}
.edit-view {
display: none;
flex-direction: column;
gap: 1rem;
padding: 1rem;
}
.hidden {
display: none !important;
}
.full-width {
width: 100%;
}
</style>
</head>
<body>
<header>
<div class="logo"></div>
<h1>BeanVault ☕</h1>
</header>
<!-- Main View -->
<div id="mainView">
<form id="coffeeForm">
<input type="text" id="coffeeName" placeholder="Coffee Name" required />
<input type="text" id="roaster" placeholder="Roaster" />
<input type="text" id="origin" placeholder="Origin (e.g., Ethiopia)" required />
<select id="brewMethod">
<option value="">Select Brew Method</option>
<option>Pour-Over</option>
<option>Espresso</option>
<option>Drip</option>
<option>French Press</option>
<option>AeroPress</option>
<option>Cold Brew</option>
</select>
<select id="rating">
<option value="">Rating</option>
<option>☕</option>
<option>☕☕</option>
<option>☕☕☕</option>
<option>☕☕☕☕</option>
<option>☕☕☕☕☕</option>
</select>
<textarea id="notes" placeholder="Tasting notes, vibe, etc."></textarea>
<label>
<input type="checkbox" id="buyAgain" />
Would Buy Again?
</label>
<input type="file" id="imageUpload" accept="image/*" />
<img id="preview" class="preview-img" style="display:none;" />
<button type="submit">Add Coffee</button>
</form>
<div id="logContainer" class="log-container"></div>
</div>
<!-- Edit View -->
<div id="editView" class="edit-view"></div>
<script>
const form = document.getElementById('coffeeForm');
const preview = document.getElementById('preview');
const logContainer = document.getElementById('logContainer');
const mainView = document.getElementById('mainView');
const editView = document.getElementById('editView');
let uploadedImageData = '';
let editingIndex = null;
document.getElementById('imageUpload').addEventListener('change', function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (e) {
const img = new Image();
img.onload = function () {
const canvas = document.createElement('canvas');
const TARGET_WIDTH = 500;
const aspect = img.width / img.height;
canvas.width = TARGET_WIDTH;
canvas.height = TARGET_WIDTH / aspect;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
uploadedImageData = canvas.toDataURL('image/jpeg', 0.85);
preview.src = uploadedImageData;
preview.style.display = 'block';
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
});
function renderCard(entry, index) {
const wrapper = document.createElement('div');
wrapper.className = 'card-wrapper';
const card = document.createElement('div');
card.className = 'card';
const image = document.createElement('img');
image.src = entry.image;
image.className = 'bean-card';
const details = document.createElement('div');
details.className = 'card-details';
details.innerHTML = `
<h3>${entry.name}</h3>
<p>${entry.origin}</p>
<p>${entry.method} | ${entry.rating}</p>
<p>${entry.notes || ''}</p>
<p>${entry.buyAgain ? '✅' : '❌'} Would Buy Again</p>
<button onclick="editCard(${index})" class="full-width">Edit</button>
`;
card.appendChild(image);
card.appendChild(details);
wrapper.appendChild(card);
return wrapper;
}
function loadLog() {
const log = JSON.parse(localStorage.getItem('coffeeLog') || '[]');
logContainer.innerHTML = '';
log.reverse().forEach((entry, i) => {
const actualIndex = log.length - 1 - i;
const card = renderCard(entry, actualIndex);
logContainer.appendChild(card);
});
}
function editCard(index) {
const log = JSON.parse(localStorage.getItem('coffeeLog') || '[]');
const entry = log[index];
editingIndex = index;
mainView.classList.add('hidden');
editView.classList.remove('hidden');
editView.innerHTML = `
<h2>Edit Coffee</h2>
<form onsubmit="saveEdit(event)" class="edit-form">
<input type="text" name="name" value="${entry.name}" required />
<input type="text" name="origin" value="${entry.origin}" required />
<input type="text" name="roaster" value="${entry.roaster || ''}" />
<select name="method" required>
${['Pour-Over','Espresso','Drip','French Press','AeroPress','Cold Brew'].map(opt => `
<option ${opt === entry.method ? 'selected' : ''}>${opt}</option>`).join('')}
</select>
<select name="rating" required>
${['☕','☕☕','☕☕☕','☕☕☕☕','☕☕☕☕☕'].map(opt => `
<option ${opt === entry.rating ? 'selected' : ''}>${opt}</option>`).join('')}
</select>
<textarea name="notes">${entry.notes || ''}</textarea>
<label><input type="checkbox" name="buyAgain" ${entry.buyAgain ? 'checked' : ''}/> Would Buy Again?</label>
<button type="submit">Save</button>
<button type="button" onclick="cancelEdit()" style="background:#444;color:white;">Cancel</button>
</form>
`;
}
function saveEdit(e) {
e.preventDefault();
const form = e.target;
const log = JSON.parse(localStorage.getItem('coffeeLog') || '[]');
log[editingIndex] = {
...log[editingIndex],
name: form.name.value.trim(),
origin: form.origin.value.trim(),
roaster: form.roaster.value.trim(),
method: form.method.value,
rating: form.rating.value,
notes: form.notes.value.trim(),
buyAgain: form.buyAgain.checked
};
localStorage.setItem('coffeeLog', JSON.stringify(log));
editingIndex = null;
editView.classList.add('hidden');
mainView.classList.remove('hidden');
loadLog();
}
function cancelEdit() {
editingIndex = null;
editView.classList.add('hidden');
mainView.classList.remove('hidden');
}
form.addEventListener('submit', async e => {
e.preventDefault();
const name = document.getElementById('coffeeName').value.trim();
const origin = document.getElementById('origin').value.trim();
const method = document.getElementById('brewMethod').value;
const rating = document.getElementById('rating').value;
if (!name || !origin || !method || !rating) {
alert('Please fill out all required fields.');
return;
}
const entry = {
name,
roaster: document.getElementById('roaster').value.trim(),
origin,
method,
rating,
notes: document.getElementById('notes').value.trim(),
image: uploadedImageData || '',
buyAgain: document.getElementById('buyAgain').checked
};
try {
const log = JSON.parse(localStorage.getItem('coffeeLog') || '[]');
log.push(entry);
localStorage.setItem('coffeeLog', JSON.stringify(log));
form.reset();
uploadedImageData = '';
preview.style.display = 'none';
loadLog();
} catch (err) {
console.error('Failed to add coffee:', err);
alert('Something went wrong while saving. Try again.');
}
});
loadLog();
</script>
</body>
</html>