2020-01-10 06:24:37 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
|
|
|
|
import './light.css';
|
|
|
|
import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
|
|
|
import moment from 'moment';
|
2020-01-15 05:12:00 +00:00
|
|
|
import { isInstructor, requester } from './utils.js';
|
2020-01-10 06:24:37 +00:00
|
|
|
import { NotFound, PleaseLogin } from './Misc.js';
|
2020-01-15 06:24:38 +00:00
|
|
|
import { InstructorCourseList, InstructorCourseDetail } from './Instructor.js';
|
2020-01-10 06:24:37 +00:00
|
|
|
|
|
|
|
export function Courses(props) {
|
|
|
|
const [courses, setCourses] = useState(false);
|
2020-01-15 05:12:00 +00:00
|
|
|
const { token, user } = props;
|
2020-01-10 06:24:37 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
requester('/courses/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setCourses(res.results);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
2020-01-10 23:56:10 +00:00
|
|
|
<Header size='large'>Courses</Header>
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2020-01-15 05:12:00 +00:00
|
|
|
{isInstructor && <Segment padded>
|
|
|
|
<InstructorCourseList courses={courses} setCourses={setCourses} {...props} />
|
|
|
|
</Segment>}
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
{courses ?
|
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Name</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
{courses.length ?
|
|
|
|
courses.map((x, i) =>
|
|
|
|
<Table.Row key={i}>
|
|
|
|
<Table.Cell>
|
|
|
|
<Link to={'/courses/'+x.id}>{x.name}</Link>
|
|
|
|
</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
)
|
|
|
|
:
|
2020-01-15 05:12:00 +00:00
|
|
|
<Table.Row><Table.Cell>None</Table.Cell></Table.Row>
|
2020-01-10 06:24:37 +00:00
|
|
|
}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
}
|
|
|
|
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export function CourseDetail(props) {
|
|
|
|
const [course, setCourse] = useState(false);
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const { token } = props;
|
|
|
|
const { id } = useParams();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
requester('/courses/'+id+'/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setCourse(res);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const getInstructor = (session) =>
|
|
|
|
session.instructor ? session.instructor.first_name : session.old_instructor;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
{!error ?
|
|
|
|
course ?
|
|
|
|
<div>
|
|
|
|
<Header size='large'>{course.name}</Header>
|
|
|
|
|
2020-01-15 06:24:38 +00:00
|
|
|
{isInstructor && <Segment padded>
|
|
|
|
<InstructorCourseDetail course={course} setCourse={setCourse} {...props} />
|
|
|
|
</Segment>}
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
<Header size='medium'>Course Description</Header>
|
2020-01-15 05:12:00 +00:00
|
|
|
{course.is_old ?
|
|
|
|
course.description.split('\n').map((x, i) =>
|
|
|
|
<p key={i}>{x}</p>
|
|
|
|
)
|
|
|
|
:
|
|
|
|
<div dangerouslySetInnerHTML={{__html: course.description}} />
|
|
|
|
}
|
2020-01-10 06:24:37 +00:00
|
|
|
|
|
|
|
<Header size='medium'>Classes</Header>
|
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Date</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Time</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Instructor</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Cost</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
{course.sessions.length ?
|
|
|
|
course.sessions.sort((a, b) => a.datetime < b.datetime).map((x, i) =>
|
|
|
|
<Table.Row key={i}>
|
|
|
|
<Table.Cell>
|
|
|
|
<Link to={'/classes/'+x.id}>
|
2020-01-10 07:39:05 +00:00
|
|
|
{moment.utc(x.datetime).format('ll')}
|
2020-01-10 06:24:37 +00:00
|
|
|
</Link>
|
|
|
|
</Table.Cell>
|
|
|
|
<Table.Cell>{moment.utc(x.datetime).format('LT')}</Table.Cell>
|
|
|
|
<Table.Cell>{getInstructor(x)}</Table.Cell>
|
|
|
|
<Table.Cell>{x.cost === '0.00' ? 'Free' : '$'+x.cost}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
)
|
|
|
|
:
|
2020-01-15 05:12:00 +00:00
|
|
|
<Table.Row><Table.Cell>None</Table.Cell></Table.Row>
|
2020-01-10 06:24:37 +00:00
|
|
|
}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
:
|
|
|
|
<NotFound />
|
|
|
|
}
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|