@@ -3,20 +3,32 @@ import { observer } from 'mobx-react-lite';
33import CloseIcon from "@material-ui/icons/Close" ;
44import SessionStore from '../store/SessionStore' ;
55import { snapshotStore } from '../store/SnapshotStore' ;
6- import React from 'react' ;
6+ import React , { useEffect } from 'react' ;
77import DeleteDialog from './DeleteDialog' ;
8+ import { apFileSystem } from '../store/APFileSystem' ;
89
910type Props = {
1011 open : boolean ,
1112 onClose : ( ) => void ,
1213 store : SessionStore ,
1314} ;
1415const SessionModal = observer ( ( { open, onClose, store } : Props ) => {
15- const [ filterValue , setFilterValue ] = React . useState ( '' ) ;
16+ const [ filterValues , setFilterValues ] = React . useState < string [ ] > ( [ ] ) ;
17+ const [ titleValue , setTitleValue ] = React . useState ( '' ) ;
18+ const [ searchValue , setSearchValue ] = React . useState ( '' ) ;
1619 const [ openDeleteDialog , setOpenDeleteDialog ] = React . useState ( false ) ;
1720 const [ pendingDeleteIndex , setPendingDeleteIndex ] = React . useState ( - 1 ) ;
21+ const [ searchType , setSearchType ] = React . useState < string > ( 'Title' ) ;
22+
23+ useEffect ( ( ) => {
24+ setTitleValue ( '' ) ;
25+ setSearchValue ( '' ) ;
26+ setSearchType ( 'Title' ) ;
27+ filterValues . splice ( 0 , filterValues . length ) ;
28+ } , [ open ] ) ;
1829
1930 function close ( ) {
31+ snapshotStore . setUpdating ( false ) ;
2032 onClose ( ) ;
2133 }
2234
@@ -32,6 +44,16 @@ const SessionModal = observer(({ open, onClose, store }: Props) => {
3244 snapshotStore . setUpdating ( false ) ;
3345 }
3446
47+ function isFilterValueMatch ( sessionName : string ) {
48+ if ( filterValues . length === 0 ) return true ;
49+ for ( const value of filterValues ) {
50+ if ( sessionName . indexOf ( value ) !== - 1 ) {
51+ return true ;
52+ }
53+ }
54+ return false ;
55+ }
56+
3557 return (
3658 < >
3759 < Modal
@@ -46,18 +68,76 @@ const SessionModal = observer(({ open, onClose, store }: Props) => {
4668 < h3 > Sessions</ h3 >
4769 < div style = { { borderTop : 'solid steelblue' , paddingTop : '.5rem' } } >
4870 < div className = "no-capture-modal__scroll-container" >
49- < input type = "search" className = "form-control" style = { { marginTop : '1rem' } }
50- placeholder = "Filter..."
51- onChange = { ( e ) => setFilterValue ( e . target . value ) }
52- value = { filterValue } />
71+ < div style = { { display : 'flex' , marginTop : '1rem' } } >
72+
73+ < select className = "form-control btn btn-primary"
74+ disabled = { snapshotStore . isUpdating ( ) }
75+ style = { { width : '7rem' } }
76+ onChange = { e => {
77+ setSearchType ( e . target . value ) ;
78+ if ( e . target . value === 'Title' ) {
79+ setFilterValues ( [ titleValue ] ) ;
80+ }
81+ } }
82+ value = { searchType }
83+ >
84+ < option selected = { searchType === 'Title' } > Title</ option >
85+ < option selected = { searchType === 'Full Text' } > Full Text</ option >
86+ </ select >
87+
88+ { searchType === 'Title' ?
89+ < input type = "search" className = "form-control"
90+ onChange = { ( e ) => {
91+ setTitleValue ( e . target . value ) ;
92+ setFilterValues ( [ e . target . value ] ) ;
93+ } }
94+ value = { titleValue } />
95+ :
96+ < input type = "search" className = "form-control"
97+ placeholder = "Hit enter to search"
98+ disabled = { snapshotStore . isUpdating ( ) }
99+ onChange = { ( e ) => setSearchValue ( e . target . value ) }
100+ onKeyUp = { async ( e ) => {
101+ if ( e . keyCode === 13 ) {
102+ if ( searchValue === '' ) {
103+ setFilterValues ( [ ] ) ;
104+ } else {
105+ snapshotStore . setUpdating ( true ) ;
106+ //console.log('enter');
107+ apFileSystem . grepDir ( 'sessions' , searchValue )
108+ . then ( ( files ) => {
109+ //console.log(files);
110+ if ( Array . isArray ( files ) ) {
111+ const values : string [ ] = [ ] ;
112+ for ( const file of files ) {
113+ const value = file . split ( '/' ) [ 1 ] ;
114+ values . push ( value ) ;
115+ }
116+ setFilterValues ( values ) ;
117+ } else {
118+ console . error ( files ) ;
119+ }
120+ snapshotStore . setUpdating ( false ) ;
121+ } )
122+ . catch ( ( e ) => {
123+ snapshotStore . setUpdating ( false ) ;
124+ console . error ( e ) ;
125+ } ) ;
126+ }
127+ }
128+ } }
129+ value = { searchValue } />
130+ }
131+
132+ </ div >
53133 < List >
54134 { store . getSessionList ( ) . length === 0 &&
55135 < div className = "center"
56136 style = { { marginTop : 'calc( 50vh - 72px' } } >
57137 No saved sessions found
58138 </ div > }
59139 { store . getSessionList ( ) . map ( ( sessionName , i ) => (
60- sessionName . indexOf ( filterValue ) !== - 1 &&
140+ ( isFilterValueMatch ( sessionName ) ) &&
61141 < ListItem key = { i }
62142 style = { {
63143 display : 'flex' , alignItems : 'center' ,
0 commit comments