Skip to content

Commit

Permalink
Merge pull request #16 from Cypher-PB/Perry-Bright
Browse files Browse the repository at this point in the history
Re-structured css
  • Loading branch information
Nde-Dilan authored Oct 13, 2024
2 parents 6d9a8d7 + 23e1cc3 commit 6f0c1f1
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 129 deletions.
38 changes: 25 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ class TechMaterialsApp {

async init() {
try {
const storedDarkMode = localStorage.getItem('darkMode');
if (storedDarkMode === 'true') {
this.isDarkMode = true;
this.updateTheme();
}
await this.loadMaterials();
this.setupEventListeners();
this.renderMaterials();
this.updateTheme();
this.updateTheme();
} catch (error) {
this.showError('Failed to initialize the application');
}
Expand Down Expand Up @@ -55,15 +60,15 @@ class TechMaterialsApp {

// Theme toggle button
const toggleButton = document.getElementById('toggleTheme');
toggleButton.addEventListener('click', () => {
this.toggleTheme();
});
toggleButton.addEventListener('click', () => {
this.toggleTheme();
});
}

handleFormSubmission() {
const contributor = document.getElementById('contributor').value;
const resourceName = document.getElementById('resourceName').value;
const link = document.getElementById('link').value;
const contributor = this.escapeHtml(document.getElementById('contributor').value);
const resourceName = this.escapeHtml(document.getElementById('resourceName').value);
const link = this.escapeHtml(document.getElementById('link').value);
const tags = document.getElementById('tags').value;

const newMaterial = {
Expand Down Expand Up @@ -161,6 +166,11 @@ class TechMaterialsApp {
.replace(/'/g, "'");
}

//in cases where escapeHtml is used for href attributes
escapeHtmlAttribute(unsafe){
return unsafe.replace(/"/g, """).replace(/'/g, "'");
} // now links can be used like this::: <a href="${this.escapeHtmlAttribute(material.link)}" target="_blank">${this.escapeHtml(material.link)}</a>

showError(message) {
console.error(message);
// You could implement a more user-friendly error display here
Expand All @@ -169,26 +179,28 @@ class TechMaterialsApp {
toggleTheme() {
this.isDarkMode = !this.isDarkMode;
this.updateTheme();
localStorage.setItem('darkMode', this.isDarkMode);
}

updateTheme() {
const body = document.body;
const addMaterialSection = document.querySelector('.add-material');
const materialCards = document.querySelectorAll('.material-card');
const header = document.querySelector('h1'); // Select the header
const labels = document.querySelectorAll('label'); // Select all labelsed
const header = document.querySelector('h1');
const labels = document.querySelectorAll('label');

if (this.isDarkMode) {
body.classList.add('dark-mode');
addMaterialSection.classList.add('dark-mode');
materialCards.forEach(card => card.classList.add('dark-mode'));
header.classList.add('dark-mode'); // Add dark-mode class to header
labels.forEach(label => label.classList.add('dark-mode')); // Add dark-mode class to all labels
header.classList.add(' dark-mode');
labels.forEach(label => label.classList.add('dark-mode'));
} else {
body.classList.remove('dark-mode');
addMaterialSection.classList.remove('dark-mode');
materialCards.forEach(card => card.classList.remove('dark-mode'));
header.classList.remove('dark-mode'); // Remove dark-mode class from header
labels.forEach(label => label.classList.remove('dark-mode')); // Remove dark-mode class from all labels
header.classList.remove('dark-mode');
labels.forEach(label => label.classList.remove('dark-mode'));
}
}
}
Expand Down
Loading

0 comments on commit 6f0c1f1

Please sign in to comment.