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

feat(core): provide information about stalled search to widgets #2569

Merged
merged 23 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
51c7df7
feat(core): the core provides information about stalled search
Nov 9, 2017
a3a5947
feat(searchbox): implements a loading indicator
Nov 9, 2017
b95c3b0
chore(lint): fix prettier and eslint check
Nov 9, 2017
0e37c0c
Merge branch 'develop' into poc/central-loading-state
bobylito Nov 10, 2017
75d7cf2
Merge branch 'develop' into poc/central-loading-state
vvo Nov 16, 2017
59fdbaf
feat(core): add option to configure stalled search delay
Nov 16, 2017
1d0aa21
Merge branch 'poc/central-loading-state' of github.com:algolia/instan…
Nov 16, 2017
6821e09
feat(searchbox): add options to set a loading indicator
Nov 22, 2017
4ecf773
Merge branch 'develop' into poc/central-loading-state
Nov 22, 2017
a4d4b89
chore: update test to match the lib changes
Nov 24, 2017
ca4ed04
chore(search-box-test): remove sinon
Nov 24, 2017
852e4ab
chore(connectSearchBox): remove sinon from test
Nov 24, 2017
d5398f5
chore(doc): add isStalledSearch on connectSearchBox rendering options
Nov 24, 2017
7a450b1
chore(validation): merge commit length should not be checked
Nov 24, 2017
ea2d14f
test(core): test new render step with stalled search
Nov 25, 2017
16475ab
Merge branch 'develop' into poc/central-loading-state
vvo Nov 27, 2017
0cd59a5
Merge branch 'develop' into poc/central-loading-state
vvo Nov 27, 2017
e3a9940
chore(searchbox): test with input tag container
Nov 27, 2017
dc5ee62
chore(doc): fix inconsistencies and add details
Nov 27, 2017
5583d18
chore(searchbox): use `.ais-stalled-search` and fix use of input
Nov 27, 2017
7e9157e
chore(doc): fix content
Nov 27, 2017
36c5dcd
Merge branch 'feat/2.3' into poc/central-loading-state
bobylito Nov 27, 2017
737d28e
chore: merge with 2.3, update snapshot
Nov 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/connectors/search-box/connectSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default function connectSearchBox(renderFn) {
);
},

render({ helper, instantSearchInstance }) {
render({ helper, instantSearchInstance, searchMetadata }) {
this._clear = clear(helper);

renderFn(
Expand All @@ -137,6 +137,7 @@ export default function connectSearchBox(renderFn) {
clear: this._cachedClear,
widgetParams,
instantSearchInstance,
isSearchStalled: searchMetadata.isSearchStalled,
},
false
);
Expand Down
10 changes: 10 additions & 0 deletions src/css/theme/_search-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
white-space: nowrap;
font-size: 14px;


&--input {
appearance: none;
font: inherit;
Expand Down Expand Up @@ -42,4 +43,13 @@
width: 18px;
}
}

&.stalled-search .ais-search-box--magnifier {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="38" height="38"><defs><linearGradient id="a" x1="8.04%" x2="65.68%" y1="0%" y2="23.86%"><stop stop-color="%23BFC7D8" stop-opacity="0" offset="0%"/><stop stop-color="%23BFC7D8" stop-opacity=".63" offset="63.15%"/><stop stop-color="%23BFC7D8" offset="100%"/></linearGradient></defs><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><path stroke="url(%23a)" stroke-width="2" d="M36 18c0-9.94-8.06-18-18-18"><animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="0.9s" repeatCount="indefinite"/></path><circle cx="36" cy="18" r="1" fill="%23BFC7D8"><animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="0.9s" repeatCount="indefinite"/></circle></g></svg>');
background-size: cover;

svg {
visibility: hidden;
}
}
}
27 changes: 27 additions & 0 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,25 @@ Usage: instantsearch({
this.helper = helper;
this._init(helper.state, this.helper);
this.helper.on('result', this._render.bind(this, this.helper));

const delay = /* stalledSearchDelay || */ 200;
this._searchStalledTimer = null;
this._isSearchStalled = false;

this.helper.search();

this.helper.on('search', () => {
if (!this._searchStalledTimer) {
this._searchStalledTimer = setTimeout(() => {
this._isSearchStalled = true;
this._render(
this.helper,
this.helper.lastResults,
this.helper.lastResults._state
);
}, delay);
}
});
}

createURL(params) {
Expand All @@ -161,6 +179,12 @@ Usage: instantsearch({
}

_render(helper, results, state) {
if (!this.helper.hasPendingRequests()) {
clearTimeout(this._searchStalledTimer);
this._searchStalledTimer = null;
this._isSearchStalled = false;
}

forEach(this.widgets, widget => {
if (!widget.render) {
return;
Expand All @@ -172,6 +196,9 @@ Usage: instantsearch({
helper,
createURL: this._createAbsoluteURL,
instantSearchInstance: this,
searchMetadata: {
isSearchStalled: this._isSearchStalled,
},
});
});

Expand Down
27 changes: 21 additions & 6 deletions src/widgets/search-box/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const renderer = ({
wrapInput,
reset,
magnifier,
}) => ({ refine, clear, query, onHistoryChange }, isFirstRendering) => {
}) => (
{ refine, clear, query, onHistoryChange, isSearchStalled },
isFirstRendering
) => {
if (isFirstRendering) {
const INPUT_EVENT = window.addEventListener ? 'input' : 'propertychange';
const input = createInput(containerNode);
Expand Down Expand Up @@ -106,11 +109,7 @@ const renderer = ({
}
}
} else {
const input = getInput(containerNode);
const isFocused = document.activeElement === input;
if (!isFocused && query !== input.value) {
input.value = query;
}
renderAfterInit({ containerNode, query, magnifier, isSearchStalled });
}

if (reset) {
Expand All @@ -127,6 +126,22 @@ const renderer = ({
}
};

function renderAfterInit({ containerNode, query, magnifier, isSearchStalled }) {
const input = getInput(containerNode);
const isFocused = document.activeElement === input;
if (!isFocused && query !== input.value) {
input.value = query;
}

if (magnifier) {
if (isSearchStalled) {
containerNode.firstChild.classList.add('stalled-search');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this CSS class name follow ais- conventions? And be documented somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes sure. Also it doesn't work if you use an input as container :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe document that part, but I won't be surprised as a dev for it not to be supported.

} else {
containerNode.firstChild.classList.remove('stalled-search');
}
}
}

const usage = `Usage:
searchBox({
container,
Expand Down