Skip to content

Commit

Permalink
feat(search-bar): redirect to image view on enter when search maches …
Browse files Browse the repository at this point in the history
…a repo:tag

Signed-off-by: Laurentiu Niculae <[email protected]>
  • Loading branch information
laurentiuNiculae committed Feb 29, 2024
1 parent e2367c2 commit 8a18a6d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Header/SearchSuggestion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,19 @@ function SearchSuggestion({ setSearchCurrentValue = () => {} }) {

const handleSearch = (event) => {
const { key, type } = event;
const name = event.target.value;
if (key === 'Enter' || type === 'click') {
navigate({ pathname: `/explore`, search: createSearchParams({ search: inputValue || '' }).toString() });
const splitName = name.split(':');
let inputInSuggestions = false;

Check warning on line 138 in src/components/Header/SearchSuggestion.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Header/SearchSuggestion.jsx#L137-L138

Added lines #L137 - L138 were not covered by tests

if (splitName.length > 1) {
inputInSuggestions = suggestionData.some((sd) => sd.repoName === splitName[0] && sd.tag === splitName[1]);
}
if (inputInSuggestions) {
navigate(`/image/${encodeURIComponent(splitName[0])}/tag/${splitName[1]}`);
} else {

Check warning on line 145 in src/components/Header/SearchSuggestion.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Header/SearchSuggestion.jsx#L144-L145

Added lines #L144 - L145 were not covered by tests
navigate({ pathname: `/explore`, search: createSearchParams({ search: inputValue || '' }).toString() });
}
}
};

Expand Down

0 comments on commit 8a18a6d

Please sign in to comment.