Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm install --legacy-peer-deps
- name: Run tests
run: npm test
# Build and deploy site to GitHub Pages
Expand Down
6 changes: 3 additions & 3 deletions form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function resetForm() {
if (context && typeof context.clearRect === 'function') {
context.clearRect(0, 0, canvas.width, canvas.height);
} else {
console.error('clearRect method is not available on the canvas context.');
console.warn('clearRect method is not available on the canvas context.');
}
const languageSelect = document.getElementById('language-select').value;
const translation = await loadTranslations(languageSelect);
Expand Down Expand Up @@ -51,7 +51,7 @@ export function calculateAPR() {
const coutEmprunt = (monthlyLoanInsurancePayment * loanDuration * 12) - borrowedAmount;
apr = coutEmprunt / borrowedAmount * 100 / loanDuration ;
} else if (borrowedAmount < 0) {
console.error('Montant emprunté négatif:', borrowedAmount);
console.warn('Montant emprunté négatif:', borrowedAmount);
}
// console.log('Calculated APR:', apr);
return apr;
Expand Down Expand Up @@ -117,7 +117,7 @@ function isValidNumber(value) {
try {
return !isNaN(parseFloat(value)) && isFinite(value) && value.trim() !== "";
} catch (error) {
console.error("Error checking if value is a valid number:", { value, error });
console.warn("Error checking if value is a valid number:", { value, error });
return false;
}
}
Expand Down
40 changes: 27 additions & 13 deletions handle-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function initiateLanguageSelection() {
// console.log('Browser language detected:', browserLanguage);
// Match browser language with available options in the select element
const availableLanguages = Array.from(languageSelect.options).map(option => option.value);
const defaultLanguage = availableLanguages.includes(browserLanguage) ? browserLanguage : 'fr'; // Fallback to 'fr' if not found
const defaultLanguage = availableLanguages.includes(browserLanguage) ? browserLanguage : 'en'; // Fallback to 'en' if not found
// Set the languageSelect value to the detected language
languageSelect.value = defaultLanguage;
// Load translations for the detected language
Expand All @@ -29,24 +29,38 @@ export async function loadTranslations(language) {
// console.log('Translations loaded:', translations);
return translations;
} catch (error) {
console.error('Error loading translations:', error);
console.warn('Error loading translations:', error);
return null;
}
}


export async function updateAPRLabel(apr, translations) {
// update APR display
const aprElement = document.getElementById('apr-overlay');
// const language = document.getElementById('language-select').value;
// const response = fetch(`translations/${language}.json`);
// const translations = response.json();
if (aprElement && typeof translations !== 'undefined' && translations && translations.reportAPR) {
console.log('Updating APR label with value:', `${translations.APR}: ${apr.toFixed(2)}%`);
aprElement.textContent = `${translations.APR}: ${apr.toFixed(2)}%`;
let aprLabel, aprValue;

if (!aprElement) {
console.warn('APR element not found.');
return;
}

// Handle apr value
if (typeof apr !== 'number' || isNaN(apr)) {
aprValue = '??.??';
} else {
aprValue = apr.toFixed(2);
}

// Handle translations and APR label
if (translations) {
if (!translations.APR) {
translations.APR = 'APR_IDIOT_LABEL';
}
aprLabel = translations.APR;
} else {
console.error('APR element not found or translations are not available.');
aprLabel = 'APR_IDIOT_TRANSLATION';
}

aprElement.textContent = `${aprLabel}: ${aprValue}%`;
}

export async function updateContent(translations) {
Expand Down Expand Up @@ -102,7 +116,7 @@ export async function updateContent(translations) {
if (sectionFinancing) sectionFinancing.textContent = translations.sectionFinancing;
if (sectionTitle) sectionTitle.textContent = translations.sectionTitle;
if (apr) {
console.log("calculating APR inside updateContent");
// console.log("calculating APR inside updateContent");
const aprValue = calculateAPR(document); //apr.textContent = `${translations.reportAPR}: `;
updateAPRLabel(aprValue, translations);
}
Expand All @@ -117,6 +131,6 @@ export async function updateContent(translations) {
if (welcomeMessage) welcomeMessage.querySelector('p').innerHTML = translations.welcomeMessage;
}
else {
console.error('Translations are not available or invalid.');
console.warn('Translations are not available or invalid.');
}
}
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ <h2 id="financing-section">Financement</h2>
<div id="report-button"></div>
<div id="download-button"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jspdf@3.0.1/dist/jspdf.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jspdf-autotable@5.0.2/dist/jspdf.plugin.autotable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.8/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jspdf/dist/jspdf.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jspdf-autotable/dist/jspdf.plugin.autotable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.umd.js"></script>
<script type="module" src="form-handler.js"></script>
<script type="module" src="report-handler.js"></script>
<script type="module" src="dark-mode.js"></script>
Expand Down
Loading