import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
import './light.css';
import { Button, Label, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment-timezone';
import { isInstructor, getInstructor, requester } from './utils.js';
import { NotFound, PleaseLogin } from './Misc.js';
import { InstructorCourseList, InstructorCourseDetail } from './InstructorCourses.js';
import { InstructorClassList } from './InstructorClasses.js';
export const tags = {
Protospace: 'black',
Laser: 'red',
Wood: 'brown',
CNC: 'orange',
Niche: 'yellow',
//name: 'olive',
Electronics: 'green',
Computers: 'teal',
Metal: 'blue',
//name: 'violet',
Event: 'purple',
Outing: 'pink',
Misc: 'grey',
};
let courseCache = false;
let tagFilterCache = false;
export function Courses(props) {
const [courses, setCourses] = useState(courseCache);
const [tagFilter, setTagFilter] = useState(tagFilterCache);
const { token, user } = props;
useEffect(() => {
requester('/courses/', 'GET', token)
.then(res => {
setCourses(res.results);
courseCache = res.results;
})
.catch(err => {
console.log(err);
});
}, []);
const byTag = (x) => tagFilter ? x.tags.includes(tagFilter) : true;
return (
Filter by tag:
{tagFilter && }
{courses ?Loading...
} ); }; export function CourseDetail(props) { const [course, setCourse] = useState(false); const [error, setError] = useState(false); const { token, user } = props; const { id } = useParams(); useEffect(() => { requester('/courses/'+id+'/', 'GET', token) .then(res => { setCourse(res); }) .catch(err => { console.log(err); setError(true); }); }, []); const now = new Date().toISOString(); return ({x}
) : }Loading...
: