Skip to content

Commit 454bec1

Browse files
feat(components): searchbar -> searchfield
1 parent d1ef574 commit 454bec1

File tree

5 files changed

+25
-79
lines changed

5 files changed

+25
-79
lines changed

client/app/bundles/course/announcements/components/misc/AnnouncementsDisplay.tsx

+10-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'types/course/announcements';
1010
import { Operation } from 'types/store';
1111

12-
import SearchBar from 'lib/components/core/fields/SearchBar';
12+
import SearchField from 'lib/components/core/fields/SearchField';
1313
import Pagination from 'lib/components/core/layouts/Pagination';
1414

1515
import AnnouncementCard from './AnnouncementCard';
@@ -56,21 +56,17 @@ const AnnouncementsDisplay: FC<Props> = (props) => {
5656
setShavedAnnouncements(announcements);
5757
}, [announcements]);
5858

59-
const handleSearchBarChange = (
60-
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
61-
): void => {
62-
if (event.target.value.trim() === '') {
59+
const handleSearchBarChange = (rawKeyword: string): void => {
60+
const keyword = rawKeyword.trim();
61+
62+
if (keyword === '') {
6363
setShavedAnnouncements(announcements);
6464
} else {
6565
setShavedAnnouncements(
6666
announcements.filter(
6767
(announcement: AnnouncementMiniEntity) =>
68-
announcement.title
69-
.toLowerCase()
70-
.includes(event.target.value.trim().toLowerCase()) ||
71-
announcement.content
72-
.toLowerCase()
73-
.includes(event.target.value.trim().toLowerCase()),
68+
announcement.title.toLowerCase().includes(keyword.toLowerCase()) ||
69+
announcement.content.toLowerCase().includes(keyword.toLowerCase()),
7470
),
7571
);
7672
}
@@ -88,12 +84,12 @@ const AnnouncementsDisplay: FC<Props> = (props) => {
8884
xs={1}
8985
>
9086
<div style={{ paddingTop: 7, paddingBottom: 5 }}>
91-
<SearchBar
92-
onChange={handleSearchBarChange}
87+
<SearchField
88+
className="w-[350px]"
89+
onChangeKeyword={handleSearchBarChange}
9390
placeholder={intl.formatMessage(
9491
translations.searchBarPlaceholder,
9592
)}
96-
width={350}
9793
/>
9894
</div>
9995
</Grid>

client/app/bundles/course/courses/components/misc/CourseDisplay.tsx

+12-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
33
import { Grid } from '@mui/material';
44
import { CourseMiniEntity } from 'types/course/courses';
55

6-
import SearchBar from 'lib/components/core/fields/SearchBar';
6+
import SearchField from 'lib/components/core/fields/SearchField';
77
import Pagination from 'lib/components/core/layouts/Pagination';
88
import Note from 'lib/components/core/Note';
99

@@ -40,17 +40,15 @@ const CourseDisplay: FC<Props> = (props) => {
4040
return <Note message={intl.formatMessage(translations.noCourse)} />;
4141
}
4242

43-
const handleSearchBarChange = (
44-
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
45-
): void => {
46-
if (event.target.value === '') {
43+
const handleSearchBarChange = (rawKeyword: string): void => {
44+
const keyword = rawKeyword.trim();
45+
46+
if (keyword === '') {
4747
setShavedCourses(courses);
4848
} else {
4949
setShavedCourses(
5050
courses.filter((course: CourseMiniEntity) =>
51-
course.title
52-
.toLowerCase()
53-
.includes(event.target.value.trim().toLowerCase()),
51+
course.title.toLowerCase().includes(keyword.toLowerCase()),
5452
),
5553
);
5654
}
@@ -64,17 +62,15 @@ const CourseDisplay: FC<Props> = (props) => {
6462
style={{
6563
display: 'flex',
6664
justifyContent: 'left',
65+
paddingTop: 16,
66+
paddingBottom: 16,
6767
}}
6868
xs={1}
6969
>
70-
<div style={{ paddingTop: 16, paddingBottom: 16 }}>
71-
<SearchBar
72-
onChange={handleSearchBarChange}
73-
placeholder={intl.formatMessage(
74-
translations.searchBarPlaceholder,
75-
)}
76-
/>
77-
</div>
70+
<SearchField
71+
onChangeKeyword={handleSearchBarChange}
72+
placeholder={intl.formatMessage(translations.searchBarPlaceholder)}
73+
/>
7874
</Grid>
7975
<Grid item xs={1}>
8076
<Pagination

client/app/bundles/course/reference-timelines/views/DayView/DayView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { ComponentRef, useMemo, useRef, useState } from 'react';
22
import { Chip, Typography } from '@mui/material';
33
import { TimelineData } from 'types/course/referenceTimelines';
44

5+
import SearchField from 'lib/components/core/fields/SearchField';
56
import { useAppSelector } from 'lib/hooks/store';
67
import useTranslation from 'lib/hooks/useTranslation';
78

89
import DayCalendar from '../../components/DayCalendar';
9-
import SearchField from '../../components/SearchField';
1010
import SubmitIndicator from '../../components/SubmitIndicator';
1111
import TimelinesOverview from '../../components/TimelinesOverview';
1212
import TimelinesStack from '../../components/TimelinesStack';

client/app/lib/components/core/fields/SearchBar.tsx

-48
This file was deleted.

client/app/bundles/course/reference-timelines/components/SearchField.tsx renamed to client/app/lib/components/core/fields/SearchField.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import LoadingIndicator from 'lib/components/core/LoadingIndicator';
88
interface SearchFieldProps {
99
onChangeKeyword?: (keyword: string) => void;
1010
placeholder?: string;
11+
className?: string;
1112
}
1213

1314
const SearchField = (props: SearchFieldProps): JSX.Element => {
@@ -26,6 +27,7 @@ const SearchField = (props: SearchFieldProps): JSX.Element => {
2627

2728
return (
2829
<TextField
30+
className={props.className}
2931
fullWidth
3032
hiddenLabel
3133
InputProps={{

0 commit comments

Comments
 (0)