-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery.js
More file actions
173 lines (141 loc) · 5.5 KB
/
gallery.js
File metadata and controls
173 lines (141 loc) · 5.5 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
// script.js - Lógica principal da galeria FlowSketch
// Agora carrega dados do images.js
// Array para armazenar obras em memória (mais recentes primeiro)
let artworks = [];
// Função para formatar data
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('pt-BR');
}
// Função para adicionar nova obra
function addArtwork(artworkData) {
// Adiciona no INÍCIO do array (mais recentes primeiro)
artworks.unshift(artworkData);
console.log(`✅ Nova obra adicionada: "${artworkData.title}" por ${artworkData.artist}`);
renderGallery();
}
// Função para renderizar galeria
function renderGallery() {
const gallery = document.getElementById('gallery');
if (!gallery) {
console.error('❌ Elemento #gallery não encontrado!');
return;
}
if (artworks.length === 0) {
gallery.innerHTML = `
<div class="gallery-empty">
<h3>🎨 Empty Gallery</h3>
<p>Download and install the extension in your browser and start creating—or flowing :D</p>
</div>
`;
return;
}
// Limpa galeria
gallery.innerHTML = '';
console.log(`🖼️ Rendering ${artworks.length} works...`);
// Renderiza cada obra (mais recentes primeiro)
artworks.forEach((artwork, index) => {
const artworkElement = document.createElement('div');
artworkElement.className = 'artwork';
artworkElement.setAttribute('data-artwork-id', index);
artworkElement.innerHTML = `
<div class="artwork-image-container">
<img src="${artwork.image}"
alt="${artwork.title}"
loading="lazy"
onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgdmlld0JveD0iMCAwIDQwMCAzMDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSI0MDAiIGhlaWdodD0iMzAwIiBmaWxsPSIjRjVGNUY1Ii8+CjxwYXRoIGQ9Ik0yMDAgMTAwVjIwME0xNTAgMTUwSDI1MCIgc3Ryb2tlPSIjQ0NDIiBzdHJva2Utd2lkdGg9IjIiLz4KPHRleHQgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE2IiBmaWxsPSIjOTk5IiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiB4PSIyMDAiIHk9IjI0MCI+SW1hZ2VtIG7Do28gZW5jb250cmFkYTwvdGV4dD4KPC9zdmc+'; this.alt='Imagem não encontrada';">
</div>
<div class="artwork-info">
<div class="artwork-title">${artwork.title}</div>
<div class="artwork-artist">por ${artwork.artist}</div>
<div class="artwork-date">${formatDate(artwork.date)}</div>
<div class="artwork-stats">${artwork.points.toLocaleString()} Movement points</div>
</div>
`;
// Adiciona animação suave
artworkElement.style.opacity = '0';
artworkElement.style.transform = 'translateY(20px)';
gallery.appendChild(artworkElement);
// Anima entrada
setTimeout(() => {
artworkElement.style.transition = 'all 0.5s ease';
artworkElement.style.opacity = '1';
artworkElement.style.transform = 'translateY(0)';
}, index * 100); // Delay escalonado
});
console.log(`✅ Gallery successfully rendered!`);
}
// Função para carregar obras do images.js
function loadImagesFromDatabase() {
if (typeof window.FlowSketchImages === 'undefined') {
console.error('❌ images.js It did not load! Please check if the file is included in the HTML.');
return;
}
console.log(`📂 Loading ${window.FlowSketchImages.length} database works...`);
// Limpa array atual
artworks = [];
// Carrega todas as obras do images.js
// Já estão em ordem cronológica (mais recentes primeiro)
window.FlowSketchImages.forEach(artwork => {
artworks.push({
title: artwork.title,
artist: artwork.artist,
date: artwork.date,
points: artwork.points,
image: artwork.image
});
});
console.log(`✅ ${artworks.length} works successfully uploaded!`);
renderGallery();
}
// Função para recarregar dados (útil quando images.js é atualizado)
function reloadGallery() {
console.log('🔄 Reloading gallery...');
loadImagesFromDatabase();
}
// Inicialização quando DOM estiver pronto
document.addEventListener('DOMContentLoaded', function() {
console.log('🎨 FlowSketch Gallery starting up...');
// Aguarda um pouco para garantir que images.js foi carregado
setTimeout(() => {
loadImagesFromDatabase();
}, 100);
});
// API pública para extensão e integrações externas
window.FlowSketchGallery = {
// Adiciona nova obra programaticamente
addArtwork: addArtwork,
// Obtém todas as obras carregadas
getArtworks: () => [...artworks], // Retorna cópia do array
// Re-renderiza galeria
renderGallery: renderGallery,
// Recarrega do banco de dados
reloadGallery: reloadGallery,
// Limpa galeria (apenas visual)
clearGallery: () => {
artworks = [];
renderGallery();
},
// Estatísticas
getStats: () => ({
total: artworks.length,
totalPoints: artworks.reduce((sum, art) => sum + art.points, 0),
artists: [...new Set(artworks.map(art => art.artist))].length,
latestDate: artworks.length > 0 ? artworks[0].date : null
})
};
// Debug: expõe no console para facilitar testes
window.FlowSketchDebug = {
artworks: () => artworks,
reloadImages: () => {
// Força reload do images.js
const script = document.createElement('script');
script.src = 'images.js?v=' + Date.now();
document.head.appendChild(script);
script.onload = () => {
console.log('🔄 images.js recarregado!');
loadImagesFromDatabase();
};
}
};
console.log('📱 Script.js loaded! Use FlowSketchGallery.* to interact with the gallery.');