From 4ca590639ddb1a4044a646fd3c4ee77c239aaa9a Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 3 Jan 2021 21:58:55 +0100 Subject: [PATCH] add a filter option to the addactor popup page --- src/elements/GPElements/Button.tsx | 2 +- .../AddActorPopup/AddActorPopup.module.css | 10 +++- .../Popups/AddActorPopup/AddActorPopup.tsx | 56 +++++++++++++++++-- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/elements/GPElements/Button.tsx b/src/elements/GPElements/Button.tsx index 45afb72..99b43ce 100644 --- a/src/elements/GPElements/Button.tsx +++ b/src/elements/GPElements/Button.tsx @@ -2,7 +2,7 @@ import React from 'react'; import style from './Button.module.css'; interface ButtonProps { - title: string; + title: string | JSX.Element; onClick?: () => void; color?: React.CSSProperties; } diff --git a/src/elements/Popups/AddActorPopup/AddActorPopup.module.css b/src/elements/Popups/AddActorPopup/AddActorPopup.module.css index 84b624f..190a53e 100644 --- a/src/elements/Popups/AddActorPopup/AddActorPopup.module.css +++ b/src/elements/Popups/AddActorPopup/AddActorPopup.module.css @@ -7,5 +7,13 @@ margin-top: 12px; padding: 6px; width: 140px; - width: 140px; +} + +.searchinput{ + width: 120px; + float: left; +} + +.searchbar { + margin-bottom: 13px; } diff --git a/src/elements/Popups/AddActorPopup/AddActorPopup.tsx b/src/elements/Popups/AddActorPopup/AddActorPopup.tsx index 4722adc..0893cb9 100644 --- a/src/elements/Popups/AddActorPopup/AddActorPopup.tsx +++ b/src/elements/Popups/AddActorPopup/AddActorPopup.tsx @@ -6,6 +6,9 @@ import {NewActorPopupContent} from '../NewActorPopup/NewActorPopup'; import {callAPI} from '../../../utils/Api'; import {ActorType} from '../../../api/VideoTypes'; import {GeneralSuccess} from '../../../api/GeneralTypes'; +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; +import {faFilter, faTimes} from '@fortawesome/free-solid-svg-icons'; +import {Button} from '../../GPElements/Button'; interface props { onHide: () => void; @@ -15,6 +18,8 @@ interface props { interface state { contentDefault: boolean; actors: ActorType[]; + filter: string; + filtervisible: boolean; } /** @@ -26,10 +31,13 @@ class AddActorPopup extends React.Component { this.state = { contentDefault: true, - actors: [] + actors: [], + filter: '', + filtervisible: false }; this.tileClickHandler = this.tileClickHandler.bind(this); + this.filterSearch = this.filterSearch.bind(this); } render(): JSX.Element { @@ -71,14 +79,48 @@ class AddActorPopup extends React.Component { */ getContent(): JSX.Element { if (this.state.actors.length !== 0) { - return (
- {this.state.actors.map((el) => ())} -
); + return ( + <> +
+ { + this.state.filtervisible ? + <> + { + this.setState({filter: e.target.value}); + }}/> +
+ {this.state.actors.filter(this.filterSearch).map((el) => ())} + + ); } else { return (
somekind of loading
); } } + /** + * filter the actor array for search matches + * @param actor + */ + private filterSearch(actor: ActorType): boolean { + return actor.name.toLowerCase().includes(this.state.filter.toLowerCase()); + } + /** * event handling for ActorTile Click */ @@ -93,12 +135,14 @@ class AddActorPopup extends React.Component { // return back to player page this.props.onHide(); } else { - console.error('an error occured while fetching actors'); - console.error(result); + console.error('an error occured while fetching actors: ' + result); } }); } + /** + * load the actors from backend and set state + */ loadActors(): void { callAPI('actor.php', {action: 'getAllActors'}, result => { this.setState({actors: result});