Skip to content
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

Add search with autocomplete #27

Closed
wants to merge 7 commits into from
Closed

Conversation

AtkishkinVlad
Copy link
Contributor

@AtkishkinVlad AtkishkinVlad commented Oct 15, 2022

  • Add mock-server json-server
  • Add SearchInput

package.json Outdated
},
"devDependencies": {
"@next/eslint-plugin-next": "^12.1.6",
"eslint": "^8.2.0",
"json-server": "0.17.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the formatting in this file

@sashachabin
Copy link
Member

sashachabin commented Oct 16, 2022

  • Please write the Issues and PR's in English. At first it will seem unusual, but English is the language of professional community.
  • Please add to PR description the Issue id #25 referenced by this task — Add search with autocomplete #25

package.json Outdated
Comment on lines 25 to 35
"bootstrap": "5.1.3",
"classnames": "2.3.1",
"lodash": "4.17.21",
"next": "12.1",
"normalize.css": "8.0.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-responsive": "^9.0.0-beta.10",
"sass": "^1.52.3",
"react-responsive": "9.0.0-beta.10",
"react-select": "^5.5.0",
"sass": "1.52.3",
"superagent": "7.1.1",
"typograf": "^6.14.1"
"typograf": "6.14.1"
Copy link
Member

@sashachabin sashachabin Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ^ symbols has been removed from this PR?

@sashachabin
Copy link
Member

sashachabin commented Oct 16, 2022

Please fix build step in deploy. Have you checked the linter?

@@ -0,0 +1,27 @@
import React from "react";
import Select from "react-select/base";
Copy link
Member

@sashachabin sashachabin Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that react-select is redundant for this task. It's main feature is multiselect.

Copy link
Member

@sashachabin sashachabin Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in our component is very different from react-search

For example, we have item groups with headings

@sashachabin sashachabin changed the title Поиск по руководствам Add a mock server to manuals search Oct 16, 2022
@sashachabin sashachabin changed the title Add a mock server to manuals search Add a mock server for manuals search Oct 16, 2022
export const SuggestionItem = ({ suggestion }) => (
<div>
<h4>
{suggestion.guide_name} / {suggestion.guide_section}
Copy link
Contributor Author

@AtkishkinVlad AtkishkinVlad Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding the guide_name of the manual to the search

Cause: sections can be duplicated in different manuals

@AtkishkinVlad AtkishkinVlad changed the title Add a mock server for manuals search SearchInput Oct 22, 2022
@AtkishkinVlad AtkishkinVlad changed the title SearchInput Add search with autocomplete Oct 22, 2022
export const SearchInput = ({ isVisible }) => {
const [suggestions, setSuggestions] = React.useState([]);
const styleInputBlock = classNames(style.searchInput__container, {
[style.hidden]: !isVisible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the hidden={!isVisible} attribute. It will be great for accessibility

Comment on lines 2 to 3
"1": {
"items": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE
It will have to return only an array. Key for simulating a user request

@sashachabin
Copy link
Member

We have to ask the backend to limit the number of search results returned.
No more than 20 results.

If backend return 20 results — write Показаны первые 20 результатов поиска at the bottom of the control.

@sashachabin
Copy link
Member

sashachabin commented Oct 22, 2022

TODO back-end

We won't do it yet

  • Create cover image
  • Generate with thumbnail 64x64
  • Return cover image as cover_preview field

import React from "react";
import { SuggestionItem } from "../SuggestionItem/SuggestionItem";

export const SearchSuggestionBlock = ({ suggestions }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchSuggestionBlock -> SearchSuggestion

import React from "react";
import Link from "next/link";

export const SuggestionItem = ({ suggestion }) => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SuggestionItem -> SearchSuggestionItem

@@ -20,6 +22,8 @@ function ManualPage({
catalogIndex,
children,
}) {
const [showSearchInput, setShowSearchInput] = React.useState(false);

const getLine = (columnList) => {
if (!columnList.children.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columnList.children.length > 0

@@ -8,32 +8,37 @@
"lint:fix": "eslint --fix --ext .js,.jsx .",
"prettier": "npx prettier --write .",
"prepare": "husky install",
"json-server": "json-server ./mock/search-data.mock.json --port 8088",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to dev: "next dev & npm run json-server"

left: calc(max(384px, 20%) + 15vw);
opacity: 0;
bottom: 0;
transition: all .4s ease-in-out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so slow)

animations more than 100-150ms seems very slow

Comment on lines +13 to +14
border: 6px solid #EEEFF1;
border-top: 6px solid #EEEFF1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

border-top duplicates border

import styles from './SearchSuggestion.module.css'

export function SearchSuggestion({ suggestions }) {
if (suggestions.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the components less smart.

Let the parent component check whether the child component should be render.

ref={(input) => input?.focus()}
className={style.input}
onChange={debounce(async (e) => {
const textInput = e.target.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this callback to separate function

@sashachabin
Copy link
Member

Done in #47

@sashachabin sashachabin deleted the search-with-suggest branch December 2, 2023 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants