forked from Boehringer-Ingelheim/goat-health-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): add option for search view
- select between `card` or `list` as current search view
- Loading branch information
1 parent
2082bc3
commit ed6daf2
Showing
4 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
IonPopover, | ||
IonButton, | ||
IonIcon, | ||
IonLabel, | ||
IonItem, | ||
IonList, | ||
IonListHeader, | ||
IonRadio, | ||
IonRadioGroup, | ||
} from '@ionic/react'; | ||
import { ellipsisHorizontal, ellipsisVertical } from 'ionicons/icons'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { setCurrentSearchView } from '../../data/user/user.slice'; | ||
import { RootState } from '../../store'; | ||
import { selectCurrentSearchView } from '../../data/user/user.selector'; | ||
|
||
export const SearchPopover: React.FC = () => { | ||
const [popoverState, setShowPopover] = useState({ | ||
showPopover: false, | ||
event: undefined, | ||
}); | ||
|
||
const dispatch = useDispatch(); | ||
const currentSearchView = useSelector((state: RootState) => | ||
selectCurrentSearchView(state), | ||
); | ||
|
||
return ( | ||
<> | ||
<IonPopover | ||
cssClass="my-custom-class" | ||
event={popoverState.event} | ||
isOpen={popoverState.showPopover} | ||
onDidDismiss={() => | ||
setShowPopover({ showPopover: false, event: undefined }) | ||
} | ||
> | ||
<IonList className={'active'}> | ||
<IonRadioGroup | ||
value={currentSearchView} | ||
onIonChange={(e) => | ||
dispatch( | ||
setCurrentSearchView({ currentSearchView: e.detail.value }), | ||
) | ||
} | ||
> | ||
<IonListHeader> | ||
<IonLabel>View</IonLabel> | ||
</IonListHeader> | ||
<IonItem> | ||
<IonLabel>Card</IonLabel> | ||
<IonRadio slot="start" value="card" /> | ||
</IonItem> | ||
<IonItem lines="none"> | ||
<IonLabel>List</IonLabel> | ||
<IonRadio slot="start" value="list" /> | ||
</IonItem> | ||
</IonRadioGroup> | ||
</IonList> | ||
</IonPopover> | ||
<IonButton | ||
onClick={(event: any) => { | ||
event.persist(); | ||
setShowPopover({ showPopover: true, event }); | ||
}} | ||
> | ||
<IonIcon | ||
slot="icon-only" | ||
ios={ellipsisHorizontal} | ||
md={ellipsisVertical} | ||
/> | ||
</IonButton> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { IonNote, IonRouterLink } from '@ionic/react'; | ||
import React from 'react'; | ||
import { Chapter, getChapterIdsByUrl } from '../Chapters'; | ||
import { LunrResult } from '../../utils/lunr'; | ||
|
||
interface ContainerProps { | ||
results: LunrResult[]; | ||
} | ||
|
||
export const SearchResults: React.FC<ContainerProps> = (props) => { | ||
const { results } = props; | ||
|
||
if (results.length === 0) { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100%', | ||
}} | ||
> | ||
<IonNote>No results found</IonNote> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<IonNote>Found {results.length} results</IonNote> | ||
<div | ||
style={{ | ||
alignItems: 'center', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
{results.map((result, resultIndex) => { | ||
const { id: chapterUrl } = result; | ||
const { id, subId } = getChapterIdsByUrl(chapterUrl); | ||
return ( | ||
<IonRouterLink | ||
key={resultIndex} | ||
routerLink={chapterUrl} | ||
routerDirection="forward" | ||
> | ||
<Chapter id={id} isCard subId={subId} /> | ||
</IonRouterLink> | ||
); | ||
})} | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters