appscms-tools-theme 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,81 +2,155 @@ const profileButton = document.getElementById("profileButton");
2
2
  const userModal = document.getElementById("userModal");
3
3
  let isModalOpen = false;
4
4
 
5
- profileButton.addEventListener("click", () => {
6
- if (isModalOpen) {
7
- userModal.style.display = "none";
8
- isModalOpen = false;
9
- } else {
10
- userModal.style.display = "block";
11
- isModalOpen = true;
12
- }
13
- });
14
-
15
- // Close modal when clicking outside
16
- document.addEventListener("click", (event) => {
17
- if (
18
- !profileButton.contains(event.target) &&
19
- !userModal.contains(event.target)
20
- ) {
21
- userModal.style.display = "none";
22
- isModalOpen = false;
23
- }
24
- });
5
+ if (profileButton && userModal) {
6
+ profileButton.addEventListener("click", () => {
7
+ if (isModalOpen) {
8
+ userModal.style.display = "none";
9
+ isModalOpen = false;
10
+ } else {
11
+ userModal.style.display = "block";
12
+ isModalOpen = true;
13
+ }
14
+ });
15
+
16
+ // Close modal when clicking outside
17
+ document.addEventListener("click", (event) => {
18
+ if (
19
+ profileButton &&
20
+ userModal &&
21
+ !profileButton.contains(event.target) &&
22
+ !userModal.contains(event.target)
23
+ ) {
24
+ userModal.style.display = "none";
25
+ isModalOpen = false;
26
+ }
27
+ });
28
+ }
29
+
25
30
  // Get the modal elements
26
- const modal = document.getElementById("sideModal");
27
- const modalOverlay = document.getElementById("modalOverlay");
31
+ const sideModal = document.getElementById("sideModal");
32
+ const modalOverlayy = document.getElementById("modalOverlay");
28
33
  const openModalBtn = document.querySelector(".open-modal-btn");
29
34
  const closeModalBtn = document.querySelector(".close-modal-btn");
30
35
 
31
36
  // Function to open the modal
32
37
  function openModal() {
33
- modalOverlay.style.display = "block";
34
- // Slight delay for the overlay to appear before the modal slides in
35
- setTimeout(() => {
36
- modal.style.right = "0";
37
- }, 50);
38
+ if (modalOverlayy && sideModal) {
39
+ modalOverlayy.style.display = "block";
40
+ // Slight delay for the overlay to appear before the modal slides in
41
+ setTimeout(() => {
42
+ sideModal.style.right = "0";
43
+ }, 50);
44
+ }
38
45
  }
39
46
 
40
47
  // Function to close the modal
41
48
  function closeModal() {
42
- modal.style.right = "-90%";
43
- // Wait for the animation to complete before hiding the overlay
44
- setTimeout(() => {
45
- modalOverlay.style.display = "none";
46
- }, 300);
49
+ if (sideModal && modalOverlayy) {
50
+ sideModal.style.right = "-90%";
51
+ // Wait for the animation to complete before hiding the overlay
52
+ setTimeout(() => {
53
+ modalOverlayy.style.display = "none";
54
+ }, 300);
55
+ }
47
56
  }
48
57
 
49
58
  // Event listeners
50
- openModalBtn.addEventListener("click", openModal);
51
- closeModalBtn.addEventListener("click", closeModal);
52
- modalOverlay.addEventListener("click", closeModal);
59
+ if (openModalBtn) {
60
+ openModalBtn.addEventListener("click", openModal);
61
+ }
62
+
63
+ if (closeModalBtn) {
64
+ closeModalBtn.addEventListener("click", closeModal);
65
+ }
66
+
67
+ if (modalOverlayy) {
68
+ modalOverlayy.addEventListener("click", closeModal);
69
+ }
53
70
 
54
71
  // Prevent closing when clicking inside the modal
55
- modal.addEventListener("click", function (event) {
56
- event.stopPropagation();
57
- });
58
- if (window.location.pathname === "/profile") {
72
+ if (sideModal) {
73
+ sideModal.addEventListener("click", function (event) {
74
+ event.stopPropagation();
75
+ });
76
+ }
77
+
78
+ if (
79
+ window.location.pathname === "/profile" &&
80
+ document.querySelector(".login-button")
81
+ ) {
59
82
  document.querySelector(".login-button").addEventListener("click", openModal);
60
83
  }
61
84
 
62
- // Firebase configuration - Replace with your own Firebase config
85
+ // Firebase configuration
86
+ let firebaseConfig;
87
+
88
+ async function loadFirebaseConfig() {
89
+ try {
90
+ // Try to get config from Netlify function
91
+ const hostname = window.location.hostname;
92
+ const port = window.location.port;
93
+
94
+ let baseUrl = "";
95
+
96
+ // Development environment detection
97
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
98
+ // When running locally, we need to specify which port the Netlify Functions are running on
99
+ // Default Netlify CLI functions port is 8888, but could be 9000 or custom
100
+ baseUrl = "http://localhost:9000"; // Adjust this if your Netlify Functions are on a different port
101
+ }
102
+
103
+ // Make the request to the Netlify function with credentials included
104
+
105
+ const response = await fetch(
106
+ `http://localhost:9000/.netlify/functions/get-firebase-config`
107
+ );
108
+
109
+ if (response.ok) {
110
+ firebaseConfig = await response.json();
111
+
112
+ // Check if we got all required config fields
113
+ if (
114
+ firebaseConfig.apiKey &&
115
+ firebaseConfig.authDomain &&
116
+ firebaseConfig.projectId
117
+ ) {
118
+ // Initialize Firebase with the config
119
+ if (typeof firebase !== "undefined") {
120
+ initializeFirebase();
121
+ } else {
122
+ console.error("Firebase SDK not loaded");
123
+ }
124
+ } else {
125
+ console.error("Incomplete Firebase configuration received");
126
+ }
127
+ } else {
128
+ console.error("Failed to load Firebase config:", response.status);
129
+ }
130
+ } catch (error) {
131
+ console.log(error);
132
+ console.error("Error loading Firebase config:", error);
133
+ }
134
+ }
135
+
136
+ function initializeFirebase() {
137
+ if (!firebase.apps.length) {
138
+ firebase.initializeApp(firebaseConfig);
63
139
 
64
- // Initialize Firebase
65
- firebase.initializeApp(firebaseConfig);
66
- const auth = firebase.auth();
140
+ setupAuthListeners();
141
+ }
142
+ }
143
+
144
+ function setupAuthListeners() {
145
+ const auth = firebase.auth();
67
146
 
68
- // Check for redirect result immediately when page loads
69
- document.addEventListener("DOMContentLoaded", function () {
70
- console.log("Checking for auth redirect...");
71
147
  auth
72
148
  .getRedirectResult()
73
149
  .then((result) => {
74
150
  if (result && result.user) {
75
- console.log("Redirect authentication successful:", result.user);
76
151
  // Twitter or other redirect login was successful
77
152
  // Auth state observer will handle the UI update
78
153
  } else if (result) {
79
- console.log("Redirect completed but no user");
80
154
  }
81
155
  })
82
156
  .catch((error) => {
@@ -85,269 +159,338 @@ document.addEventListener("DOMContentLoaded", function () {
85
159
  alert(`Authentication error: ${error.message}`);
86
160
  }
87
161
  });
88
- });
89
-
90
- // DOM Elements
91
- const loginForm = document.getElementById("loginForm");
92
- const signupForm = document.getElementById("signupForm");
93
- const forgotPasswordForm = document.getElementById("forgotPasswordForm");
94
- const authContainer = document.getElementById("authContainer");
95
- const userAvatar = document.getElementById("userAvatar");
96
- const profileUserAvatar = document.querySelector(".profile-user-avatar");
97
-
98
- // Switch between login and signup
99
- document.getElementById("showSignup").addEventListener("click", (e) => {
100
- e.preventDefault();
101
- loginForm.style.display = "none";
102
- signupForm.style.display = "block";
103
- forgotPasswordForm.style.display = "none";
104
- });
105
-
106
- document.getElementById("showLogin").addEventListener("click", (e) => {
107
- e.preventDefault();
108
- signupForm.style.display = "none";
109
- loginForm.style.display = "block";
110
- forgotPasswordForm.style.display = "none";
111
- });
112
-
113
- // Show forgot password form
114
- document.getElementById("forgotPassword").addEventListener("click", (e) => {
115
- e.preventDefault();
116
- loginForm.style.display = "none";
117
- forgotPasswordForm.style.display = "block";
118
- });
119
-
120
- // Back to login from forgot password
121
- document.getElementById("backToLogin").addEventListener("click", () => {
122
- forgotPasswordForm.style.display = "none";
123
- loginForm.style.display = "block";
124
- document.getElementById("resetSuccess").style.display = "none";
125
- });
126
-
127
- // Handle reset password form submission
128
- // Handle reset password form submission
129
- // Handle reset password form submission
130
- // Handle reset password form submission
131
- document.getElementById("resetPasswordForm").addEventListener("submit", (e) => {
132
- e.preventDefault();
133
- const email = document.getElementById("resetEmail").value;
134
-
135
- // This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
136
- const actionCodeSettings = {
137
- url: "https://pdftoolkit-develop.netlify.app/",
138
- handleCodeInApp: false,
139
- };
140
162
 
141
- auth
142
- .sendPasswordResetEmail(email, actionCodeSettings)
143
- .then(() => {
144
- // Show success message
145
- document.getElementById("resetSuccess").style.display = "block";
146
- document.getElementById("resetPasswordForm").reset();
147
- })
148
- .catch((error) => {
149
- alert(`Error: ${error.message}`);
163
+ // DOM Elements
164
+ const loginForm = document.getElementById("loginForm");
165
+ const signupForm = document.getElementById("signupForm");
166
+ const forgotPasswordForm = document.getElementById("forgotPasswordForm");
167
+ const userAvatar = document.getElementById("userAvatar");
168
+ const profileUserAvatar = document.querySelector(".profile-user-avatar");
169
+
170
+ // Switch between login and signup
171
+ const showSignupBtn = document.getElementById("showSignup");
172
+ if (showSignupBtn) {
173
+ showSignupBtn.addEventListener("click", (e) => {
174
+ e.preventDefault();
175
+ if (loginForm) loginForm.style.display = "none";
176
+ if (signupForm) signupForm.style.display = "block";
177
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
150
178
  });
151
- });
152
-
153
- // Toggle password visibility
154
- document.getElementById("toggleLoginPassword").addEventListener("click", () => {
155
- const passwordInput = document.getElementById("loginPassword");
156
- passwordInput.type = passwordInput.type === "password" ? "text" : "password";
157
- });
158
-
159
- document
160
- .getElementById("toggleSignupPassword")
161
- .addEventListener("click", () => {
162
- const passwordInput = document.getElementById("signupPassword");
163
- passwordInput.type =
164
- passwordInput.type === "password" ? "text" : "password";
165
- });
179
+ }
166
180
 
167
- // Email/Password Login
168
- document.getElementById("emailLoginForm").addEventListener("submit", (e) => {
169
- e.preventDefault();
170
- const email = document.getElementById("loginEmail").value;
171
- const password = document.getElementById("loginPassword").value;
181
+ const showLoginBtn = document.getElementById("showLogin");
182
+ if (showLoginBtn) {
183
+ showLoginBtn.addEventListener("click", (e) => {
184
+ e.preventDefault();
185
+ if (signupForm) signupForm.style.display = "none";
186
+ if (loginForm) loginForm.style.display = "block";
187
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
188
+ });
189
+ }
172
190
 
173
- auth
174
- .signInWithEmailAndPassword(email, password)
175
- .then((userCredential) => {
176
- // Signed in
177
- const user = userCredential.user;
178
- console.log("User logged in:", user);
179
- })
180
- .catch((error) => {
181
- alert(`Login error: ${error.message}`);
191
+ // Show forgot password form
192
+ const forgotPasswordBtn = document.getElementById("forgotPassword");
193
+ if (forgotPasswordBtn) {
194
+ forgotPasswordBtn.addEventListener("click", (e) => {
195
+ e.preventDefault();
196
+ if (loginForm) loginForm.style.display = "none";
197
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "block";
182
198
  });
183
- });
199
+ }
184
200
 
185
- // Email/Password Signup
186
- document.getElementById("emailSignupForm").addEventListener("submit", (e) => {
187
- e.preventDefault();
188
- const email = document.getElementById("signupEmail").value;
189
- const password = document.getElementById("signupPassword").value;
201
+ // Back to login from forgot password
202
+ const backToLoginBtn = document.getElementById("backToLogin");
203
+ if (backToLoginBtn) {
204
+ backToLoginBtn.addEventListener("click", () => {
205
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
206
+ if (loginForm) loginForm.style.display = "block";
207
+ const resetSuccess = document.getElementById("resetSuccess");
208
+ if (resetSuccess) resetSuccess.style.display = "none";
209
+ });
210
+ }
190
211
 
191
- auth
192
- .createUserWithEmailAndPassword(email, password)
193
- .then((userCredential) => {
194
- // Signed up
195
- const user = userCredential.user;
196
- console.log("User created:", user);
197
- })
198
- .catch((error) => {
199
- alert(`Signup error: ${error.message}`);
212
+ // Handle reset password form submission
213
+ const resetPasswordForm = document.getElementById("resetPasswordForm");
214
+ if (resetPasswordForm) {
215
+ resetPasswordForm.addEventListener("submit", (e) => {
216
+ e.preventDefault();
217
+ const resetEmail = document.getElementById("resetEmail");
218
+ if (!resetEmail) return;
219
+
220
+ const email = resetEmail.value;
221
+
222
+ // This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
223
+ const actionCodeSettings = {
224
+ url: "https://pdftoolkit-develop.netlify.app/",
225
+ handleCodeInApp: false,
226
+ };
227
+
228
+ auth
229
+ .sendPasswordResetEmail(email, actionCodeSettings)
230
+ .then(() => {
231
+ // Show success message
232
+ const resetSuccess = document.getElementById("resetSuccess");
233
+ if (resetSuccess) resetSuccess.style.display = "block";
234
+ resetPasswordForm.reset();
235
+ })
236
+ .catch((error) => {
237
+ alert(`Error: ${error.message}`);
238
+ });
200
239
  });
201
- });
240
+ }
202
241
 
203
- // Google Login
204
- document.getElementById("googleLogin").addEventListener("click", () => {
205
- const provider = new firebase.auth.GoogleAuthProvider();
206
- auth
207
- .signInWithPopup(provider)
208
- .then((result) => {
209
- console.log("Google login successful");
210
- })
211
- .catch((error) => {
212
- alert(`Google login error: ${error.message}`);
242
+ // Toggle password visibility
243
+ const toggleLoginPassword = document.getElementById("toggleLoginPassword");
244
+ if (toggleLoginPassword) {
245
+ toggleLoginPassword.addEventListener("click", () => {
246
+ const passwordInput = document.getElementById("loginPassword");
247
+ if (passwordInput) {
248
+ passwordInput.type =
249
+ passwordInput.type === "password" ? "text" : "password";
250
+ }
213
251
  });
214
- });
252
+ }
215
253
 
216
- document.getElementById("googleSignup").addEventListener("click", () => {
217
- const provider = new firebase.auth.GoogleAuthProvider();
218
- auth
219
- .signInWithPopup(provider)
220
- .then((result) => {
221
- console.log(result);
222
- console.log("Google signup successful");
223
- })
224
- .catch((error) => {
225
- alert(`Google signup error: ${error.message}`);
254
+ const toggleSignupPassword = document.getElementById("toggleSignupPassword");
255
+ if (toggleSignupPassword) {
256
+ toggleSignupPassword.addEventListener("click", () => {
257
+ const passwordInput = document.getElementById("signupPassword");
258
+ if (passwordInput) {
259
+ passwordInput.type =
260
+ passwordInput.type === "password" ? "text" : "password";
261
+ }
226
262
  });
227
- });
263
+ }
228
264
 
229
- // Facebook Login
230
- document.getElementById("facebookLogin").addEventListener("click", () => {
231
- const provider = new firebase.auth.FacebookAuthProvider();
232
- provider.addScope("email");
265
+ // Email/Password Login
266
+ const emailLoginForm = document.getElementById("emailLoginForm");
267
+ if (emailLoginForm) {
268
+ emailLoginForm.addEventListener("submit", (e) => {
269
+ e.preventDefault();
270
+ const loginEmail = document.getElementById("loginEmail");
271
+ const loginPassword = document.getElementById("loginPassword");
272
+ if (!loginEmail || !loginPassword) return;
273
+
274
+ const email = loginEmail.value;
275
+ const password = loginPassword.value;
276
+
277
+ auth
278
+ .signInWithEmailAndPassword(email, password)
279
+ .then((userCredential) => {
280
+ // Signed in
281
+ const user = userCredential.user;
282
+ })
283
+ .catch((error) => {
284
+ alert(`Login error: ${error.message}`);
285
+ });
286
+ });
287
+ }
233
288
 
234
- // Try popup instead of redirect for Facebook
235
- auth
236
- .signInWithPopup(provider)
237
- .then((result) => {
238
- console.log("Facebook login successful");
239
- })
240
- .catch((error) => {
241
- console.error("Facebook login error:", error);
242
- alert(`Facebook login error: ${error.message}`);
289
+ // Email/Password Signup
290
+ const emailSignupForm = document.getElementById("emailSignupForm");
291
+ if (emailSignupForm) {
292
+ emailSignupForm.addEventListener("submit", (e) => {
293
+ e.preventDefault();
294
+ const signupEmail = document.getElementById("signupEmail");
295
+ const signupPassword = document.getElementById("signupPassword");
296
+ if (!signupEmail || !signupPassword) return;
297
+
298
+ const email = signupEmail.value;
299
+ const password = signupPassword.value;
300
+
301
+ auth
302
+ .createUserWithEmailAndPassword(email, password)
303
+ .then((userCredential) => {
304
+ // Signed up
305
+ const user = userCredential.user;
306
+ })
307
+ .catch((error) => {
308
+ alert(`Signup error: ${error.message}`);
309
+ });
243
310
  });
244
- });
311
+ }
245
312
 
246
- // Twitter Login - Try using popup method first
247
- document.getElementById("twitterLogin").addEventListener("click", () => {
248
- console.log("Starting Twitter login...");
249
- const provider = new firebase.auth.TwitterAuthProvider();
313
+ // Google Login
314
+ const googleLoginBtn = document.getElementById("googleLogin");
315
+ if (googleLoginBtn) {
316
+ googleLoginBtn.addEventListener("click", () => {
317
+ const provider = new firebase.auth.GoogleAuthProvider();
318
+ auth
319
+ .signInWithPopup(provider)
320
+ .then((result) => {})
321
+ .catch((error) => {
322
+ alert(`Google login error: ${error.message}`);
323
+ });
324
+ });
325
+ }
250
326
 
251
- try {
252
- // Try popup method first as it provides better error feedback
253
- auth
254
- .signInWithPopup(provider)
255
- .then((result) => {
256
- console.log("Twitter login successful via popup");
257
- })
258
- .catch((error) => {
259
- console.error("Twitter popup error:", error);
260
-
261
- // If popup fails, fallback to redirect
262
- if (
263
- error.code === "auth/popup-blocked" ||
264
- error.code === "auth/popup-closed-by-user"
265
- ) {
266
- console.log("Popup blocked, trying redirect instead");
267
- auth.signInWithRedirect(provider).catch((redirectError) => {
268
- console.error("Twitter redirect error:", redirectError);
269
- alert(`Twitter login error: ${redirectError.message}`);
327
+ const googleSignupBtn = document.getElementById("googleSignup");
328
+ if (googleSignupBtn) {
329
+ googleSignupBtn.addEventListener("click", () => {
330
+ const provider = new firebase.auth.GoogleAuthProvider();
331
+ auth
332
+ .signInWithPopup(provider)
333
+ .then((result) => {})
334
+ .catch((error) => {
335
+ alert(`Google signup error: ${error.message}`);
336
+ });
337
+ });
338
+ }
339
+
340
+ // Facebook Login
341
+ const facebookLoginBtn = document.getElementById("facebookLogin");
342
+ if (facebookLoginBtn) {
343
+ facebookLoginBtn.addEventListener("click", () => {
344
+ const provider = new firebase.auth.FacebookAuthProvider();
345
+ provider.addScope("email");
346
+
347
+ // Try popup instead of redirect for Facebook
348
+ auth
349
+ .signInWithPopup(provider)
350
+ .then((result) => {})
351
+ .catch((error) => {
352
+ console.error("Facebook login error:", error);
353
+ alert(`Facebook login error: ${error.message}`);
354
+ });
355
+ });
356
+ }
357
+
358
+ // Twitter Login - Try using popup method first
359
+ const twitterLoginBtn = document.getElementById("twitterLogin");
360
+ if (twitterLoginBtn) {
361
+ twitterLoginBtn.addEventListener("click", () => {
362
+ const provider = new firebase.auth.TwitterAuthProvider();
363
+
364
+ try {
365
+ // Try popup method first as it provides better error feedback
366
+ auth
367
+ .signInWithPopup(provider)
368
+ .then((result) => {})
369
+ .catch((error) => {
370
+ console.error("Twitter popup error:", error);
371
+
372
+ // If popup fails, fallback to redirect
373
+ if (
374
+ error.code === "auth/popup-blocked" ||
375
+ error.code === "auth/popup-closed-by-user"
376
+ ) {
377
+ auth.signInWithRedirect(provider).catch((redirectError) => {
378
+ console.error("Twitter redirect error:", redirectError);
379
+ alert(`Twitter login error: ${redirectError.message}`);
380
+ });
381
+ } else {
382
+ alert(`Twitter login error: ${error.message}`);
383
+ }
270
384
  });
271
- } else {
272
- alert(`Twitter login error: ${error.message}`);
273
- }
274
- });
275
- } catch (e) {
276
- console.error("Exception during Twitter login:", e);
385
+ } catch (e) {
386
+ console.error("Exception during Twitter login:", e);
387
+ }
388
+ });
277
389
  }
278
- });
279
390
 
280
- // Logout
281
- document.getElementById("logoutBtn").addEventListener("click", () => {
282
- auth
283
- .signOut()
284
- .then(() => {
285
- document.querySelector(".user-profile-header").style.display = "none";
286
- window.location.reload();
287
- console.log("User signed out");
288
- })
289
- .catch((error) => {
290
- alert(`Logout error: ${error.message}`);
391
+ // Logout
392
+ const logoutBtn = document.getElementById("logoutBtn");
393
+ if (logoutBtn) {
394
+ logoutBtn.addEventListener("click", () => {
395
+ auth
396
+ .signOut()
397
+ .then(() => {
398
+ const userProfileHeader = document.querySelector(
399
+ ".user-profile-header"
400
+ );
401
+ if (userProfileHeader) userProfileHeader.style.display = "none";
402
+ window.location.reload();
403
+ })
404
+ .catch((error) => {
405
+ alert(`Logout error: ${error.message}`);
406
+ });
291
407
  });
292
- });
408
+ }
409
+
410
+ // Auth state observer
411
+ auth.onAuthStateChanged((user) => {
412
+ if (user) {
413
+ const email = user.email || "No email available";
414
+ const loggedInUserEmail = document.querySelector(".logged-in-user-email");
415
+ if (loggedInUserEmail) loggedInUserEmail.textContent = email;
416
+
417
+ let displayName =
418
+ user.displayName || (user.email ? user.email.split("@")[0] : "User");
419
+
420
+ // Special handling for Twitter users who might not have email
421
+ if (
422
+ user.providerData[0].providerId === "twitter.com" &&
423
+ !user.displayName
424
+ ) {
425
+ displayName = user.providerData[0].uid;
426
+ }
293
427
 
294
- // Auth state observer
295
- auth.onAuthStateChanged((user) => {
296
- console.log(
297
- "Auth state changed:",
298
- user ? "User logged in" : "User logged out"
299
- );
428
+ if (sideModal) {
429
+ sideModal.style.display = "none";
430
+ sideModal.style.right = "-90%";
431
+ }
300
432
 
301
- if (user) {
302
- console.log(user);
433
+ if (modalOverlayy) {
434
+ modalOverlayy.style.display = "none";
435
+ }
303
436
 
304
- const email = user.email || "No email available";
305
- document.querySelector(".logged-in-user-email").textContent = email;
306
- let displayName =
307
- user.displayName || (user.email ? user.email.split("@")[0] : "User");
437
+ const loggedInUsername = document.querySelector(".logged-in-username");
438
+ if (loggedInUsername) loggedInUsername.textContent = displayName;
308
439
 
309
- // Special handling for Twitter users who might not have email
310
- if (
311
- user.providerData[0].providerId === "twitter.com" &&
312
- !user.displayName
313
- ) {
314
- displayName = user.providerData[0].uid;
315
- }
440
+ const loginModalButton = document.querySelector(".login-modal-button");
441
+ if (loginModalButton) loginModalButton.style.display = "none";
442
+
443
+ // Set initials for avatar
444
+ const initials = displayName
445
+ .split(" ")
446
+ .map((n) => n[0])
447
+ .join("")
448
+ .toUpperCase()
449
+ .substring(0, 2);
316
450
 
317
- console.log("Provider:", user.providerData[0].providerId);
318
- console.log("Display name:", displayName);
319
- modal.style.display = "none";
320
- modal.style.right = "-90%";
321
- modalOverlay.style.display = "none";
322
- document.querySelector(".logged-in-username").textContent = displayName;
323
- document.querySelector(".login-modal-button").style.display = "none";
324
-
325
- // Set initials for avatar
326
- const initials = displayName
327
- .split(" ")
328
- .map((n) => n[0])
329
- .join("")
330
- .toUpperCase()
331
- .substring(0, 2);
332
- document.getElementById("profileButton").textContent = initials;
333
- profileUserAvatar.textContent = initials;
334
- document.querySelector(".user-profile-header").style.display = "block";
335
-
336
- userAvatar.textContent = initials;
337
- userAvatar.style.display = "flex";
338
- if (window.location.pathname === "/profile") {
339
- document.querySelector(".user-profile-section").style.display = "flex";
340
- document.querySelector(".profile-login-container").style.display = "none";
341
- document.querySelector(".avatar-large").textContent = initials;
342
- document.querySelector("#user-email-input").value = email;
343
- document.querySelector(".username-input").value = displayName;
344
-
345
- console.log("You are on the profile page.");
451
+ if (profileButton) profileButton.textContent = initials;
452
+ if (profileUserAvatar) profileUserAvatar.textContent = initials;
453
+
454
+ const userProfileHeader = document.querySelector(".user-profile-header");
455
+ if (userProfileHeader) userProfileHeader.style.display = "block";
456
+
457
+ if (userAvatar) {
458
+ userAvatar.textContent = initials;
459
+ userAvatar.style.display = "flex";
460
+ }
461
+
462
+ if (window.location.pathname === "/profile") {
463
+ const userProfileSection = document.querySelector(
464
+ ".user-profile-section"
465
+ );
466
+ if (userProfileSection) userProfileSection.style.display = "flex";
467
+
468
+ const profileLoginContainer = document.querySelector(
469
+ ".profile-login-container"
470
+ );
471
+ if (profileLoginContainer) profileLoginContainer.style.display = "none";
472
+
473
+ const avatarLarge = document.querySelector(".avatar-large");
474
+ if (avatarLarge) avatarLarge.textContent = initials;
475
+
476
+ const userEmailInput = document.querySelector("#user-email-input");
477
+ if (userEmailInput) userEmailInput.value = email;
478
+
479
+ const usernameInput = document.querySelector(".username-input");
480
+ if (usernameInput) usernameInput.value = displayName;
481
+ }
482
+ } else {
483
+ if (userAvatar) userAvatar.style.display = "none";
484
+ if (loginForm) loginForm.style.display = "block";
485
+ if (signupForm) signupForm.style.display = "none";
486
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
346
487
  }
347
- } else {
348
- userAvatar.style.display = "none";
349
- loginForm.style.display = "block";
350
- signupForm.style.display = "none";
351
- forgotPasswordForm.style.display = "none";
352
- }
353
- });
488
+ });
489
+ }
490
+
491
+ // Initialize the app
492
+ if (document.readyState === "loading") {
493
+ document.addEventListener("DOMContentLoaded", loadFirebaseConfig);
494
+ } else {
495
+ loadFirebaseConfig();
496
+ }