Skip to content

Commit 0ccd6b0

Browse files
Worked to make the classpage more responsive to phone, so it looks better
1 parent b71ae68 commit 0ccd6b0

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

src/components/ClassPage.css

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77

88
.side-bar {
9+
display: block;
910
grid-area: sidebar;
1011
background-color: #f0f0f0;
1112
padding: 20px;
@@ -114,3 +115,73 @@ ul {
114115
text-decoration: underline; /* Add underline on hover */
115116
}
116117

118+
119+
/* Dropdown Menu */
120+
.dropdown {
121+
position: relative;
122+
display: none;
123+
}
124+
125+
.dropdown-icon {
126+
margin-left : 10px;
127+
}
128+
129+
130+
@media screen and (max-width: 768px) {
131+
132+
.department-container {
133+
display: grid;
134+
grid-template-rows: auto;
135+
grid-template-columns: auto; /* Change to auto for single column layout */
136+
grid-template-areas: "main"; /* Only main area on smaller screens */
137+
}
138+
139+
.side-bar {
140+
display: none; /* Hide sidebar on smaller screens */
141+
}
142+
143+
.dropdown {
144+
display: inline-block; /* Show dropdown button on smaller screens */
145+
}
146+
147+
/* Dropdown Button */
148+
.dropbtn {
149+
background-color: #721212;
150+
color: white;
151+
padding: 10px;
152+
font-size: 16px;
153+
border: none;
154+
cursor: pointer;
155+
}
156+
157+
/* Dropdown Content (Hidden by Default) */
158+
.dropdown-content {
159+
display: none;
160+
position: absolute;
161+
background-color: #f9f9f9;
162+
min-width: 160px;
163+
z-index: 1;
164+
}
165+
166+
/* Links inside the dropdown */
167+
.dropdown-content button {
168+
display: block;
169+
padding: 10px;
170+
text-decoration: none;
171+
color: black;
172+
}
173+
174+
/* Change color of dropdown links on hover */
175+
.dropdown-content button:hover {
176+
background-color: #ddd;
177+
}
178+
179+
/* Show the dropdown menu on hover */
180+
.dropdown:hover .dropdown-content {
181+
display: block;
182+
}
183+
184+
185+
186+
}
187+

src/components/ClassPage.jsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const ClassPage = () => {
9494
const [newPostTitle, setNewPostTitle] = useState('');
9595
const [newPostContent, setNewPostContent] = useState('');
9696
const [activeClass, setActiveClass] = useState(null); //working on this
97+
const [dropdownVisible, setDropdownVisible ] = useState(false);
98+
9799

98100
useEffect(() => {
99101
const fetchCoursesFromBackend = async () => {
@@ -132,8 +134,9 @@ const ClassPage = () => {
132134
};
133135

134136

135-
const handleClassClick = async (courseId) => {
136-
setActiveClass(courseId);
137+
const handleClassClick = async (course) => {
138+
const courseId = course.id;
139+
setActiveClass(course);
137140
try {
138141
const response = await axios.get(`https://courseconnect-delta.vercel.app/api/posts/${courseId}`);
139142
console.log(response)
@@ -180,7 +183,7 @@ const ClassPage = () => {
180183
content: newPostContent,
181184
username: userId,
182185
timestamp: new Date().toISOString(),
183-
course: activeClass // hardcoded for now
186+
course: activeClass.id
184187
};
185188
try {
186189
const response = await axios.post('https://courseconnect-delta.vercel.app/api/posts', newPost);
@@ -197,14 +200,26 @@ const ClassPage = () => {
197200
}
198201
};
199202

203+
204+
const toggleDropdown = () => {
205+
setDropdownVisible((prevVisible) => !prevVisible);
206+
};
207+
208+
// Function to handle course selection from the dropdown menu
209+
const handleCourseSelection = (course) => {
210+
handleClassClick(course); // Function to load posts for the selected course
211+
setDropdownVisible(false); // Hide the dropdown menu after selection
212+
};
213+
200214
return (
201215
<div className="department-container">
216+
202217
<div className="side-bar">
203218
<h2>Courses</h2>
204219
<ul>
205220
{courses.map((course, index) => (
206221
<button
207-
onClick={() => handleClassClick(course.id)}
222+
onClick={() => handleClassClick(course)}
208223
key={index}
209224
className={activeClass === course.id ? 'active' : ''}
210225
>
@@ -214,6 +229,20 @@ const ClassPage = () => {
214229
</ul>
215230
</div>
216231
<div className='main'>
232+
233+
<div className="dropdown">
234+
<button className="dropbtn" onClick={toggleDropdown}>{activeClass ? activeClass.name : 'Select Course'}<span className="dropdown-icon">&#9660;</span></button>
235+
{dropdownVisible && (
236+
<div className="dropdown-content">
237+
{courses.map((course) => (
238+
<button key={course.id} onClick={() => handleCourseSelection(course)}>
239+
{course.name}
240+
</button>
241+
))}
242+
</div>
243+
)}
244+
</div>
245+
217246
<h2>Posts</h2>
218247
{!showNewPostForm ? (
219248
<button onClick={createNewPost}>Create New Post</button>

src/components/LoginPage.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ button {
4545
font-size: 16px;
4646
cursor: pointer;
4747
transition: background-color 0.3s ease; /* Transition for button hover */
48+
margin-bottom: 10px;
4849
}
4950

5051
button:hover {

0 commit comments

Comments
 (0)