From bf418b6a15942e6dbeec81dc08c56092af08e638 Mon Sep 17 00:00:00 2001
From: Tanner Collin
Date: Tue, 6 Sep 2022 21:56:51 +0000
Subject: [PATCH] Add search function to classes page
---
webclient/src/Classes.js | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/webclient/src/Classes.js b/webclient/src/Classes.js
index 648ca62..22978c7 100644
--- a/webclient/src/Classes.js
+++ b/webclient/src/Classes.js
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useReducer } from 'react';
import { Link, useParams } from 'react-router-dom';
import './light.css';
-import { Label, Button, Container, Dropdown, Form, Header, Icon, Segment, Table } from 'semantic-ui-react';
+import { Label, Button, Container, Dropdown, Form, Header, Icon, Input, Segment, Table } from 'semantic-ui-react';
import moment from 'moment-timezone';
import { apiUrl, isAdmin, getInstructor, BasicTable, requester, useIsMobile } from './utils.js';
import { NotFound } from './Misc.js';
@@ -305,6 +305,7 @@ export function ClassFeed(props) {
export function Classes(props) {
const [classes, setClasses] = useState(classesCache);
const [courses, setCourses] = useState(false);
+ const [search, setSearch] = useState('');
const [sortByCourse, setSortByCourse] = useState(sortCache);
const [tagFilter, setTagFilter] = useState(tagFilterCache);
const { token, user, refreshUser } = props;
@@ -334,6 +335,8 @@ export function Classes(props) {
const byDate = (a, b) => a.datetime > b.datetime ? 1 : -1;
const classesByTag = (x) => tagFilter ? x.course_data.tags.includes(tagFilter) : true;
const coursesByTag = (x) => tagFilter ? x.tags.includes(tagFilter) : true;
+ const classesBySearch = (x) => search ? x.course_data.name.toLowerCase().includes(search.toLowerCase()) : true;
+ const coursesBySearch = (x) => search ? x.name.toLowerCase().includes(search.toLowerCase()) : true;
return (
@@ -368,6 +371,21 @@ export function Classes(props) {
>
Sort by date
+
+ setSearch(event.target.value)}
+ aria-label='search products'
+ style={{ margin: '0.5rem 0.5rem 0.5rem 0' }}
+ />
+
+ {!!search.length &&
+
Filter by tag:
@@ -413,14 +431,14 @@ export function Classes(props) {
{classes.length && courses.length ?
sortByCourse ?
:
-
+
:
Loading...
}