Guest User

Untitled

a guest
Sep 21st, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.46 KB | None | 0 0
  1. "use client";
  2. import { Card, Space, Text, TextInput, rem, Select, MultiSelect, ScrollArea, Checkbox } from "@mantine/core";
  3. import { IconSearch } from "@tabler/icons-react";
  4. import { useState } from "react";
  5. import FilteredStudentList from "./FilteredStudentList";
  6. import { ProfileType } from "@prisma/client";
  7.  
  8. /* TODO: Map cs in search query to the actual COMPSCI name. so that when someone looks up cs 61c then
  9. they are going to get the right thing. */
  10.  
  11. export default function StudentSearch({highSchools, courses, students}) {
  12.  
  13. const icon = <IconSearch style={{ width: rem(16), height: rem(16) }} />;
  14. const [studentData, setStudentData] = useState(students);
  15. const [checked, setChecked] = useState(false);
  16. const [filters, setFilters] = useState({name: "", majors:[], courses:[], year: "", sex: "", relationshipStatus: "", housing: "", highSchool: "", checked: false});
  17.  
  18. const majors = [
  19. "Computer Science",
  20. "Econometrics And Quantitative Economics",
  21. "Cellular And Molecular Biology",
  22. "Computer And Information Sciences, Other",
  23. "Electrical And Electronics Engineering",
  24. "Political Science And Government",
  25. "Business Administration And Management",
  26. "Research And Experimental Psychology",
  27. "Sociology",
  28. "Media Studies",
  29. "Applied Mathematics",
  30. "Cognitive Science",
  31. "Environmental Studies",
  32. "English Language And Literature",
  33. "Legal Studies",
  34. "Public Health",
  35. "Mechanical Engineering",
  36. "Social Sciences",
  37. "Biology",
  38. "Chemistry",
  39. "Statistics",
  40. "History",
  41. "International Studies",
  42. "Civil Engineering",
  43. "Chemical Engineering",
  44. "Anthropology",
  45. "Nutrition Sciences",
  46. "Conservation",
  47. "Physics",
  48. "Mathematics",
  49. "Bioengineering And Biomedical Engineering",
  50. "Social Work",
  51. "Philosophy",
  52. "Environmental Science",
  53. "Film Studies",
  54. "Ethnic Studies",
  55. "Operations Research",
  56. "Linguistics",
  57. "Interdisciplinary Studies",
  58. "Hispanic And Latin American Languages, Literatures, And Linguistics",
  59. "Fine Arts",
  60. "Rhetoric And Composition",
  61. "American Studies",
  62. "Astrophysics",
  63. "Microbiology",
  64. "Art History, Criticism And Conservation",
  65. "Music",
  66. "Women's Studies",
  67. "Materials Science",
  68. "Natural Resources Conservation And Research",
  69. "Theatre Arts",
  70. "Comparative Literature",
  71. "Urban Studies",
  72. "Architecture",
  73. "Engineering Science",
  74. "French Language And Literature",
  75. "Landscape Architecture",
  76. "Chicano Studies",
  77. "Classical, Ancient Mediterranean And Near Eastern Studies And Archaeology",
  78. "African-American",
  79. "Engineering",
  80. "Botany",
  81. "Oceanography, Chemical And Physical",
  82. "Applied Physics",
  83. "Foreign Languages, Literatures, And Linguistics",
  84. "Nuclear Engineering",
  85. "Japanese Language And Literature",
  86. "Asian Studies",
  87. "Environmental Health Engineering",
  88. "Slavic Languages, Literatures, And Linguistics",
  89. "Forest Sciences And Biology",
  90. "Dance",
  91. "German Language And Literature",
  92. "Middle Eastern And Semitic Languages, Literatures, And Linguistics",
  93. "Geology",
  94. "Geophysics And Seismology",
  95. "Chinese Language And Literature",
  96. "Classics And Classical Languages, Literatures, And Linguistics",
  97. "Italian Language And Literature",
  98. "Latin Language And Literature",
  99. "Peace Studies And Conflict Resolution",
  100. "Planetary Astronomy And Science",
  101. "Atmospheric Sciences And Meteorology",
  102. "East Asian Languages, Literatures, And Linguistics",
  103. "Scandinavian Languages, Literatures, And Linguistics"
  104. ];
  105.  
  106. const sexText = {
  107. MALE: 'Male',
  108. FEMALE: 'Female',
  109. };
  110.  
  111. const relationshipStatusText = {
  112. SINGLE: 'Single',
  113. IN_RELATIONSHIP: 'In a Relationship',
  114. PREFER_NOT_TO_SAY: 'Prefer Not to Say',
  115. };
  116.  
  117. const yearText = {
  118. FRESHMEN: 'Freshman',
  119. SOPHOMORE: 'Sophomore',
  120. JUNIOR: 'Junior',
  121. SENIOR: 'Senior',
  122. };
  123.  
  124. const locationText = {
  125. UNIT_1: 'Unit 1',
  126. UNIT_2: 'Unit 2',
  127. UNIT_3: 'Unit 3',
  128. CLARK_KERR: 'Clark Kerr',
  129. BLACKWELL: 'Blackwell',
  130. OFF_CAMPUS: 'Off Campus',
  131. PEOPLES_PARK: "People's Park"
  132. };
  133.  
  134. const handleNameChange = (event) => {
  135. setFilters({ ...filters, name: event.target.value });
  136. };
  137.  
  138. const handleMajorChange = (selectedMajors) => {
  139. setFilters({...filters, majors: selectedMajors});
  140. };
  141.  
  142. const handleCourseChange = (selectedCourseNames) => {
  143. setFilters({...filters, courses: selectedCourseNames});
  144. };
  145.  
  146. const handleYearChange = (selectedYear) => {
  147. setFilters({ ...filters, year: selectedYear });
  148. };
  149.  
  150. const handleSexChange = (selectedSex) => {
  151. setFilters({ ...filters, sex: selectedSex });
  152. };
  153.  
  154. const handleRelationshipChange = (selectedRelationship) => {
  155. setFilters({ ...filters, relationshipStatus: selectedRelationship });
  156. };
  157.  
  158. const handleHousingChange = (selectedHousing) => {
  159. setFilters({ ...filters, housing: selectedHousing });
  160. };
  161.  
  162. const handleHighSchoolChange = (selectedHighSchool) => {
  163. setFilters({ ...filters, highSchool: selectedHighSchool });
  164. };
  165.  
  166. const handleAnonymousUsersCheckbox = (event) => {
  167. setFilters({...filters, checked: event.currentTarget.checked})
  168. setChecked(event.currentTarget.checked)
  169. };
  170.  
  171. function capitalizeWords(str) {
  172. return str
  173. .toLowerCase()
  174. .split(' ')
  175. .map(word => word.charAt(0).toUpperCase() + word.slice(1))
  176. .join(' ');
  177. }
  178.  
  179.  
  180. const filteredData = studentData.filter(item => {
  181. return (filters.name ? item.name.toLowerCase().includes(filters.name.toLowerCase()) : true) &&
  182. (filters.majors.length > 0 ? filters.majors.every(major => item.majors.includes(major)) : true) &&
  183. (filters.courses.length > 0 ? filters.courses.every(course => item.courses.includes(course)) : true) &&
  184. (filters.year ? item.year === filters.year : true) &&
  185. (filters.sex ? item.sex === filters.sex : true) &&
  186. (filters.relationshipStatus ? item.relationshipStatus === filters.relationshipStatus : true) &&
  187. (filters.housing ? item.housing === filters.housing: true) &&
  188. (filters.highSchool ? item.high_school === filters.highSchool: true) &&
  189. (filters.checked ? true : item.profileType === ProfileType.PUBLIC);
  190. });
  191.  
  192. return (
  193. <>
  194. <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: '10px', paddingRight:'10px'}}>
  195. <ScrollArea>
  196. <Card p={20} w="100%" h={"100%"} bg="var(--color-component)">
  197. <Text size="xl" fw={600}>Search</Text>
  198. <Space w="xl" />
  199.  
  200. <Checkbox py={'12px'} fw={500} label={"Include Anonymous Users"} checked={checked} onChange={handleAnonymousUsersCheckbox}>
  201. </Checkbox>
  202.  
  203. <TextInput
  204. my='10px'
  205. label="Name"
  206. leftSectionPointerEvents="none"
  207. leftSection={icon}
  208. placeholder="Search by name"
  209. value={filters.name}
  210. onChange={handleNameChange}
  211. />
  212.  
  213. <MultiSelect
  214. label="Majors"
  215. value={filters.majors}
  216. onChange={handleMajorChange}
  217. placeholder="Pick value"
  218. data={majors}
  219. searchable
  220. />
  221.  
  222. <MultiSelect
  223. label="Courses (EX: COMPSCI 61A)"
  224. value={filters.courses}
  225. onChange={handleCourseChange}
  226. placeholder="Pick value"
  227. limit={15}
  228. data={courses}
  229. searchable
  230. />
  231.  
  232. <Select
  233. w={"100%"}
  234. label="Class Year"
  235. onChange={handleYearChange}
  236. data={Object.keys(yearText).map((key) => ({
  237. value: key,
  238. label: yearText[key],
  239. }))}
  240. />
  241.  
  242. <Select
  243. w={"100%"}
  244. label={"Sex"}
  245. onChange={handleSexChange}
  246. data={Object.keys(sexText).map((key) => ({
  247. value: key,
  248. label: sexText[key],
  249. }))}
  250. />
  251.  
  252.  
  253. <Select
  254. w={"100%"}
  255. label={"Relationship Status"}
  256. onChange={handleRelationshipChange}
  257. data={Object.keys(relationshipStatusText).map((key) => ({
  258. value: key,
  259. label: relationshipStatusText[key],
  260. }))}
  261. />
  262.  
  263.  
  264. <Select
  265. w={"100%"}
  266. label={"Housing Situation"}
  267. onChange={handleHousingChange}
  268. data={Object.keys(locationText).map((key) => ({
  269. value: key,
  270. label: locationText[key],
  271. }))}
  272. />
  273.  
  274. <Select
  275. w={"100%"}
  276. label={"High School"}
  277. onChange={handleHighSchoolChange}
  278.  
  279. data={highSchools.map(highSchool => capitalizeWords(highSchool))}
  280. placeholder="Pick value"
  281. limit={25}
  282. value={filters.highSchool}
  283. searchable
  284. />
  285.  
  286.  
  287. {/* <Select
  288. my='10px'
  289. label="Department"
  290. placeholder="Pick a category"
  291. data={departments}
  292. value={filters.department}
  293. onChange={handleDepartmentChange}
  294. searchable
  295. /> */}
  296. </Card>
  297. </ScrollArea>
  298. </div>
  299.  
  300. <div style={{ flex: 1, paddingRight:'10px'}}>
  301. <FilteredStudentList data={filteredData}/>
  302. {/* <FilteredCourseList data={filteredData} /> */}
  303. </div>
  304. </>
  305. );
  306. }
  307.  
Advertisement
Add Comment
Please, Sign In to add comment