codebybrody commited on
Commit
92fa1bd
·
verified ·
1 Parent(s): 2b76b81

Upload 56 files

Browse files
Files changed (2) hide show
  1. App.tsx +99 -14
  2. components/DataForm.tsx +29 -16
App.tsx CHANGED
@@ -4,7 +4,7 @@ import { Card } from './components/Card';
4
  import { DataForm } from './components/DataForm';
5
  import { DetailView } from './components/DetailView';
6
  import { Button } from './components/Button';
7
- import { Plus, Search, Layers, Loader2, WifiOff, Settings, Code, Type, Clock, Calendar, Shuffle } from 'lucide-react';
8
  import { subscribeToItems, addItem, updateItem, deleteItem } from './services/firebase';
9
  import { subscribeToStyleConfig } from './services/codeStyleService';
10
 
@@ -23,6 +23,8 @@ const App: React.FC = () => {
23
  return 'normal';
24
  });
25
  const [isSettingsOpen, setIsSettingsOpen] = useState(false);
 
 
26
 
27
  useEffect(() => {
28
  if (typeof window !== 'undefined') {
@@ -200,6 +202,88 @@ const App: React.FC = () => {
200
 
201
  }, [items, searchQuery, sortOrder]);
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  const handleCreate = async (data: Omit<DataItem, 'id' | 'createdAt'>) => {
204
  try {
205
  await addItem(data);
@@ -401,19 +485,20 @@ const App: React.FC = () => {
401
  <p className="text-gray-500 mt-2">El repositorio está vacío o no hay coincidencias.</p>
402
  </div>
403
  ) : (
404
- <div
405
- className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3"
406
- >
407
- {filteredItems.map(item => (
408
- <Card
409
- key={item.id}
410
- item={item}
411
- onClick={(i) => { setSelectedItem(i); setView('DETAIL'); }}
412
- />
413
- ))}
414
- </div>
415
- )}
416
- </>
 
417
  )}
418
 
419
  {view === 'CREATE' && (
 
4
  import { DataForm } from './components/DataForm';
5
  import { DetailView } from './components/DetailView';
6
  import { Button } from './components/Button';
7
+ import { Plus, Search, Layers, Loader2, WifiOff, Settings, Code, Type, Clock, Calendar, Shuffle, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight } from 'lucide-react';
8
  import { subscribeToItems, addItem, updateItem, deleteItem } from './services/firebase';
9
  import { subscribeToStyleConfig } from './services/codeStyleService';
10
 
 
23
  return 'normal';
24
  });
25
  const [isSettingsOpen, setIsSettingsOpen] = useState(false);
26
+ const [currentPage, setCurrentPage] = useState(1);
27
+ const ITEMS_PER_PAGE = 20;
28
 
29
  useEffect(() => {
30
  if (typeof window !== 'undefined') {
 
202
 
203
  }, [items, searchQuery, sortOrder]);
204
 
205
+ // Reset to first page when search or sort changes
206
+ useEffect(() => {
207
+ setCurrentPage(1);
208
+ }, [searchQuery, sortOrder]);
209
+
210
+ const paginatedItems = useMemo(() => {
211
+ const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
212
+ return filteredItems.slice(startIndex, startIndex + ITEMS_PER_PAGE);
213
+ }, [filteredItems, currentPage]);
214
+
215
+ const totalPages = Math.ceil(filteredItems.length / ITEMS_PER_PAGE);
216
+
217
+ const renderPagination = () => {
218
+ if (totalPages <= 1) return null;
219
+
220
+ const pages = [];
221
+ const maxVisiblePages = 5;
222
+
223
+ let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
224
+ let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
225
+
226
+ if (endPage - startPage + 1 < maxVisiblePages) {
227
+ startPage = Math.max(1, endPage - maxVisiblePages + 1);
228
+ }
229
+
230
+ for (let i = startPage; i <= endPage; i++) {
231
+ pages.push(
232
+ <button
233
+ key={i}
234
+ onClick={() => { setCurrentPage(i); window.scrollTo({ top: 0, behavior: 'smooth' }); }}
235
+ className={`w-10 h-10 flex items-center justify-center rounded-xl font-medium transition-colors ${
236
+ currentPage === i
237
+ ? 'bg-primary text-background'
238
+ : 'bg-surface hover:bg-white/10 text-gray-400 hover:text-white'
239
+ }`}
240
+ >
241
+ {i}
242
+ </button>
243
+ );
244
+ }
245
+
246
+ return (
247
+ <div className="flex items-center justify-center gap-2 mt-12 mb-8 animate-fade-in">
248
+ <button
249
+ onClick={() => { setCurrentPage(1); window.scrollTo({ top: 0, behavior: 'smooth' }); }}
250
+ disabled={currentPage === 1}
251
+ className="w-10 h-10 flex items-center justify-center rounded-xl bg-surface hover:bg-white/10 text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
252
+ >
253
+ <ChevronsLeft size={18} />
254
+ </button>
255
+ <button
256
+ onClick={() => { setCurrentPage(prev => Math.max(1, prev - 1)); window.scrollTo({ top: 0, behavior: 'smooth' }); }}
257
+ disabled={currentPage === 1}
258
+ className="w-10 h-10 flex items-center justify-center rounded-xl bg-surface hover:bg-white/10 text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
259
+ >
260
+ <ChevronLeft size={18} />
261
+ </button>
262
+
263
+ {pages}
264
+
265
+ {endPage < totalPages && (
266
+ <span className="text-gray-500 px-1">...</span>
267
+ )}
268
+
269
+ <button
270
+ onClick={() => { setCurrentPage(prev => Math.min(totalPages, prev + 1)); window.scrollTo({ top: 0, behavior: 'smooth' }); }}
271
+ disabled={currentPage === totalPages}
272
+ className="w-10 h-10 flex items-center justify-center rounded-xl bg-surface hover:bg-white/10 text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
273
+ >
274
+ <ChevronRight size={18} />
275
+ </button>
276
+ <button
277
+ onClick={() => { setCurrentPage(totalPages); window.scrollTo({ top: 0, behavior: 'smooth' }); }}
278
+ disabled={currentPage === totalPages}
279
+ className="w-10 h-10 flex items-center justify-center rounded-xl bg-surface hover:bg-white/10 text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
280
+ >
281
+ <ChevronsRight size={18} />
282
+ </button>
283
+ </div>
284
+ );
285
+ };
286
+
287
  const handleCreate = async (data: Omit<DataItem, 'id' | 'createdAt'>) => {
288
  try {
289
  await addItem(data);
 
485
  <p className="text-gray-500 mt-2">El repositorio está vacío o no hay coincidencias.</p>
486
  </div>
487
  ) : (
488
+ <>
489
+ <div
490
+ className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-3"
491
+ >
492
+ {paginatedItems.map(item => (
493
+ <Card
494
+ key={item.id}
495
+ item={item}
496
+ onClick={(i) => { setSelectedItem(i); setView('DETAIL'); }}
497
+ />
498
+ ))}
499
+ </div>
500
+ {renderPagination()}
501
+ </>
502
  )}
503
 
504
  {view === 'CREATE' && (
components/DataForm.tsx CHANGED
@@ -6,31 +6,38 @@ import { Save, X, Link as LinkIcon, Download, Hash, Sparkles } from 'lucide-reac
6
 
7
  interface DataFormProps {
8
  initialData?: DataItem | null;
9
- onSave: (data: Omit<DataItem, 'id' | 'createdAt'>) => void;
10
  onCancel: () => void;
11
  }
12
 
13
  export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCancel }) => {
14
  const [title, setTitle] = useState(initialData?.title || '');
15
- const [icon, setIcon] = useState(initialData?.icon || '');
16
  const [summary, setSummary] = useState(initialData?.summary || '');
17
  const [downloadUrl, setDownloadUrl] = useState(initialData?.downloadUrl || '');
18
  const [visitUrl, setVisitUrl] = useState(initialData?.visitUrl || '');
19
  const [tagsString, setTagsString] = useState(initialData?.tags.join(', ') || '');
 
20
 
21
- const handleSubmit = (e: React.FormEvent) => {
22
  e.preventDefault();
 
 
 
23
 
24
- // We only save the metadata here. Blocks are managed independently in DetailView.
25
- onSave({
26
- icon: icon || undefined,
27
- title,
28
- content: "", // Legacy
29
- summary,
30
- downloadUrl: downloadUrl || undefined,
31
- visitUrl: visitUrl || undefined,
32
- tags: tagsString.split(',').map(t => t.trim()).filter(Boolean),
33
- });
 
 
 
34
  };
35
 
36
  return (
@@ -49,7 +56,12 @@ export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCance
49
  {/* MAIN INFO CARD */}
50
  <div className="bg-surface p-8 rounded-2xl border border-white/5 shadow-xl space-y-6">
51
  <div>
52
- <label className="block text-sm font-medium text-gray-400 mb-2">Título</label>
 
 
 
 
 
53
  <div className="flex gap-4 items-start">
54
  <IconPicker
55
  selectedIcon={icon}
@@ -57,6 +69,7 @@ export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCance
57
  />
58
  <input
59
  required
 
60
  type="text"
61
  className="w-full bg-background border border-white/10 rounded-lg p-4 text-white text-lg focus:border-primary focus:ring-1 focus:ring-primary outline-none transition-colors"
62
  value={title}
@@ -166,8 +179,8 @@ export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCance
166
  <Button type="button" variant="ghost" onClick={onCancel} className="flex-1">
167
  Cancelar
168
  </Button>
169
- <Button type="submit" className="flex-1 py-3 text-lg shadow-[0_0_20px_rgba(187,134,252,0.2)]">
170
- <Save size={20} /> Guardar Cambios
171
  </Button>
172
  </div>
173
  </form>
 
6
 
7
  interface DataFormProps {
8
  initialData?: DataItem | null;
9
+ onSave: (data: Omit<DataItem, 'id' | 'createdAt'>) => void | Promise<void>;
10
  onCancel: () => void;
11
  }
12
 
13
  export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCancel }) => {
14
  const [title, setTitle] = useState(initialData?.title || '');
15
+ const [icon, setIcon] = useState(initialData?.icon || 'layers');
16
  const [summary, setSummary] = useState(initialData?.summary || '');
17
  const [downloadUrl, setDownloadUrl] = useState(initialData?.downloadUrl || '');
18
  const [visitUrl, setVisitUrl] = useState(initialData?.visitUrl || '');
19
  const [tagsString, setTagsString] = useState(initialData?.tags.join(', ') || '');
20
+ const [isSubmitting, setIsSubmitting] = useState(false);
21
 
22
+ const handleSubmit = async (e: React.FormEvent) => {
23
  e.preventDefault();
24
+ if (isSubmitting) return;
25
+
26
+ setIsSubmitting(true);
27
 
28
+ try {
29
+ await onSave({
30
+ icon: icon || 'layers',
31
+ title,
32
+ content: "", // Legacy
33
+ summary,
34
+ downloadUrl: downloadUrl || undefined,
35
+ visitUrl: visitUrl || undefined,
36
+ tags: tagsString.split(',').map(t => t.trim()).filter(Boolean),
37
+ });
38
+ } finally {
39
+ setIsSubmitting(false);
40
+ }
41
  };
42
 
43
  return (
 
56
  {/* MAIN INFO CARD */}
57
  <div className="bg-surface p-8 rounded-2xl border border-white/5 shadow-xl space-y-6">
58
  <div>
59
+ <div className="flex justify-between items-center mb-2">
60
+ <label className="block text-sm font-medium text-gray-400">Título</label>
61
+ <span className={`text-xs ${title.length >= 30 ? 'text-red-400' : 'text-gray-500'}`}>
62
+ {title.length}/30
63
+ </span>
64
+ </div>
65
  <div className="flex gap-4 items-start">
66
  <IconPicker
67
  selectedIcon={icon}
 
69
  />
70
  <input
71
  required
72
+ maxLength={30}
73
  type="text"
74
  className="w-full bg-background border border-white/10 rounded-lg p-4 text-white text-lg focus:border-primary focus:ring-1 focus:ring-primary outline-none transition-colors"
75
  value={title}
 
179
  <Button type="button" variant="ghost" onClick={onCancel} className="flex-1">
180
  Cancelar
181
  </Button>
182
+ <Button type="submit" className="flex-1 py-3 text-lg shadow-[0_0_20px_rgba(187,134,252,0.2)]" disabled={isSubmitting}>
183
+ <Save size={20} /> {isSubmitting ? 'Guardando...' : 'Guardar Cambios'}
184
  </Button>
185
  </div>
186
  </form>