codebybrody commited on
Commit
97e4af3
·
verified ·
1 Parent(s): 92a4c44

Upload 58 files

Browse files
Files changed (2) hide show
  1. App.tsx +65 -1
  2. components/DetailView.tsx +1 -1
App.tsx CHANGED
@@ -23,7 +23,13 @@ const App: React.FC = () => {
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(() => {
@@ -53,6 +59,64 @@ const App: React.FC = () => {
53
  localStorage.setItem('sortOrder', sortOrder);
54
  }, [sortOrder]);
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  // Helper function to apply code style dynamically to DOM
57
  const applyCodeStyleToDOM = (config: any) => {
58
  const rgbaMatch = config.bgColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);
 
23
  return 'normal';
24
  });
25
  const [isSettingsOpen, setIsSettingsOpen] = useState(false);
26
+ const [currentPage, setCurrentPage] = useState(() => {
27
+ if (typeof window !== 'undefined') {
28
+ const p = new URLSearchParams(window.location.search).get('page');
29
+ if (p && !isNaN(Number(p))) return Math.max(1, parseInt(p, 10));
30
+ }
31
+ return 1;
32
+ });
33
  const ITEMS_PER_PAGE = 20;
34
 
35
  useEffect(() => {
 
59
  localStorage.setItem('sortOrder', sortOrder);
60
  }, [sortOrder]);
61
 
62
+ // Handle URL Sync
63
+ useEffect(() => {
64
+ if (typeof window !== 'undefined') {
65
+ const url = new URL(window.location.href);
66
+ const params = url.searchParams;
67
+ let modified = false;
68
+
69
+ if (selectedItem) {
70
+ if (params.get('item') !== selectedItem.id) {
71
+ params.set('item', selectedItem.id);
72
+ modified = true;
73
+ }
74
+ } else {
75
+ if (params.has('item')) {
76
+ params.delete('item');
77
+ modified = true;
78
+ }
79
+ }
80
+
81
+ if (currentPage > 1) {
82
+ if (params.get('page') !== currentPage.toString()) {
83
+ params.set('page', currentPage.toString());
84
+ modified = true;
85
+ }
86
+ } else {
87
+ if (params.has('page')) {
88
+ params.delete('page');
89
+ modified = true;
90
+ }
91
+ }
92
+
93
+ if (modified) {
94
+ const newSearch = params.toString() ? `?${params.toString()}` : '';
95
+ window.history.replaceState({}, '', url.pathname + newSearch);
96
+ }
97
+ }
98
+ }, [currentPage, selectedItem]);
99
+
100
+ // Load deep linked item
101
+ useEffect(() => {
102
+ if (!loading && items.length > 0 && typeof window !== 'undefined' && view === 'LIST' && !selectedItem) {
103
+ const params = new URLSearchParams(window.location.search);
104
+ const itemId = params.get('item');
105
+ if (itemId) {
106
+ const found = items.find((i) => i.id === itemId);
107
+ if (found) {
108
+ setSelectedItem(found);
109
+ setView('DETAIL');
110
+ } else {
111
+ params.delete('item');
112
+ const newSearch = params.toString() ? `?${params.toString()}` : '';
113
+ window.history.replaceState({}, '', window.location.pathname + newSearch);
114
+ }
115
+ }
116
+ }
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, [loading, items]);
119
+
120
  // Helper function to apply code style dynamically to DOM
121
  const applyCodeStyleToDOM = (config: any) => {
122
  const rgbaMatch = config.bgColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)/);
components/DetailView.tsx CHANGED
@@ -569,7 +569,7 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
569
  )}
570
  {item.downloadUrl && (
571
  <a href={item.downloadUrl} target="_blank" rel="noopener noreferrer" className="flex-1 flex w-full">
572
- <button className="w-full flex items-center justify-center gap-2 py-2.5 px-4 rounded-xl border border-blue-500/30 text-blue-400 hover:bg-blue-500/10 transition-colors text-sm font-medium">
573
  <Download size={16} /> Descargar
574
  </button>
575
  </a>
 
569
  )}
570
  {item.downloadUrl && (
571
  <a href={item.downloadUrl} target="_blank" rel="noopener noreferrer" className="flex-1 flex w-full">
572
+ <button className="w-full flex items-center justify-center gap-2 py-2.5 px-4 rounded-xl border border-primary/30 text-primary hover:bg-primary/10 transition-colors text-sm font-medium">
573
  <Download size={16} /> Descargar
574
  </button>
575
  </a>