Skip to content

Commit

Permalink
studentSemesters type array
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiarba committed May 2, 2021
1 parent 83477b9 commit d18703c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '../stylesheets/Roster.css';
import * as decode from 'jwt-decode';
import RosterCard from './RosterCard';
import 'antd/dist/antd.css';
import { Button } from 'antd';
import { Button, Radio } from 'antd';
import { UserRefreshClient } from 'google-auth-library';

const Roster = props => {
Expand Down
36 changes: 6 additions & 30 deletions client/src/components/RosterCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const RosterCard = props => {
const [displayNotes, setDisplayNotes] = useState(notes);
const [studentSemesters, setStudentSemesters] = useState(person.studentSemesters);
const [editedStudentSemesters, setEditedStudentSemesters] = useState(studentSemesters);
// const [displayStudentSemesters, setDisplayStudentSemesters] = useState(
// studentSemesters,
// );

const getCurrentSemester = () => {
const currDate = new Date();
Expand All @@ -43,28 +40,14 @@ const RosterCard = props => {
const onChangeStudentSemesters = checked => {
console.log('checked: ', checked);
console.log('is Toggle Active: ', isToggleActive());
let edited = editedStudentSemesters ? editedStudentSemesters : [];
let edited = [...editedStudentSemesters] ? [...editedStudentSemesters] : [];

console.log('edited prev: ', edited);

if (checked && !isToggleActive()) {
// const newKey = '' + edited.keys.length() + 1;

// edited = [...edited, { newKey: currSemester }];
edited.push(currSemester);
// if (edited) {
// edited = edited.push(currSemester);
// } else {
// edited = edited + currSemester;
// }
} else {
// edited.delete(edited.keys.length());
edited.pop();
// if (edited.includes(',')) {
// edited = edited.replace(', ' + currSemester, '');
// } else {
// edited = edited.replace(currSemester, ' ');
// }
}
console.log('edited: ', edited);
setEditedStudentSemesters(edited);
Expand Down Expand Up @@ -98,7 +81,6 @@ const RosterCard = props => {
setShowEditModal(false);
setDisplayNotes(editedNotes);
setEditedStudentSemesters(editedStudentSemesters);
// setDisplayStudentSemesters(editedStudentSemesters);
setStudentSemesters(editedStudentSemesters);
})
.catch(error => {
Expand Down Expand Up @@ -161,23 +143,20 @@ const RosterCard = props => {
checkedChildren="Active Student"
unCheckedChildren="Inactive Student"
defaultChecked={
// studentSemesters && studentSemesters.includes(currSemester)
editedStudentSemesters &&
editedStudentSemesters.includes(currSemester)
}
checked={
editedStudentSemesters &&
editedStudentSemesters.includes(currSemester)
// // : studentSemesters && studentSemesters.includes(currSemester)
}
onChange={onChangeStudentSemesters}
/>
</Col>
<Col>
{
editedStudentSemesters
// : displayStudentSemesters
}
{editedStudentSemesters
? editedStudentSemesters.join(', ')
: editedStudentSemesters}
</Col>
</Row>
</Modal>
Expand All @@ -193,7 +172,6 @@ const RosterCard = props => {
fetch(`/api/v1/roster/getUserSemester?uid=${id}`)
.then(res => res.json())
.then(userSemester => {
// setDisplayStudentSemesters([userSemester[0].semester]);
setEditedStudentSemesters([userSemester[0].semester]);
setStudentSemesters([userSemester[0].semester]);
});
Expand Down Expand Up @@ -261,8 +239,7 @@ const RosterCard = props => {
<span className="rosterCardItem" id="semestersAttendedBubble">
SEMESTERS
</span>{' '}
{/* {displayStudentSemesters} */}
{studentSemesters}
{studentSemesters ? studentSemesters.join(', ') : null}
</p>
<p>
<span className="rosterCardItem" id="notesBubble">
Expand Down Expand Up @@ -309,8 +286,7 @@ const RosterCard = props => {
<span className="rosterCardItem" id="semestersAttendedBubble">
SEMESTERS
</span>{' '}
{/* {displayStudentSemesters} */}
{studentSemesters}
{studentSemesters ? studentSemesters.join(', ') : null}
</p>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions client/src/stylesheets/Roster.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,12 @@ input[type='submit']:hover {
/* .editFields .ant-row {
padding: 20 0px;
} */

.studentFilterButtons {
border-radius: 15px;
margin-right: 10px;
margin-bottom: 20px;
font-family: Poppins;
font-size: 13px;
font-weight: 600;
}
2 changes: 1 addition & 1 deletion controllers/rosters_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const update = async (req, res) => {
.where({ id: req.body.id })
.update({
notes: req.body.editedNotes,
studentSemesters: req.body.editedStudentSemesters,
studentSemesters: knex.raw(req.body.editedStudentSemesters),
});
return res.status(200).send({ data });
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions db/migrations/20190221001732_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports.up = knex =>
table.string('notes');
table.string('candy');
table.string('hobby');
table.string('fact');
});

exports.down = knex => knex.raw(`DROP TABLE IF EXISTS "user" CASCADE`);

0 comments on commit d18703c

Please sign in to comment.