Skip to content

Commit ca2b14e

Browse files
committed
Move new course button
1 parent 3eee018 commit ca2b14e

File tree

1 file changed

+54
-62
lines changed

1 file changed

+54
-62
lines changed

frontend/src/components/pages/CourseDashboard.js

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -92,76 +92,68 @@ export function CourseDashboard() {
9292
if (!courseInfo) return <p>Loading...</p>;
9393
if (!userInfo) return <p>Loading...</p>;
9494

95-
var courseList = [];
96-
//Push all courses into courseList
95+
let createButton = null;
9796
if (userInfo.role === "educator"){
98-
courseInfo.forEach(course => {
99-
courseList.push(
100-
<a href={`/courses/${course.ID}`}>
101-
<div className="bg-gray-100 p-4 rounded shadow hover:bg-gray-300" >
102-
<h3 className="text-xl font-semibold" >{course.title}</h3>
103-
<p className="mt-2">{course.description}</p>
97+
createButton =
98+
<Popup trigger={<div className="bg-blue-500 p-2 rounded shadow hover:bg-blue-700 text-center text-sm text-white font-semibold hover:cursor-pointer" >
99+
<div>+ New Course</div> </div>} modal nested>
100+
{close => (
101+
<div className="flex-auto">
102+
<h3 className="font-semibold">
103+
Create New Course
104+
</h3>
105+
<div className="p-2">
106+
<label>Course Name: </label>
107+
<input className="border-2 border-black rounded p-2 size-11/12"
108+
type="text"
109+
name="title"
110+
onChange={handleChange}
111+
/>
104112
</div>
105-
</a>
106-
)
107-
});
108-
//Push the create course button at the end of courses
109-
courseList.push(
110-
<Popup trigger={<div className="bg-blue-500 p-4 rounded shadow hover:bg-blue-700 m-auto text-center text-xl text-white font-semibold hover:cursor-pointer" >
111-
<div>+ New Course</div> </div>} modal nested>
112-
{close => (
113-
<div className="flex-auto">
114-
<h3 className="font-semibold">
115-
Create New Course
116-
</h3>
117-
<div className="p-2">
118-
<label>Course Name: </label>
119-
<input className="border-2 border-black rounded p-2 size-11/12"
120-
type="text"
121-
name="title"
122-
onChange={handleChange}
123-
/>
124-
</div>
125-
<div className="p-2">
126-
<label>Course Description: </label>
127-
<input className="border-2 border-black rounded p-2 size-11/12"
128-
type="text"
129-
name="description"
130-
onChange={handleChange}
131-
/>
132-
</div>
133-
<div className="grid grid-rows-1 grid-cols-2">
134-
<button className="justify-self-start border-2 border-black p-1 rounded" onClick=
135-
{() => close()}>
136-
Cancel
137-
</button>
138-
<button className="justify-self-end border-2 border-black p-1 rounded bg-green-400"
139-
onClick={handleCreateCourse}>
140-
Create
141-
</button>
142-
</div>
113+
<div className="p-2">
114+
<label>Course Description: </label>
115+
<input className="border-2 border-black rounded p-2 size-11/12"
116+
type="text"
117+
name="description"
118+
onChange={handleChange}
119+
/>
143120
</div>
144-
)
145-
}
146-
</Popup>
147-
)
148-
}
149-
else{
150-
courseInfo.forEach(course => {
151-
courseList.push(
152-
<a href={`/courses/${course.ID}`}>
153-
<div className="bg-gray-100 p-4 rounded shadow hover:bg-gray-300" >
154-
<h3 className="text-xl font-semibold" >{course.title}</h3>
155-
<p className="mt-2">{course.description}</p>
121+
<div className="grid grid-rows-1 grid-cols-2">
122+
<button className="justify-self-start border-2 border-black p-1 rounded" onClick=
123+
{() => close()}>
124+
Cancel
125+
</button>
126+
<button className="justify-self-end border-2 border-black p-1 rounded bg-green-400"
127+
onClick={handleCreateCourse}>
128+
Create
129+
</button>
156130
</div>
157-
</a>
158-
)
159-
});
131+
</div>
132+
)
133+
}
134+
</Popup>
135+
160136
}
161137

138+
var courseList = [];
139+
//Push all courses into courseList
140+
courseInfo.forEach(course => {
141+
courseList.push(
142+
<a href={`/courses/${course.ID}`}>
143+
<div className="bg-gray-100 p-4 rounded shadow hover:bg-gray-300" >
144+
<h3 className="text-xl font-semibold" >{course.title}</h3>
145+
<p className="mt-2">{course.description}</p>
146+
</div>
147+
</a>
148+
)
149+
});
150+
162151
return (
163152
<div className="p-6">
164-
<h1 className="text-2xl font-bold mb-4">Courses</h1>
153+
<div className="flex justify-between flex-wrap mb-5">
154+
<h1 className="text-2xl font-bold">Courses</h1>
155+
{createButton}
156+
</div>
165157
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
166158
{courseList}
167159
</div>

0 commit comments

Comments
 (0)