-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotos.html
More file actions
534 lines (474 loc) · 13.3 KB
/
Copy pathphotos.html
File metadata and controls
534 lines (474 loc) · 13.3 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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title id="pageTabTitle">Cousinade — Photos</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@500;700&display=swap" rel="stylesheet">
<style>
:root{
--cream:#FBEAD2;
--ink:#291A0C;
--ink-soft:#9A7F63;
--red:#E63946;
--orange:#FF7A1A;
--coral:#FF6B4A;
--coral-dark:#E8562F;
--gold:#FFB627;
--olive:#6E7E32;
--purple:#A6415C;
--line:#F0DDBF;
--head:#FBEAD2;
}
*{box-sizing:border-box;}
body{
margin:0;
background:var(--cream);
color:var(--ink);
font-family:Arial, Helvetica, sans-serif;
padding:32px 16px 60px;
}
.wrap{max-width:900px;margin:0 auto;}
.site-logo{
display:block;
width:150px;
height:150px;
margin:0 auto 10px;
border-radius:50%;
box-shadow:0 8px 24px rgba(41,26,12,0.15);
}
.title-row{
display:flex;
align-items:center;
justify-content:center;
gap:12px;
text-align:center;
}
h1{
font-family:'Fredoka', Arial, sans-serif;
font-size:52px;
font-weight:700;
margin:0;
letter-spacing:.01em;
color:var(--coral);
}
.flame{font-size:36px;}
.sub{
text-align:center;
color:var(--ink-soft);
font-size:15px;
font-weight:bold;
margin:10px 0 20px;
}
.nav-tabs{
display:flex;
justify-content:center;
gap:10px;
flex-wrap:wrap;
margin-bottom:24px;
}
.nav-tab{
display:inline-flex;
align-items:center;
gap:6px;
padding:8px 18px;
border-radius:999px;
background:#fff;
color:var(--ink-soft);
font-weight:bold;
font-size:13px;
text-decoration:none;
box-shadow:0 4px 14px rgba(41,26,12,0.08);
transition:background .15s, color .15s;
}
.nav-tab:hover{background:var(--head);}
.nav-tab.active{background:var(--coral);color:#fff;}
.year-picker{
display:flex;
align-items:center;
justify-content:center;
gap:10px;
margin-bottom:22px;
flex-wrap:wrap;
}
.year-picker label{
font-weight:bold;
font-size:13px;
color:var(--ink-soft);
}
.year-picker select{
padding:9px 14px;
border:1px solid var(--line);
border-radius:999px;
font-size:14px;
font-family:inherit;
font-weight:bold;
background:#fff;
color:var(--ink);
}
.upload-card{
background:#fff;
border-radius:20px;
padding:18px;
margin-bottom:24px;
box-shadow:0 8px 24px rgba(41,26,12,0.08);
text-align:center;
}
.upload-card input[type="file"]{
display:none;
}
.upload-label{
display:inline-flex;
align-items:center;
gap:8px;
background:var(--coral);
color:#fff;
border:none;
padding:10px 26px;
border-radius:999px;
font-size:14px;
font-weight:bold;
cursor:pointer;
box-shadow:0 4px 14px rgba(255,107,74,0.4);
transition:transform .15s, box-shadow .15s, background .15s;
}
.upload-label:hover{
background:var(--coral-dark);
transform:translateY(-1px);
box-shadow:0 6px 18px rgba(255,107,74,0.5);
}
.upload-hint{
color:var(--ink-soft);
font-size:12px;
margin-top:10px;
}
.gallery{
display:grid;
grid-template-columns:repeat(auto-fill, minmax(150px, 1fr));
gap:12px;
}
.photo-card{
position:relative;
aspect-ratio:1;
border-radius:14px;
overflow:hidden;
background:#fff;
box-shadow:0 6px 18px rgba(41,26,12,0.10);
cursor:pointer;
}
.photo-card img{
width:100%;
height:100%;
object-fit:cover;
display:block;
}
.photo-del{
position:absolute;
top:6px;
right:6px;
width:28px;
height:28px;
border-radius:50%;
background:rgba(41,26,12,0.55);
color:#fff;
border:none;
font-size:15px;
cursor:pointer;
display:flex;
align-items:center;
justify-content:center;
opacity:0;
transition:opacity .15s, background .15s;
}
.photo-card:hover .photo-del{opacity:1;}
.photo-del:hover{background:var(--red);}
.empty-gallery{
text-align:center;
color:var(--ink-soft);
font-style:italic;
padding:40px 14px;
background:#fff;
border-radius:20px;
box-shadow:0 8px 24px rgba(41,26,12,0.08);
}
.lightbox{
position:fixed;
inset:0;
background:rgba(20,12,6,0.85);
display:none;
align-items:center;
justify-content:center;
padding:24px;
z-index:100;
}
.lightbox.show{display:flex;}
.lightbox img{
max-width:100%;
max-height:100%;
border-radius:12px;
}
.lightbox-close{
position:absolute;
top:20px;
right:24px;
color:#fff;
font-size:28px;
background:none;
border:none;
cursor:pointer;
}
.status{
position:fixed;
bottom:18px;
left:50%;
transform:translateX(-50%);
background:var(--ink);
color:#fff;
font-size:12px;
padding:8px 16px;
border-radius:20px;
opacity:0;
transition:opacity .25s;
z-index:200;
}
.status.show{opacity:1;}
footer{
text-align:center;
margin-top:24px;
color:var(--ink-soft);
font-size:12px;
}
.credit{
display:inline-flex;
align-items:center;
gap:6px;
margin-top:10px;
color:var(--ink-soft);
font-size:13px;
text-decoration:none;
}
.credit:hover .credit-des{color:var(--ink);}
.credit:hover .credit-codes{color:var(--coral-dark);}
.credit-logo{display:inline-flex;align-items:center;}
.credit-icon{
color:var(--coral);
font-weight:bold;
font-family:'Courier New', monospace;
margin-right:4px;
}
.credit-des{font-weight:bold;letter-spacing:.02em;color:var(--ink-soft);}
.credit-codes{font-weight:bold;letter-spacing:.02em;color:var(--coral);}
@media (max-width: 640px){
body{padding:20px 12px 60px;}
.site-logo{width:110px;height:110px;}
h1{font-size:34px;}
.flame{font-size:26px;}
.title-row{gap:8px;}
.sub{font-size:13px;}
.gallery{grid-template-columns:repeat(auto-fill, minmax(105px, 1fr));gap:8px;}
}
</style>
</head>
<body>
<div class="wrap">
<img src="images/logo-cousinade.png" alt="Cousinade — La grande famille" class="site-logo">
<div class="title-row">
<span class="flame">📸</span>
<h1>Photos</h1>
<span class="flame">📸</span>
</div>
<div class="sub">Les souvenirs de la Cousinade</div>
<div class="nav-tabs">
<a href="index.html" class="nav-tab">🏠 Accueil</a>
<a href="archive.html" class="nav-tab">🗄️ Archives</a>
<a href="photos.html" class="nav-tab active">📸 Photos</a>
</div>
<div class="year-picker">
<label for="yearSelect">Édition :</label>
<select id="yearSelect"></select>
</div>
<div class="upload-card">
<label class="upload-label" for="fileInput">📤 Ajouter des photos</label>
<input type="file" id="fileInput" accept="image/*" multiple>
<div class="upload-hint">Visibles par tous, immédiatement.</div>
</div>
<div id="gallery" class="gallery"></div>
<footer>
<div>Les photos sont partagées entre tous les cousins et cousines.</div>
<a class="credit" href="https://www.descodes.com" target="_blank" rel="noopener noreferrer">Créé par <span class="credit-logo"><span class="credit-icon"></></span><span class="credit-des">DES</span><span class="credit-codes">CODES</span></span></a>
</footer>
</div>
<div class="lightbox" id="lightbox">
<button class="lightbox-close" id="lightboxClose" aria-label="Fermer">✕</button>
<img id="lightboxImg" src="" alt="Photo en grand">
</div>
<div class="status" id="status"></div>
<script>
const SUPABASE_URL = "https://ejgmecoqzejdtuwfzwia.supabase.co";
const SUPABASE_KEY = "sb_publishable_C6pCeS5t1h27nIJK4MVuLA_HEuw7pI4";
const BUCKET = "photos";
let CURRENT_YEAR = null;
let selectedYear = null;
function showStatus(msg){
const el = document.getElementById("status");
el.textContent = msg;
el.classList.add("show");
clearTimeout(el._t);
el._t = setTimeout(() => el.classList.remove("show"), 1800);
}
async function restFetch(path){
const res = await fetch(`${SUPABASE_URL}/rest/v1/${path}`, {
headers: {
"apikey": SUPABASE_KEY,
"Authorization": `Bearer ${SUPABASE_KEY}`,
"Content-Type": "application/json"
}
});
if(!res.ok) throw new Error(`Supabase error ${res.status}`);
return res.json();
}
async function loadCurrentYear(){
try{
const rows = await restFetch("app_settings?key=eq.current_year&select=value");
CURRENT_YEAR = rows && rows[0] ? parseInt(rows[0].value, 10) : new Date().getFullYear();
}catch(e){
CURRENT_YEAR = new Date().getFullYear();
}
}
async function loadYearOptions(){
const select = document.getElementById("yearSelect");
let years = [];
try{
const rows = await restFetch("entries?select=year");
years = [...new Set(rows.map(r => r.year))];
}catch(e){}
if(!years.includes(CURRENT_YEAR)) years.push(CURRENT_YEAR);
years.sort((a, b) => b - a);
select.innerHTML = years.map(y =>
`<option value="${y}">${y}${y === CURRENT_YEAR ? " (édition en cours)" : ""}</option>`
).join("");
select.value = CURRENT_YEAR;
selectedYear = CURRENT_YEAR;
}
function publicUrl(name){
return `${SUPABASE_URL}/storage/v1/object/public/${BUCKET}/${selectedYear}/${encodeURIComponent(name)}`;
}
async function loadGallery(){
const gallery = document.getElementById("gallery");
gallery.innerHTML = `<div class="empty-gallery">Chargement…</div>`;
let storagePhotos = [];
let linkedPhotos = [];
try{
const res = await fetch(`${SUPABASE_URL}/storage/v1/object/list/${BUCKET}`, {
method: "POST",
headers: {
"apikey": SUPABASE_KEY,
"Authorization": `Bearer ${SUPABASE_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
prefix: `${selectedYear}/`,
limit: 200,
sortBy: { column: "created_at", order: "desc" }
})
});
if(res.ok){
storagePhotos = (await res.json()).filter(f => f.id).map(f => ({
type: "storage", name: f.name, url: publicUrl(f.name)
}));
}
}catch(e){}
try{
const rows = await restFetch(`photo_links?year=eq.${selectedYear}&select=id,url&order=created_at.asc`);
linkedPhotos = rows.map(r => ({ type: "link", id: r.id, url: r.url }));
}catch(e){}
const allPhotos = [...linkedPhotos, ...storagePhotos];
if(allPhotos.length === 0){
gallery.innerHTML = `<div class="empty-gallery">Aucune photo pour ${selectedYear} pour l'instant.</div>`;
return;
}
gallery.innerHTML = allPhotos.map(p => `
<div class="photo-card">
<img src="${p.url}" alt="Photo Cousinade ${selectedYear}" loading="lazy">
${p.type === "storage" ? `<button class="photo-del" data-name="${p.name}" aria-label="Supprimer">✕</button>` : ""}
</div>
`).join("");
gallery.querySelectorAll(".photo-card img").forEach(img => {
img.addEventListener("click", () => openLightbox(img.src));
});
gallery.querySelectorAll(".photo-del").forEach(btn => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
deletePhoto(btn.dataset.name);
});
});
}
async function uploadFiles(fileList){
const files = Array.from(fileList);
if(files.length === 0) return;
let okCount = 0;
for(const file of files){
const safeName = file.name.replace(/[^a-zA-Z0-9.\-_]/g, "_");
const objectName = `${Date.now()}-${Math.random().toString(36).slice(2, 7)}-${safeName}`;
try{
const res = await fetch(`${SUPABASE_URL}/storage/v1/object/${BUCKET}/${selectedYear}/${objectName}`, {
method: "POST",
headers: {
"apikey": SUPABASE_KEY,
"Authorization": `Bearer ${SUPABASE_KEY}`,
"Content-Type": file.type || "application/octet-stream"
},
body: file
});
if(res.ok) okCount++;
}catch(e){}
}
showStatus(okCount === files.length ? "Photos ajoutées" : `${okCount}/${files.length} photos ajoutées`);
loadGallery();
}
async function deletePhoto(name){
try{
const res = await fetch(`${SUPABASE_URL}/storage/v1/object/${BUCKET}/${selectedYear}/${name}`, {
method: "DELETE",
headers: {
"apikey": SUPABASE_KEY,
"Authorization": `Bearer ${SUPABASE_KEY}`
}
});
if(!res.ok) throw new Error();
showStatus("Photo supprimée");
loadGallery();
}catch(e){
showStatus("Erreur de suppression");
}
}
function openLightbox(src){
document.getElementById("lightboxImg").src = src;
document.getElementById("lightbox").classList.add("show");
}
function closeLightbox(){
document.getElementById("lightbox").classList.remove("show");
}
document.getElementById("fileInput").addEventListener("change", (e) => {
uploadFiles(e.target.files);
e.target.value = "";
});
document.getElementById("yearSelect").addEventListener("change", (e) => {
selectedYear = e.target.value;
loadGallery();
});
document.getElementById("lightboxClose").addEventListener("click", closeLightbox);
document.getElementById("lightbox").addEventListener("click", (e) => {
if(e.target.id === "lightbox") closeLightbox();
});
(async () => {
await loadCurrentYear();
document.getElementById("pageTabTitle").textContent = `Cousinade ${CURRENT_YEAR} — Photos`;
await loadYearOptions();
loadGallery();
})();
</script>
</body>
</html>