-
Notifications
You must be signed in to change notification settings - Fork 0
Day 2 search #9
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
base: day-2
Are you sure you want to change the base?
Day 2 search #9
Conversation
palkan
left a comment
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.
👍
| @@ -0,0 +1,5 @@ | |||
| <%# locals: (album:, album_counter: nil, album_iteration: nil) -%> | |||
| <li class="nav--search--result"> | |||
| <%= link_to album.title, album_path(album), class: "hover:text-secondary", data: { action: "click->search#clear" } %> | |||
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.
Я правильно понимаю, что мы добавляем вызов clear, а дальше событие обрабатывается браузером (ну в нашем случае Turbo) и работает как обычно?
Идея интересная; как пример использования Stimulus вообще отлично. Единственный отрицательный (для меня) момент — логика работы компонента сильно размазана, теперь любые ссылки внутри него должны знать про это. С другой стороны, мы пока предполагаем, что для превью свои шаблоны.
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.
Да, понял правильно.
Что касается размазанной логики - мне тоже текущая реализация не совсем нравится, как одно из улучшений на первый взгляд - можно навесить экшн на клик по основному элементу и в нем проверять была ли нажата ссылка или нет, тогда логика будет собрана в одном месте
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.
Есть ещё вариант слушать событие turbo:click 😉
| q = params[:q] | ||
|
|
||
| if q.blank? || q.length < 3 | ||
| if (q.blank? || q.length < 3) && !(params.include? :preview) |
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.
Кажется, мы могли бы тут проверять на то, идёт запрос из фрейма или нет. Использование параметров для такого различия — не лучший вариант (ну вдруг кто-то решить по этому адресу открыть страницу?).
И ограничение на минимальную длину имеет смысл и для превью. Это можно добавить в Stimulus (и даже параметризовать через Values).
Задача:
Реализовать функционал «живого» поиска (search autocomplete), используя технологии Turbo Frames и Stimulus.