Skip to content

Commit

Permalink
Fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Jan 10, 2024
1 parent b5a4f61 commit c3e3132
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IReadonlyTheme } from '@microsoft/sp-component-base';

export interface IPeopleSearchBoxProps {
onSearch: (searchQuery: string) => Promise<void>;
onSearch: (searchQuery: string, isReset: boolean) => Promise<void>;
themeVariant: IReadonlyTheme | undefined;
searchInputValue: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class PeopleSearchBox extends React.Component<IPeopleSearchBoxProps,IPeop
}

// Notify the dynamic data controller
await this.props.onSearch(query);
await this.props.onSearch(query, isReset);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface IPeopleSearchContainerState {
hasError: boolean;
page: number;
searchParameter: string;
isReset: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class PeopleSearchContainer extends React.Component<IPeopleSearchContaine
errorMessage: '',
hasError: false,
page: 1,
searchParameter: ''
searchParameter: '',
isReset: false
};
}

Expand All @@ -58,7 +59,17 @@ export class PeopleSearchContainer extends React.Component<IPeopleSearchContaine
*/
public async componentDidUpdate(prevProps: IPeopleSearchContainerProps, prevState: IPeopleSearchContainerState): Promise<void> {
if (!isEqual(this.props.searchService, prevProps.searchService)) {
await this._fetchPeopleSearchResults(1, true);
if (this.state.isReset && this.props.hideResultsOnload) {
this.setState({
isReset: false,
results: [{
value: []
}]
});
}
else {
await this._fetchPeopleSearchResults(1, true);
}
}
else if (!isEqual(this.props, prevProps)) {
if (this.state.hasError) {
Expand Down Expand Up @@ -147,7 +158,11 @@ export class PeopleSearchContainer extends React.Component<IPeopleSearchContaine
const renderSearchResultTemplate = this.props.templateService.getTemplateComponent(this.props.selectedLayout, templateContext);

if (this.props.searchParameterOption === SearchParameterOption.SearchBox) {
renderSearchBox = <PeopleSearchBox themeVariant={this.props.themeVariant} onSearch={async (searchQuery) => { await this.props.updateSearchParameter(searchQuery); }} searchInputValue={this.props.searchService.searchParameter} />;
renderSearchBox = <PeopleSearchBox themeVariant={this.props.themeVariant} onSearch={async (searchQuery, isReset) => {
this.setState({
isReset: isReset
});
await this.props.updateSearchParameter(searchQuery); }} searchInputValue={this.props.searchService.searchParameter} />;
}

if (this.props.showPagination) {
Expand Down

0 comments on commit c3e3132

Please sign in to comment.