Skip to content

Commit

Permalink
deed it
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Schwartz committed Jun 15, 2024
1 parent fcdfec2 commit d6b3af6
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 109 deletions.
3 changes: 2 additions & 1 deletion assets/js/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "https://www.gstatic.com/firebasejs/10.8.0/firebase-auth.js";
import { auth } from './firebaseInit.js';


// Function to handle the token client-side
onAuthStateChanged(auth, user => {
if (user) {
Expand Down Expand Up @@ -70,7 +71,7 @@ async function sendVerificationEmail(user) {

async function sendPasswordResetEmail(email) {
try {
await firebase.auth().sendPasswordResetEmail(email);
await firebaseSendPasswordResetEmail(auth, email);
console.log('Password reset email sent.');
} catch (error) {
console.error('Error sending password reset email:', error);
Expand Down
265 changes: 161 additions & 104 deletions assets/js/lookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
import { auth } from './firebaseInit.js';
import { signUp } from './authentication.js';

// Variables for UI elements
var userLanguage = getCookie('userLanguage') || 'en';
var modal = document.getElementById('cookie-consent-modal');
var bodyContent = document.querySelector('.main-content');
var languageDropdown = document.getElementById('language-dropdown');

// Utility functions for cookies and language settings


function setCookie(name, value, days) {
Expand All @@ -35,15 +28,26 @@ function eraseCookie(name) {
document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}

function applyLanguageSettings(language) {
document.querySelectorAll('[data-translate]').forEach(function (elem) {
var key = elem.getAttribute('data-translate');
if (translations[key] && translations[key][language]) {
elem.innerHTML = translations[key][language];
}
});
// Utility function to apply language settings asynchronously
async function applyLanguageSettings(language) {
try {
// Fetch the translation file for the selected language
const response = await fetch(`assets/trans/${language}.json`);
const translations = await response.json();

// Apply translations to all elements with the 'data-translate' attribute
document.querySelectorAll('[data-translate]').forEach(function (elem) {
const key = elem.getAttribute('data-translate');
if (translations[key]) {
elem.textContent = translations[key]; // Using textContent for security
}
});
} catch (error) {
console.error('Error loading or applying translations:', error);
}
}


function setLanguagePreference(language) {
setCookie('userLanguage', language, 365);
applyLanguageSettings(language);
Expand Down Expand Up @@ -90,6 +94,13 @@ function switchLanguage(lang) {
});
}

// Variables for UI elements
var userLanguage = getCookie('userLanguage') || 'en';
var modal = document.getElementById('cookie-consent-modal');
var bodyContent = document.querySelector('.main-content');
var languageDropdown = document.getElementById('language-dropdown');

// Utility functions for cookies and language settings


function openBlogFormModal() {
Expand Down Expand Up @@ -127,96 +138,147 @@ function setupEventListeners() {
closeModalById(modalId);
});
});

// Setup for cookie consent buttons
const acceptBtn = document.getElementById('accept-cookies');
const declineBtn = document.getElementById('decline-cookies');

if (acceptBtn) {
acceptBtn.addEventListener('click', function() {
setCookie('userConsent', 'accepted', 365);
closeModalById('cookie-consent-modal');
applyLanguageSettings(userLanguage); // Apply language settings on consent
});
}

if (declineBtn) {
declineBtn.addEventListener('click', function() {
setCookie('userConsent', 'declined', 365);
closeModalById('cookie-consent-modal');
});
}

if (languageDropdown) {
languageDropdown.addEventListener('change', function () {
setLanguagePreference(this.value);
document.addEventListener('DOMContentLoaded', function() {
setupEventListeners();
applyLanguageSettings('en'); // Default language set to English on page load
});
}








document.getElementById("loginButton").addEventListener("click", function() {
if (userIsAuthenticated()) {
openModalById('alreadyLoggedInModal');
} else {
openModalById('auth-modal');

function setupEventListeners() {
const acceptBtn = document.getElementById('accept-cookies');
const declineBtn = document.getElementById('decline-cookies');
const languageDropdown = document.getElementById('language-dropdown');

// Event listener for accepting cookies
if (acceptBtn) {
acceptBtn.addEventListener('click', function() {
setCookie('userConsent', 'accepted', 365);
closeModalById('cookie-consent-modal');
applyLanguageSettings(getCookie('userLanguage') || 'en'); // Apply language settings based on user preference or default
});
} else {
console.error('Accept button not found');
}

// Event listener for declining cookies
if (declineBtn) {
declineBtn.addEventListener('click', function() {
setCookie('userConsent', 'declined', 365);
closeModalById('cookie-consent-modal');
});
}

// Event listener for language selection
if (languageDropdown) {
languageDropdown.addEventListener('change', function() {
setLanguagePreference(this.value);
applyLanguageSettings(this.value); // Apply language settings as soon as the user changes the language
});
}

document.querySelectorAll('.close').forEach(element => {
element.addEventListener('click', function() {
const modalId = this.closest('.modal').id;
closeModalById(modalId);
});
});
}
});

document.getElementById('signupForm').addEventListener('submit', function(event) {
event.preventDefault();
const email = document.getElementById('signupEmail').value;
signUp(email).then(() => {
console.log("Sending validation email to:", email);
transitionModalStep('step1', 'step2');
}).catch(error => {
console.error("Error during sign-up:", error);
});
});

document.getElementById('userDetailsForm').addEventListener('submit', function(event) {
event.preventDefault();
const userName = document.getElementById('userName').value;
const activationCode = document.getElementById('activationCode').value;
const password = document.getElementById('choosePassword').value;
console.log("Verifying details for:", userName, "with code:", activationCode);
transitionModalStep('step2', 'step3');
});

document.getElementById('addBlogPostForm').addEventListener('submit', function(event) {
event.preventDefault();
const title = document.getElementById('blogTitle').value;
const content = document.getElementById('blogContent').value;
console.log("Posting blog titled:", title);
closeModalById('auth-modal');
});

document.querySelectorAll('.close').forEach(element => {
element.addEventListener('click', function() {
const modalId = this.closest('.modal').id;
closeModalById(modalId);
});
});


if (acceptBtn) {
acceptBtn.addEventListener('click', acceptCookies);
}

if (declineBtn) {
declineBtn.addEventListener('click', declineCookies);
}

if (languageDropdown) {
languageDropdown.addEventListener('change', function() {
setLanguagePreference(this.value);
document.addEventListener('DOMContentLoaded', function() {
setupEventListeners();
});
}
}

function setupEventListeners() {
const loginButton = document.getElementById("loginButton");
const signUpForm = document.getElementById('signupForm');
const userDetailsForm = document.getElementById('userDetailsForm');
const addBlogPostForm = document.getElementById('addBlogPostForm');
const acceptBtn = document.getElementById('accept-cookies');
const declineBtn = document.getElementById('decline-cookies');
const languageDropdown = document.getElementById('language-dropdown');

if (loginButton) {
loginButton.addEventListener("click", function() {
if (userIsAuthenticated()) {
openModalById('alreadyLoggedInModal');
} else {
openModalById('auth-modal');
}
});
}

if (signUpForm) {
signUpForm.addEventListener('submit', function(event) {
event.preventDefault();
const email = this.querySelector('#signupEmail').value;
const password = this.querySelector('#signupPassword').value; // Assuming password field exists
signUp(email, password).then(() => {
console.log("Sending validation email to:", email);
transitionModalStep('step1', 'step2');
}).catch(error => {
console.error("Error during sign-up:", error);
});
});
}

if (userDetailsForm) {
userDetailsForm.addEventListener('submit', function(event) {
event.preventDefault();
const userName = this.querySelector('#userName').value;
const activationCode = this.querySelector('#activationCode').value;
const password = this.querySelector('#choosePassword').value;
console.log("Verifying details for:", userName, "with code:", activationCode);
transitionModalStep('step2', 'step3');
});
}

if (addBlogPostForm) {
addBlogPostForm.addEventListener('submit', function(event) {
event.preventDefault();
const title = this.querySelector('#blogTitle').value;
const content = this.querySelector('#blogContent').value;
console.log("Posting blog titled:", title);
closeModalById('auth-modal');
});
}

if (acceptBtn) {
acceptBtn.addEventListener('click', function() {
setCookie('userConsent', 'accepted', 365);
closeModalById('cookie-consent-modal');
applyLanguageSettings(userLanguage); // Apply language settings on consent
});
}

if (declineBtn) {
declineBtn.addEventListener('click', function() {
setCookie('userConsent', 'declined', 365);
closeModalById('cookie-consent-modal');
});
}

if (languageDropdown) {
languageDropdown.addEventListener('change', function () {
setLanguagePreference(this.value);
});
}
document.querySelectorAll('.close').forEach(element => {
element.addEventListener('click', function() {
const modalId = this.closest('.modal').id;
closeModalById(modalId);
});
});


}

function userIsAuthenticated() {
// Updated to use Firebase auth check
return !!auth.currentUser;
}


// Initialize all scripts after the DOM is fully loaded
document.addEventListener('DOMContentLoaded', setupEventListeners);
Expand Down Expand Up @@ -245,9 +307,4 @@ function closeModalById(modalId) {
const modal = document.getElementById(modalId);
if (modal) modal.style.display = 'none';


function userIsAuthenticated() {
// Implementation depends on how authentication status is determined
// Dummy implementation:
return !!auth.currentUser;
}}
}}
3 changes: 2 additions & 1 deletion assets/en.json → assets/trans/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"statement": "Play hangman <br> Guess a letter to solve the puzzle <br> Hint: Fruits & Vegetables",
"does": "Social Connection<br>Publishing<br>Language Learning Streams<br>Contests<br>Puppet Shows<br>Games<br>Chat",
"is": "an English teacher, web developer and applied linguist. Language learning is our first habit and I want to help people find their youthful sensitivity to it online with cultural immersion."
"is": "an English teacher, web developer and applied linguist. Language learning is our first habit and I want to help people find their youthful sensitivity to it online with cultural immersion.",
"works": ""
}
3 changes: 2 additions & 1 deletion assets/fr.json → assets/trans/fr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"statement": "Jouez au Pendu en anglais <br> Devinez les lettres à résoudre <br> Indice: fruits et légumes",
"does": "Connexion sociale<br>Édition<br>Flux d'apprentissage des langues<br>Concours<br>Spectacles de marionnettes<br>Jeux<br>Bavarder pour pratique les langues",
"is": "professeur d'anglais, développeur web et linguiste appliqué. L'apprentissage des langues est notre première habitude et je veux aider les gens à retrouver leur sensibilité de jeunesse en ligne grâce à une immersion culturelle."
"is": "professeur d'anglais, développeur web et linguiste appliqué. L'apprentissage des langues est notre première habitude et je veux aider les gens à retrouver leur sensibilité de jeunesse en ligne grâce à une immersion culturelle.",
"works": ""
}
3 changes: 2 additions & 1 deletion assets/it.json → assets/trans/it.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"statement": "Gioca all'impiccato <br> Indovina una lettera per risolvere il puzzle <br> Suggerimento: frutta e verdura",
"does": "Connessione sociale<br>Pubblicazione<br>Streaming di apprendimento linguistico<br>Concorsi<br>Spettacoli di marionette<br>Giochi<br>Chat",
"is": "un insegnante di inglese, sviluppatore web e linguista applicato. L'apprendimento delle lingue è la nostra prima abitudine e voglio aiutare le persone a trovare la loro sensibilità giovanile online con l'immersione culturale."
"is": "un insegnante di inglese, sviluppatore web e linguista applicato. L'apprendimento delle lingue è la nostra prima abitudine e voglio aiutare le persone a trovare la loro sensibilità giovanile online con l'immersione culturale.",
"works": ""
}
3 changes: 2 additions & 1 deletion assets/zh.json → assets/trans/zh.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"statement": "用英语玩刽子手<br>猜字母来解决<br>提示: 水果和蔬菜。",
"does": "社交联系<br>出版<br>语言学习流<br>竞赛<br>木偶戏<br>游戏<br>聊天练习语言",
"is": "英语教师、网络开发人员和应用语言学家。 语言学习是我们的第一个习惯,我想通过文化沉浸帮助人们在网上找到他们年轻时对语言的敏感度。"
"is": "英语教师、网络开发人员和应用语言学家。 语言学习是我们的第一个习惯,我想通过文化沉浸帮助人们在网上找到他们年轻时对语言的敏感度。",
"works": ""
}

0 comments on commit d6b3af6

Please sign in to comment.