@@ -7,17 +7,24 @@ import parse from 'html-react-parser';
7
7
import timeGridPlugin from '@fullcalendar/timegrid' ;
8
8
import rrulePlugin from '@fullcalendar/rrule' ;
9
9
10
+ import SearchHeader from './components/SearchHeader' ;
11
+ import './App.css' ;
12
+
10
13
import useEscKey from './hooks/useEscKey' ;
11
14
12
15
import Icon from '@mdi/react' ;
13
16
import { mdiCalendarRange , mdiMapMarkerOutline , mdiClose } from '@mdi/js' ;
14
- import './App.css' ;
17
+
18
+ import eventData from './events.json'
15
19
16
20
const htmlRegex = / < \/ * h t m l - b l o b > / ;
17
21
18
22
function App ( ) {
19
23
const calendarRef = createRef ( ) ;
20
24
25
+ const eventsArray = Array . from ( eventData )
26
+ const [ events , setEvents ] = useState ( eventsArray )
27
+
21
28
const [ loading , setLoading ] = useState ( true ) ;
22
29
const [ showEventDetails , setShowEventDetails ] = useState ( false ) ;
23
30
const [ eventDetails , setEventDetails ] = useState ( false ) ;
@@ -51,6 +58,16 @@ function App() {
51
58
setPopupPosition ( { left : position . left + 'px' , top : position . top + 'px' } )
52
59
}
53
60
61
+ const filterEvents = ( searchTerm ) => {
62
+ if ( ! searchTerm ) return setEvents ( eventsArray ) //handles searchbox clear
63
+ let matchingEvents = eventsArray . filter ( ( event ) => {
64
+ const titleIncludes = event . title ?. toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) )
65
+ const descriptionIncludes = event . description ?. toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) )
66
+ return titleIncludes || descriptionIncludes
67
+ } )
68
+ setEvents ( matchingEvents )
69
+ }
70
+
54
71
const handleEventClick = useCallback ( ( clickInfo ) => {
55
72
window . outerWidth > 600 && createPopupPosition ( clickInfo . jsEvent )
56
73
setEventDetails ( clickInfo . event ) ;
@@ -174,7 +191,7 @@ function App() {
174
191
aspectRatio = { aspectRatio }
175
192
handleWindowResize = { true }
176
193
windowResize = { windowResize }
177
- events = " events.json"
194
+ events = { events }
178
195
headerToolbar = { {
179
196
left : 'prev,next today' ,
180
197
center : 'title' ,
@@ -188,10 +205,11 @@ function App() {
188
205
eventClick = { handleEventClick }
189
206
loading = { ( isLoading ) => setLoading ( isLoading ) }
190
207
/>
191
- ) , [ aspectRatio , initialView ] ) ;
208
+ ) , [ aspectRatio , initialView , events ] ) ;
192
209
193
210
return (
194
211
< div className = "App main" >
212
+ < SearchHeader filterEvents = { filterEvents } />
195
213
< div className = "finos-calendar" > { renderFullCalendar } </ div >
196
214
{ showEventDetails && renderEventDetails ( ) }
197
215
{ loading && < div className = "finos-calendar-overlay" /> }
0 commit comments