Skip to content

Commit c36371d

Browse files
Merge pull request #13 from SatyaRajAwasth1/satyarajawasth1-patch
refactor: Updates design of sidebar and profiles page
2 parents 26ff9c0 + 051bc76 commit c36371d

File tree

3 files changed

+103
-30
lines changed

3 files changed

+103
-30
lines changed

src/components/MainContent.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<main class="flex-1 p-4">
1+
<main>
22
<slot />
33
</main>

src/components/shared/LeftSidebar.astro

+84-13
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,91 @@ const currentYear = (new Date()).getFullYear();
44
const yearsRange = Array.from({ length: currentYear - startYear + 1 }, (_, i) => startYear + i);
55
---
66

7-
<nav class="w-64 bg-gray-200 p-4">
8-
<ul>
7+
<nav id="sidebar" class="w-64 bg-gray-800 text-white p-4 fixed inset-y-0 left-0 transform transition-transform duration-200 ease-in-out -translate-x-full sm:translate-x-0 sm:relative z-30 overflow-y-auto h-full">
8+
<div class="flex justify-between items-center mb-4">
9+
<span class="text-lg font-bold">Menu</span>
10+
<button id="closeBtn" class="text-white">
11+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
12+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
13+
</svg>
14+
</button>
15+
</div>
16+
17+
<ul class="space-y-2">
918
{yearsRange.map((year) => (
10-
<li>
11-
<a href={`/profiles/${year}`}>{year}</a>
12-
</li>
19+
<li>
20+
<a href={`/profiles/${year}`} class="block p-2 hover:bg-gray-700 rounded transition">
21+
{year}
22+
</a>
23+
</li>
1324
))}
1425
</ul>
15-
<hr />
16-
<ul>
17-
<li><a href="/profiles/it">IT</a></li>
18-
<li><a href="/profiles/elx">ELX</a></li>
19-
<li><a href="/profiles/cmp">COMP</a></li>
20-
<li><a href="/profiles/se">SE</a></li>
21-
<li><a href="/profiles/civil">CIVIL</a></li>
26+
27+
<hr class="my-4 border-gray-600" />
28+
29+
<ul class="space-y-2">
30+
<li><a href="/profiles/it" class="block p-2 hover:bg-gray-700 rounded transition">IT</a></li>
31+
<li><a href="/profiles/elx" class="block p-2 hover:bg-gray-700 rounded transition">ELX</a></li>
32+
<li><a href="/profiles/cmp" class="block p-2 hover:bg-gray-700 rounded transition">COMP</a></li>
33+
<li><a href="/profiles/se" class="block p-2 hover:bg-gray-700 rounded transition">SE</a></li>
34+
<li><a href="/profiles/civil" class="block p-2 hover:bg-gray-700 rounded transition">CIVIL</a></li>
2235
</ul>
23-
</nav>
36+
</nav>
37+
38+
<div id="backdrop" class="fixed inset-0 bg-black bg-opacity-50 z-20 hidden"></div>
39+
40+
<button id="toggleBtn" class="sm:hidden text-white fixed top-4 left-4 z-40">
41+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
42+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16m-7 6h7" />
43+
</svg>
44+
</button>
45+
46+
<script>
47+
document.addEventListener('DOMContentLoaded', () => {
48+
const sidebar = document.getElementById('sidebar');
49+
const backdrop = document.getElementById('backdrop');
50+
const toggleBtn = document.getElementById('toggleBtn');
51+
const closeBtn = document.getElementById('closeBtn');
52+
53+
function toggleSidebar() {
54+
console.log("opening sidebar")
55+
const isHidden = sidebar.classList.toggle('-translate-x-full');
56+
backdrop.classList.toggle('hidden', isHidden);
57+
if (!isHidden) {
58+
document.body.style.overflow = 'hidden'; // Disable scrolling
59+
} else {
60+
document.body.style.overflow = ''; // Enable scrolling
61+
}
62+
}
63+
64+
function closeSidebar() {
65+
console.log("closing sidebar")
66+
sidebar.classList.add('-translate-x-full');
67+
backdrop.classList.add('hidden');
68+
document.body.style.overflow = ''; // Enable scrolling
69+
}
70+
71+
toggleBtn.addEventListener('click', toggleSidebar);
72+
closeBtn.addEventListener('click', closeSidebar);
73+
backdrop.addEventListener('click', closeSidebar);
74+
});
75+
</script>
76+
77+
78+
<style>
79+
@media (min-width: 640px) {
80+
#sidebar {
81+
transform: translateX(0);
82+
}
83+
}
84+
85+
@media (max-width: 639px) {
86+
#sidebar {
87+
transform: -translateX(-100%);
88+
}
89+
}
90+
91+
#backdrop {
92+
transition: opacity 0.3s ease;
93+
}
94+
</style>

src/pages/profiles/index.astro

+18-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,24 @@ const sortedYears = Array.from(batchMap.keys()).sort();
3333
---
3434

3535
<TwoColLayout>
36-
{sortedYears.map((year) => {
37-
let showAll = false;
38-
39-
return (
40-
<div class="mb-8">
41-
<h3 class="text-lg font-bold flex items-center justify-between">
42-
{year} Batch
43-
</h3>
44-
<div class="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mt-4 text-white">
45-
{(showAll ? batchMap.get(year) : batchMap.get(year).slice(0, 3))
46-
.map((profile) => (
47-
<ProfileCard key={profile.slug} slug={profile.slug} {...profile.data} />
48-
))}
36+
<section class="bg-gray-900 text-white p-4 sm:p-6 lg:p-8">
37+
{sortedYears.map((year) => {
38+
let showAll = false;
39+
40+
return (
41+
<div class="mb-8">
42+
<h3 class="text-lg sm:text-xl lg:text-2xl font-bold flex items-center justify-between">
43+
{year} Batch
44+
</h3>
45+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 mt-4">
46+
{(showAll ? batchMap.get(year) : batchMap.get(year).slice(0, 3))
47+
.map((profile) => (
48+
<ProfileCard slug={profile.slug} {...profile.data} />
49+
))}
50+
</div>
4951
</div>
50-
</div>
51-
);
52-
})}
52+
);
53+
})}
54+
</section>
5355
</TwoColLayout>
5456

0 commit comments

Comments
 (0)