ichieh commited on
Commit
307a281
·
1 Parent(s): 7a04ee7

Fix participant data loading in admin panel

Browse files
Files changed (1) hide show
  1. templates/admin.html +9 -4
templates/admin.html CHANGED
@@ -178,8 +178,15 @@
178
  const response = await fetch('/api/admin/participants');
179
  const data = await response.json();
180
 
 
 
 
 
 
 
 
181
  // 依照桌次和座位號排序
182
- data.sort((a, b) => {
183
  // 先比較桌次
184
  const tableA = parseInt(a.table_id) || 0;
185
  const tableB = parseInt(b.table_id) || 0;
@@ -192,12 +199,10 @@
192
  return seatA - seatB;
193
  });
194
 
195
- participants = data;
196
- tables = data.tables;
197
  renderParticipants();
198
  } catch (error) {
199
  console.error('Error:', error);
200
- Swal.fire('錯誤', '載入參與者資料失敗', 'error');
201
  }
202
  }
203
 
 
178
  const response = await fetch('/api/admin/participants');
179
  const data = await response.json();
180
 
181
+ if (data.error) {
182
+ throw new Error(data.error);
183
+ }
184
+
185
+ participants = data.participants;
186
+ tables = data.tables;
187
+
188
  // 依照桌次和座位號排序
189
+ participants.sort((a, b) => {
190
  // 先比較桌次
191
  const tableA = parseInt(a.table_id) || 0;
192
  const tableB = parseInt(b.table_id) || 0;
 
199
  return seatA - seatB;
200
  });
201
 
 
 
202
  renderParticipants();
203
  } catch (error) {
204
  console.error('Error:', error);
205
+ Swal.fire('錯誤', '載入參與者資料失敗:' + error.message, 'error');
206
  }
207
  }
208