Skip to content

Commit

Permalink
Improved theme management and updated interface
Browse files Browse the repository at this point in the history
- Added dynamic background color management for `playlist-card` elements, depending on theme (light or dark).
- CSS updated to support `light-theme` and `dark-theme` classes, ensuring smooth color transition when changing theme.
- Corrected theme-toggle behavior to ensure a consistent experience across the page.
- Harmonization of text and background colors in both themes.

Objective: Improve UX by ensuring that all page elements react correctly to theme changes and by harmonizing the user interface.
  • Loading branch information
YakeDev committed Oct 11, 2024
1 parent 0b5b4e8 commit 662e4c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 54 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<title>My Favorite Books Music App</title>
</head>

<body class="bg-gray-900 text-gray-300 dark-theme">
<body class="dark-theme bg-gray-900 text-gray-300">
<!-- Navbar -->
<nav class="sticky top-0 z-20 bg-gray-800 p-4">
<div class="container mx-auto flex justify-between items-center">
Expand Down Expand Up @@ -215,6 +215,6 @@ <h2 class="text-center text-2xl mb-6">Share Your Thoughts</h2>
</footer>

<!-- JS Scripts -->
<script src="script.js"></script>
<script src="./script.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions pbd.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<title>My Favorite Books Music App</title>
</head>

<body class="bg-gray-900 text-gray-300 dark-mode">
<body class="dark-theme bg-gray-900 text-gray-300">
<!-- Navbar -->
<nav class="sticky top-0 z-20 bg-gray-800 p-4">
<div class="container mx-auto flex justify-between items-center">
Expand Down Expand Up @@ -233,6 +233,6 @@ <h2 class="text-center text-2xl mb-6">Share Your Thoughts</h2>
</footer>

<!-- JavaScript -->
<script src="script.js"></script>
<script src="./script.js"></script>
</body>
</html>
105 changes: 56 additions & 49 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
document.addEventListener('DOMContentLoaded', function () {
const playlistItems = document.querySelectorAll('#playlist li');
const audioPlayer = document.getElementById('audio-player');
const themeToggle = document.getElementById('theme-toggle');
const menuToggle = document.getElementById("menu-toggle");
const menuClose = document.getElementById("menu-close");
const menu = document.getElementById("menu");

playlistItems.forEach(item => {
item.addEventListener('click', function () {
audioPlayer.src = item.getAttribute('data-src');
audioPlayer.play();
});
});

// Comment Submission
document.getElementById('comment-form').addEventListener('submit', function (e) {
e.preventDefault();
const username = document.getElementById('username').value;
const comment = document.getElementById('comment').value;

const commentHTML = `<div class="bg-gray-700 text-white p-4 rounded-lg">
document.addEventListener("DOMContentLoaded", function () {
const playlistItems = document.querySelectorAll("#playlist li");
const audioPlayer = document.getElementById("audio-player");
const themeToggle = document.getElementById("theme-toggle");
const menuToggle = document.getElementById("menu-toggle");
const menuClose = document.getElementById("menu-close");
const menu = document.getElementById("menu");

playlistItems.forEach((item) => {
item.addEventListener("click", function () {
audioPlayer.src = item.getAttribute("data-src");
audioPlayer.play();
});
});

// Comment Submission
document
.getElementById("comment-form")
.addEventListener("submit", function (e) {
e.preventDefault();
const username = document.getElementById("username").value;
const comment = document.getElementById("comment").value;

const commentHTML = `<div class="bg-gray-700 text-white p-4 rounded-lg">
<strong>${username}:</strong>
<p>${comment}</p>
</div>`;

document.getElementById('comments-list').insertAdjacentHTML('beforeend', commentHTML);

// Reset form
document.getElementById('comment-form').reset();
});
// Theme Toggle
themeToggle.addEventListener('change', function() {
if (this.checked) {
document.body.classList.remove('dark-mode');
document.body.classList.add('light-mode');
} else {
document.body.classList.remove('light-mode');
document.body.classList.add('dark-mode');
}
});

//Mobile menu toggle
menuToggle.addEventListener("click", () => {
menu.classList.remove("scale-0");
menu.classList.add("scale-100");
});

menuClose.addEventListener("click", () => {
menu.classList.add("scale-0");
menu.classList.remove("scale-100");
});
});
document
.getElementById("comments-list")
.insertAdjacentHTML("beforeend", commentHTML);

// Reset form
document.getElementById("comment-form").reset();
});

// Theme Toggle
themeToggle.addEventListener("click", function () {
if (document.body.classList.contains("dark-theme")) {
document.body.classList.remove("dark-theme");
document.body.classList.add("light-theme");
console.log("light");
} else {
document.body.classList.remove("light-theme");
document.body.classList.add("dark-theme");
console.log("dark");
}
});

//Mobile menu toggle
menuToggle.addEventListener("click", () => {
menu.classList.remove("scale-0");
menu.classList.add("scale-100");
});

menuClose.addEventListener("click", () => {
menu.classList.add("scale-0");
menu.classList.remove("scale-100");
});
});
9 changes: 8 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ body.dark-theme {
background-color: #121212;
color: #b3b3b3;
}
body.dark-theme .playlist-card {
background-color: #121212;
color: #b3b3b3;
}

h1,
h2,
Expand Down Expand Up @@ -60,11 +64,14 @@ footer a:hover {
cursor: pointer;
}

.playlist-card {
body.dark-theme .playlist-card {
width: 100%;
background-color: #181818;
transition: transform 0.3s, box-shadow 0.3s;
}
body.light-theme .playlist-card {
background-color: #ffffff;
}
.playlist-card:hover {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
Expand Down

0 comments on commit 662e4c5

Please sign in to comment.