Skip to content

Commit 4e9c58a

Browse files
committed
[MAJOR] theme shift bug fix
1 parent 0b8fc9e commit 4e9c58a

File tree

13 files changed

+58
-108
lines changed

13 files changed

+58
-108
lines changed

app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
app = Flask(__name__)
99

10-
def get_theme_css():
11-
# Implement logic to retrieve the user's theme preference and return the corresponding CSS path
12-
theme_preference = "light" # Replace with your actual logic
13-
return f"static/{theme_preference}_theme.css"
14-
1510
# Register the Blueprints from separate files
1611
app.register_blueprint(index_blueprint)
1712
app.register_blueprint(browse_blueprint)

routes/browse_routes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,31 @@
3232

3333
@browse_blueprint.route('/browse/<course_name>', endpoint='browse_details')
3434
def details(course_name):
35+
theme_preference = request.cookies.get('theme', 'light') # Default to 'light' if cookie not found
36+
theme_css = theme_preference + "_theme" # Assuming your CSS files are named "light_theme.css" and "dark_theme.css"
3537

3638
# Check if the given course_name exists in the mapping, if not, return an error or redirect
3739
if course_name not in course_mapping:
38-
return render_template('components/error.html')
40+
return render_template('components/error.html', theme_css=theme_css )
3941

4042
# Get the corresponding course data from the course_mapping
4143
course = course_mapping[course_name]
4244
lectures_data = lecturesData.get(course_name, []) # Get lectures data for the course
4345

4446
trending = menuData.trending
45-
return render_template('details.html', course=course, lectures_data=lectures_data, trending=trending)
47+
return render_template('details.html', course=course, lectures_data=lectures_data, trending=trending, theme_css=theme_css)
4648

4749
####################### details end #######################
50+
51+
4852
################### General /browse page ###################
4953
@browse_blueprint.route('/browse', endpoint='browse_home', methods=['GET', 'POST']) # used when no course_name is provided
5054
def browse():
5155
trending = menuData.trending
5256
allCourses = menuData.all
5357
theme_preference = request.cookies.get('theme', 'light') # Default to 'light' if cookie not found
54-
theme_css = f"static/assets/sass/{theme_preference}_theme.css"
55-
58+
theme_css = theme_preference + "_theme" # Assuming your CSS files are named "light_theme.css" and "dark_theme.css"
59+
5660
# If the form is submitted (POST request), get the search keyword from the form
5761
if request.method == 'POST':
5862
search_keyword = request.form.get('searchKeyword')

routes/error_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
@error_blueprint.errorhandler(404)
77
def page_not_found(e):
88
theme_preference = request.cookies.get('theme', 'light') # Default to 'light' if cookie not found
9-
theme_css = f"static/assets/sass/{theme_preference}_theme.css"
9+
theme_css = theme_preference + "_theme" # Assuming your CSS files are named "light_theme.css" and "dark_theme.css
10+
1011
return render_template('components/error.html', theme_css=theme_css), 404

routes/index_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
def index():
99
trending = menuData.trending
1010
theme_preference = request.cookies.get('theme', 'light') # Default to 'light' if cookie not found
11-
theme_css = f"static/assets/sass/{theme_preference}_theme.css"
11+
theme_css = theme_preference + "_theme" # Assuming your CSS files are named "light_theme.css" and "dark_theme.css
12+
1213
return render_template('index.html', trending=trending, theme_css=theme_css)

routes/login_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
@login_blueprint.route('/login')
77
def login():
88
theme_preference = request.cookies.get('theme', 'light') # Default to 'light' if cookie not found
9-
theme_css = f"static/assets/sass/{theme_preference}_theme.css"
9+
theme_css = theme_preference + "_theme" # Assuming your CSS files are named "light_theme.css" and "dark_theme.css
10+
1011
return render_template('login.html', theme_css=theme_css)

static/assets/js/theme.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ function setCookie(name, value) {
33
}
44

55
function toggleTheme() {
6+
67
const currentTheme = document.querySelector("link[href*='theme']").getAttribute("href");
78
const newTheme = currentTheme.includes("light") ? "dark" : "light";
8-
document.querySelector("link[href*='theme']").setAttribute("href", `/static/assets/sass/${newTheme}_theme.css`);
99

10-
// Set the theme preference as a cookie
10+
// Set the theme preference as a cookie before changing the theme
1111
setCookie("theme", newTheme);
12+
13+
// Change the theme by updating the CSS link
14+
const themeLink = document.querySelector("link[href*='theme']");
15+
themeLink.setAttribute("href", `/static/assets/sass/${newTheme}_theme.css`);
1216
}

static/assets/sass/light_theme.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ figcaption {
2727
}
2828

2929
.cardborder:hover {
30-
border: 5px #D7EEFF solid;
30+
border: 5px #a5d8ff solid;
3131
}
3232

3333
clearfix:after {
@@ -110,7 +110,7 @@ img {
110110

111111
html,
112112
body {
113-
background: #D7EEFF;
113+
background: #a5d8ff;
114114
font-family: "Poppins", sans-serif;
115115
}
116116

@@ -225,7 +225,7 @@ section {
225225
left: 0;
226226
right: 0;
227227
bottom: 0;
228-
background-color: #D7EEFF;
228+
background-color: #a5d8ff;
229229
display: flex;
230230
align-items: center;
231231
justify-content: center;
@@ -679,7 +679,7 @@ section {
679679
}
680680
}
681681
.main-banner {
682-
background: linear-gradient(310deg, rgb(83, 141, 255) 0%, rgb(215, 238, 255) 100%);
682+
background: linear-gradient(310deg, rgb(83, 141, 255) 0%, #b2dcfc 100%);
683683
background-position: center center;
684684
background-size: cover;
685685
min-height: 380px;
@@ -708,7 +708,7 @@ section {
708708
.most-popular {
709709
margin-top: 60px;
710710
padding: 30px;
711-
background-color: #D7EEFF;
711+
background-color: #a5d8ff;
712712
border-radius: 23px;
713713
}
714714

@@ -771,7 +771,7 @@ section {
771771
.gaming-library {
772772
margin-top: 60px;
773773
padding: 30px;
774-
background-color: #D7EEFF;
774+
background-color: #a5d8ff;
775775
border-radius: 23px;
776776
}
777777

@@ -829,7 +829,7 @@ section {
829829
}
830830

831831
footer {
832-
background-color: #D7EEFF;
832+
background-color: #a5d8ff;
833833
bottom: 0;
834834
width: 100%;
835835
}
@@ -867,7 +867,7 @@ footer p a:hover {
867867
.game-details .content {
868868
border-radius: 23px;
869869
padding: 30px;
870-
background-color: #D7EEFF;
870+
background-color: #a5d8ff;
871871
}
872872

873873
.game-details .content .left-info {

0 commit comments

Comments
 (0)