Lashtw commited on
Commit
fc70ca4
·
verified ·
1 Parent(s): 1320c52

Upload 10 files

Browse files
Files changed (1) hide show
  1. src/views/InstructorView.js +35 -32
src/views/InstructorView.js CHANGED
@@ -43,10 +43,10 @@ export async function renderInstructorView() {
43
  </div>
44
 
45
  <div class="mt-6 flex gap-2">
46
- <button id="login-btn" class="flex-1 bg-cyan-600 hover:bg-cyan-500 text-white font-bold py-2 px-4 rounded transition-colors duration-200">
47
  登入
48
  </button>
49
- <button id="register-btn" class="flex-1 bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded transition-colors duration-200">
50
  註冊
51
  </button>
52
  </div>
@@ -377,49 +377,52 @@ export function setupInstructorEvents() {
377
  console.log("Starting setupInstructorEvents...");
378
 
379
  // Login Logic
380
- const loginBtn = document.getElementById('login-btn');
381
- const registerBtn = document.getElementById('register-btn');
382
- const emailInput = document.getElementById('login-email');
383
- const passwordInput = document.getElementById('login-password');
384
  const authErrorMsg = document.getElementById('auth-error');
385
  const authModal = document.getElementById('auth-modal');
386
 
 
 
 
 
 
 
387
 
388
- if (loginBtn) {
389
- loginBtn.addEventListener('click', async () => {
390
- const email = emailInput.value.trim();
391
- const password = passwordInput.value.trim();
392
- if (!email || !password) return alert("請輸入帳號與密碼");
393
 
394
- try {
395
- // Determine if this is a login or register flow?
396
- // Wait, register btn is separate.
397
- await loginWithEmail(email, password);
398
- // Auth Observer will handle the rest
399
- } catch (e) {
400
- console.error("Login Error:", e);
401
  authErrorMsg.textContent = "登入失敗: " + e.message;
402
  authErrorMsg.classList.remove('hidden');
403
  }
404
- });
405
- }
 
 
406
 
407
- if (registerBtn) {
408
- registerBtn.addEventListener('click', async () => {
409
- const email = emailInput.value.trim();
410
- const password = passwordInput.value.trim();
411
- if (!email || !password) return alert("請輸入帳號與密碼");
412
 
413
- try {
414
- await registerWithEmail(email, password);
415
- alert("註冊成功,請登入");
416
- } catch (e) {
417
- console.error("Register Error:", e);
 
418
  authErrorMsg.textContent = "註冊失敗: " + e.message;
419
  authErrorMsg.classList.remove('hidden');
420
  }
421
- });
422
- }
 
423
 
424
  // --- Instructor Management Helper ---
425
  async function loadInstructorList() {
 
43
  </div>
44
 
45
  <div class="mt-6 flex gap-2">
46
+ <button id="login-btn" onclick="window.instructorLogin()" class="flex-1 bg-cyan-600 hover:bg-cyan-500 text-white font-bold py-2 px-4 rounded transition-colors duration-200">
47
  登入
48
  </button>
49
+ <button id="register-btn" onclick="window.instructorRegister()" class="flex-1 bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded transition-colors duration-200">
50
  註冊
51
  </button>
52
  </div>
 
377
  console.log("Starting setupInstructorEvents...");
378
 
379
  // Login Logic
 
 
 
 
380
  const authErrorMsg = document.getElementById('auth-error');
381
  const authModal = document.getElementById('auth-modal');
382
 
383
+ // Make functions global for robust onclick handling
384
+ window.instructorLogin = async () => {
385
+ console.log("Login clicked");
386
+ const email = document.getElementById('login-email').value.trim();
387
+ const password = document.getElementById('login-password').value.trim();
388
+ if (!email || !password) return alert("請輸入帳號與密碼");
389
 
390
+ const btn = document.getElementById('login-btn');
391
+ const originalText = btn.textContent;
392
+ btn.textContent = "登入中...";
393
+ btn.disabled = true;
 
394
 
395
+ try {
396
+ await loginWithEmail(email, password);
397
+ // Auth state listener will handle the rest
398
+ } catch (e) {
399
+ console.error("Login Error:", e);
400
+ if (authErrorMsg) {
 
401
  authErrorMsg.textContent = "登入失敗: " + e.message;
402
  authErrorMsg.classList.remove('hidden');
403
  }
404
+ btn.textContent = originalText;
405
+ btn.disabled = false;
406
+ }
407
+ };
408
 
409
+ window.instructorRegister = async () => {
410
+ const email = document.getElementById('login-email').value.trim();
411
+ const password = document.getElementById('login-password').value.trim();
412
+ if (!email || !password) return alert("請輸入帳號與密碼");
 
413
 
414
+ try {
415
+ await registerWithEmail(email, password);
416
+ alert("註冊成功,請登入");
417
+ } catch (e) {
418
+ console.error("Register Error:", e);
419
+ if (authErrorMsg) {
420
  authErrorMsg.textContent = "註冊失敗: " + e.message;
421
  authErrorMsg.classList.remove('hidden');
422
  }
423
+ }
424
+ };
425
+
426
 
427
  // --- Instructor Management Helper ---
428
  async function loadInstructorList() {