Skip to content

Commit 0b4e4ef

Browse files
authored
refactor(ui): refactor sidebar on the challenge page (laike9m#42)
* chore: adjust theme switcher size * chore: add sidebar nav * Refactor challenge layout * feat: improve many ui details * chore: improve some details for sidebar * chore: adjust index and challenge_card layout details * Fix sidebar alignment * Update transition duration in challenge sidebar
1 parent da706e7 commit 0b4e4ef

File tree

7 files changed

+188
-76
lines changed

7 files changed

+188
-76
lines changed

templates/challenge.html

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@
1515
<style type="text/css">
1616
.challenge-container {
1717
display: flex;
18-
padding: 1rem 2rem;
19-
max-height: 100vh;
20-
width: max(95vw, 95%);
18+
height: 100dvh;
2119
}
2220

2321
/* Sidebar Area */
2422
.sidebar-container {
2523
display: flex;
2624
flex-direction: column;
2725
align-items: center;
28-
margin-right: 2rem;
26+
padding-bottom: 12px;
27+
border-right: 1px solid hsl(205, 20%, 94%);
2928
}
3029

31-
.sidebar-container .sidebar-challenge-list {
30+
.sidebar-container .sidebar-challenge-main {
3231
overflow-y: auto;
33-
max-width: fit-content;
34-
min-width: 100px;
32+
padding-left: 8px;
33+
padding-right: 8px;
3534
}
3635

3736
.sidebar-container .sidebar-actions {
@@ -48,6 +47,7 @@
4847
.challenge-area {
4948
display: flex;
5049
flex-direction: column;
50+
margin: 0 2rem;
5151
width: 100%;
5252
}
5353

@@ -58,9 +58,10 @@
5858
}
5959

6060
.challenge-header__title>span:nth-child(1) {
61-
font-size: 30px;
62-
font-weight: bold;
61+
font-size: 35px;
62+
font-weight: 700;
6363
margin-right: 20px;
64+
margin-top: 8px;
6465
}
6566

6667
.challenge-header__exerpt {
@@ -138,18 +139,29 @@
138139
align-items: center;
139140
margin-top: 20px;
140141
height: 100%;
141-
width: 100%;
142+
padding: 8px 12px;
142143
}
143144

144145
.sidebar-container {
145-
overflow-y: auto;
146146
margin-right: 0;
147147
margin-bottom: 2rem;
148-
min-height: 100px;
148+
flex-direction: row;
149+
width: 100%;
150+
border-right: 0px;
151+
gap: 4px;
149152
}
150153

151-
.sidebar-container .sidebar-challenge-list {
154+
.sidebar-container .sidebar-challenge-main {
152155
height: 100%;
156+
padding-left: 0px;
157+
margin-right: auto;
158+
}
159+
160+
.sidebar-container .sidebar-actions {
161+
margin-top: 0px;
162+
padding-top: 0px;
163+
border-top: 0px;
164+
width: initial;
153165
}
154166

155167
.challenge-header__title {
@@ -189,11 +201,11 @@
189201
{% endblock %}
190202

191203
{% block content %}
192-
<div class="challenge-container container-fluid">
204+
<div class="challenge-container">
193205
<!-- Left/Top Sidebar -->
194206
<div class="sidebar-container">
195-
<div class="sidebar-challenge-list">
196-
{% include 'components/challenge_list.html' %}
207+
<div class="sidebar-challenge-main">
208+
{% include 'components/challenge_sidebar.html' with context %}
197209
</div>
198210
<div class="sidebar-actions">
199211
{% include 'components/darkmode.html' %}
@@ -323,4 +335,4 @@
323335
checkWidth(); // Check the width initially
324336
window.addEventListener('resize', checkWidth);
325337
</script>
326-
{% endblock %}
338+
{% endblock %}

templates/components/challenge_card.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
align-items: center;
2626
gap: 8px;
2727
}
28+
29+
@media only screen and (max-width: 1080px) and (min-width: 800px) {
30+
.challenges {
31+
grid-template-columns: repeat(2, 1fr);
32+
}
33+
}
34+
35+
@media only screen and (max-width: 800px) {
36+
.challenge-card .challenge-card__list {
37+
display: grid;
38+
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
39+
justify-items: center;
40+
width: 100%;
41+
}
42+
}
2843
</style>
2944

3045
<div class="challenge-card">
@@ -34,4 +49,4 @@ <h3 class="challenge-card__level">{{level}}</h3>
3449
<a href="/{{ level }}/{{ name }}">{{ name }}</a>
3550
{% endfor %}
3651
</div>
37-
</div>
52+
</div>

templates/components/challenge_list.html

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<style>
2+
/* override picocss default style */
3+
nav ol:first-of-type,
4+
nav ul:first-of-type {
5+
margin-left: 0;
6+
}
7+
8+
.challenge-nav {
9+
display: flex;
10+
flex-direction: column;
11+
}
12+
13+
.challenge-nav ul li {
14+
padding: 0px 8px;
15+
}
16+
17+
.challenge-nav ul li:not(:first-of-type) a {
18+
padding: 8px 10px;
19+
}
20+
21+
.challenge-nav .challenge-level {
22+
width: fit-content;
23+
border-bottom: 1px dashed hsl(240, 2%, 90%);
24+
text-transform: uppercase;
25+
letter-spacing: 1px;
26+
font-size: 20px;
27+
font-weight: bold;
28+
margin: 1rem 0px;
29+
}
30+
31+
.challenge-nav ul:nth-child(1)>li:nth-child(1) {
32+
position: relative;
33+
}
34+
35+
.sidebar-toggle {
36+
display: none;
37+
}
38+
39+
40+
@media only screen and (max-width: 800px) {
41+
.sidebar-toggle {
42+
display: flex;
43+
gap: 4px;
44+
cursor: pointer;
45+
}
46+
47+
.sidebar-toggle-close {
48+
margin-left: auto;
49+
position: absolute;
50+
top: 50%;
51+
right: 0;
52+
transform: translateY(-50%);
53+
cursor: pointer;
54+
}
55+
56+
.drawer {
57+
position: fixed;
58+
top: 0;
59+
left: -100%;
60+
width: fit-content;
61+
padding: 4px 8px;
62+
height: 100%;
63+
/* use picocss default css variable. see: https://github.com/picocss/pico/blob/master/css/themes/default.css */
64+
background: var(--background-color);
65+
box-shadow: 0 0 10px #00000080;
66+
transition: left 0.2s ease-in-out;
67+
z-index: 1;
68+
overflow-y: auto;
69+
}
70+
71+
.drawer-container {
72+
position: relative;
73+
}
74+
75+
76+
.drawer.open {
77+
left: 0;
78+
}
79+
}
80+
</style>
81+
82+
<span class="sidebar-toggle">
83+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 1024 1024">
84+
<path fill="currentColor"
85+
d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM142.4 642.1L298.7 519a8.84 8.84 0 0 0 0-13.9L142.4 381.9c-5.8-4.6-14.4-.5-14.4 6.9v246.3a8.9 8.9 0 0 0 14.4 7z" />
86+
</svg>
87+
<span>All Challenges</span>
88+
</span>
89+
90+
<aside class="drawer">
91+
<nav class="challenge-nav drawer-container">
92+
{% for level, challenge_names in challenges_groupby_level.items() %}
93+
<ul>
94+
<!-- Compose close button with first level in row -->
95+
{% if level == "basic" %}
96+
<li>
97+
<h5 class="challenge-level">{{ level }}</h5>
98+
<span class="sidebar-toggle sidebar-toggle-close">
99+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
100+
<path fill="currentColor"
101+
d="M6.4 19L5 17.6l5.6-5.6L5 6.4L6.4 5l5.6 5.6L17.6 5L19 6.4L13.4 12l5.6 5.6l-1.4 1.4l-5.6-5.6L6.4 19Z" />
102+
</svg>
103+
</span>
104+
</li>
105+
{% else %}
106+
<li>
107+
<h5 class="challenge-level">{{ level }}</h5>
108+
</li>
109+
{% endif %}
110+
{% for name in challenge_names %}
111+
<li><a href="/{{ level }}/{{ name }}">{{ name }}</a></li>
112+
{% endfor %}
113+
</ul>
114+
{% endfor %}
115+
</nav>
116+
</aside>
117+
118+
<script>
119+
const sidebarTogglers = document.querySelectorAll('.sidebar-toggle');
120+
const drawer = document.querySelector('.drawer');
121+
122+
sidebarTogglers.forEach((toggler) => {
123+
toggler.addEventListener('click', () => {
124+
drawer.classList.toggle('open');
125+
});
126+
});
127+
</script>

templates/components/darkmode.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
display: flex;
55
place-items: center;
66
position: relative;
7-
height: 24px;
8-
width: 24px;
7+
height: 20px;
8+
width: 20px;
99
}
1010

1111
#theme-switch {
1212
display: none;
1313
}
1414

15-
.icon-sun, .icon-moon {
15+
.icon-sun,
16+
.icon-moon {
1617
position: absolute;
1718
left: 0;
1819
top: 0;
@@ -27,11 +28,11 @@
2728
opacity: 0;
2829
}
2930

30-
#theme-switch:checked ~ label .icon-sun {
31+
#theme-switch:checked~label .icon-sun {
3132
opacity: 0;
3233
}
3334

34-
#theme-switch:checked ~ label .icon-moon {
35+
#theme-switch:checked~label .icon-moon {
3536
opacity: 1;
3637
}
3738
</style>
@@ -40,8 +41,14 @@
4041
<div class="theme-switcher">
4142
<input type="checkbox" id="theme-switch" />
4243
<label for="theme-switch">
43-
<svg class="icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 256 256"><path fill="currentColor" d="M120 40V16a8 8 0 0 1 16 0v24a8 8 0 0 1-16 0Zm72 88a64 64 0 1 1-64-64a64.07 64.07 0 0 1 64 64Zm-16 0a48 48 0 1 0-48 48a48.05 48.05 0 0 0 48-48ZM58.34 69.66a8 8 0 0 0 11.32-11.32l-16-16a8 8 0 0 0-11.32 11.32Zm0 116.68l-16 16a8 8 0 0 0 11.32 11.32l16-16a8 8 0 0 0-11.32-11.32ZM192 72a8 8 0 0 0 5.66-2.34l16-16a8 8 0 0 0-11.32-11.32l-16 16A8 8 0 0 0 192 72Zm5.66 114.34a8 8 0 0 0-11.32 11.32l16 16a8 8 0 0 0 11.32-11.32ZM48 128a8 8 0 0 0-8-8H16a8 8 0 0 0 0 16h24a8 8 0 0 0 8-8Zm80 80a8 8 0 0 0-8 8v24a8 8 0 0 0 16 0v-24a8 8 0 0 0-8-8Zm112-88h-24a8 8 0 0 0 0 16h24a8 8 0 0 0 0-16Z"/></svg>
44-
<svg class="icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 256 256"><path fill="currentColor" d="M235.54 150.21a104.84 104.84 0 0 1-37 52.91A104 104 0 0 1 32 120a103.09 103.09 0 0 1 20.88-62.52a104.84 104.84 0 0 1 52.91-37a8 8 0 0 1 10 10a88.08 88.08 0 0 0 109.8 109.8a8 8 0 0 1 10 10Z"/></svg>
44+
<svg class="icon-sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
45+
<path fill="currentColor"
46+
d="M120 40V16a8 8 0 0 1 16 0v24a8 8 0 0 1-16 0Zm72 88a64 64 0 1 1-64-64a64.07 64.07 0 0 1 64 64Zm-16 0a48 48 0 1 0-48 48a48.05 48.05 0 0 0 48-48ZM58.34 69.66a8 8 0 0 0 11.32-11.32l-16-16a8 8 0 0 0-11.32 11.32Zm0 116.68l-16 16a8 8 0 0 0 11.32 11.32l16-16a8 8 0 0 0-11.32-11.32ZM192 72a8 8 0 0 0 5.66-2.34l16-16a8 8 0 0 0-11.32-11.32l-16 16A8 8 0 0 0 192 72Zm5.66 114.34a8 8 0 0 0-11.32 11.32l16 16a8 8 0 0 0 11.32-11.32ZM48 128a8 8 0 0 0-8-8H16a8 8 0 0 0 0 16h24a8 8 0 0 0 8-8Zm80 80a8 8 0 0 0-8 8v24a8 8 0 0 0 16 0v-24a8 8 0 0 0-8-8Zm112-88h-24a8 8 0 0 0 0 16h24a8 8 0 0 0 0-16Z" />
47+
</svg>
48+
<svg class="icon-moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
49+
<path fill="currentColor"
50+
d="M235.54 150.21a104.84 104.84 0 0 1-37 52.91A104 104 0 0 1 32 120a103.09 103.09 0 0 1 20.88-62.52a104.84 104.84 0 0 1 52.91-37a8 8 0 0 1 10 10a88.08 88.08 0 0 0 109.8 109.8a8 8 0 0 1 10 10Z" />
51+
</svg>
4552
</label>
4653

4754

templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
flex-direction: column;
1414
justify-content: center;
1515
align-items: center;
16-
height: 100vh;
16+
padding: 1rem;
1717
font-family: 'IBM Plex Mono', monospace;
1818
}
1919

views/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
request,
1111
)
1212

13-
from .challenge import challenge_manager, Level, ChallengeKey
13+
from .challenge import ChallengeKey, Level, challenge_manager
1414
from .sitemap import sitemapper
1515

1616
app_views = Blueprint("app_views", __name__)

0 commit comments

Comments
 (0)