-
Notifications
You must be signed in to change notification settings - Fork 1.3k
add solution #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yevhen-Srdk
wants to merge
4
commits into
mate-academy:master
Choose a base branch
from
Yevhen-Srdk:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add solution #1156
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
10f05cb
add solution
Yevhen-Srdk 0d89c20
renamed data-cy attribute to data-qa and renamed onFocus func to hand…
Yevhen-Srdk 49a15c6
renamed data-cy attribute to data-qa in App.tsx
Yevhen-Srdk 4aa5fb1
renamed AGAIN data-qa attributes to data-cy in App.tsx & Autocomplete…
Yevhen-Srdk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
| import React, { useEffect, useRef, useState } from 'react'; | ||
| import { Person } from '../types/Person'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| type Props = { | ||
| people: Person[]; | ||
| delay?: number; | ||
| onSelected: (person: Person | null) => void; | ||
| }; | ||
|
|
||
| export const Autocomplete: React.FC<Props> = ({ | ||
| people, | ||
| delay = 300, | ||
| onSelected, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The project instructions say: "Don't remove the title currently uses
|
||
| }) => { | ||
| const [query, setQuery] = useState(''); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [suggestions, setSuggestions] = useState<Person[]>(people); | ||
| const prevQuery = useRef(''); | ||
|
|
||
| useEffect(() => { | ||
| const timeout = setTimeout(() => { | ||
| if (prevQuery.current === query) { | ||
| return; | ||
| } | ||
|
|
||
| prevQuery.current = query; | ||
|
|
||
| if (!query.trim()) { | ||
| setSuggestions(people); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const filtered = people.filter(person => | ||
| person.name.toLowerCase().includes(query.toLowerCase()), | ||
| ); | ||
|
|
||
| setSuggestions(filtered); | ||
| }, delay); | ||
|
|
||
| return () => clearTimeout(timeout); | ||
| }, [query, delay, people]); | ||
|
|
||
| const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| const value = event.target.value; | ||
|
|
||
| setQuery(value); | ||
| onSelected(null); | ||
| }; | ||
|
|
||
| const handleFocus = () => { | ||
| setIsOpen(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={classNames('dropdown', { 'is-active': isOpen })}> | ||
| <div className="dropdown-trigger"> | ||
| <input | ||
| type="text" | ||
| placeholder="Enter a part of the name" | ||
| className="input" | ||
| data-qa="search-input" | ||
| value={query} | ||
| onChange={handleQueryChange} | ||
| onFocus={handleFocus} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="dropdown-menu" role="menu" data-qa="suggestions-list"> | ||
| <div className="dropdown-content"> | ||
| {suggestions.map((human: Person) => ( | ||
| <div | ||
| key={human.name + human.born} | ||
| className="dropdown-item" | ||
| data-qa="suggestion-item" | ||
| onMouseDown={() => { | ||
| setQuery(human.name); | ||
| setIsOpen(false); | ||
| onSelected(human); | ||
| }} | ||
| > | ||
| <p className="has-text-link">{human.name}</p> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| {query.trim() && suggestions.length === 0 && ( | ||
| <div | ||
| className=" | ||
| notification | ||
| is-danger | ||
| is-light | ||
| mt-3 | ||
| is-align-self-flex-start | ||
| " | ||
| role="alert" | ||
| data-qa="no-suggestions-message" | ||
| > | ||
| <p className="has-text-danger">No matching suggestions</p> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app's title uses
data-cy="title". Tests and the task description requiredata-qaattributes. Please replace the attribute withdata-qa="title". (Requirement: "Don't remove thedata-qaattributes. It is required for tests.")