Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat: provide a loading indicator #354

Merged
merged 12 commits into from
Jan 29, 2018
Merged

feat: provide a loading indicator #354

merged 12 commits into from
Jan 29, 2018

Conversation

bobylito
Copy link
Contributor

@bobylito bobylito commented Nov 3, 2017

This PR provides a way for the searchbox to display a spinner when the search is stalled.

The approach taken here is similar to the one from react-instantsearch: the mechanism that detects the stalled search is actually implemented at the top level. As in RIS this makes the implementation of this state update easier in multiple widgets, which seems like a good strategy.

On the UI implementation, because vue-IS doesn't implement any style, the magnifying glass svg is toggle with a spinner in the template. The effect is good as far as I can tell.

Missing elements:

  • actual API to customize the parameters
  • tests

Question:

  • not sure about the implementation in store.js/waitUntilSync @rayrutjes

Related to algolia/instantsearch#2509

@bobylito bobylito self-assigned this Nov 3, 2017
@bobylito bobylito requested a review from rayrutjes November 3, 2017 13:25
@bobylito bobylito changed the title feat(searchbox): provide a loading indicator feat: provide a loading indicator Nov 3, 2017
Haroenv
Haroenv previously requested changes Nov 3, 2017
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

yarn lint:fix

@@ -3,13 +3,29 @@
<slot>
<ais-input :search-store="searchStore" :placeholder="placeholder" :autofocus="autofocus"></ais-input>
<button type="submit" :class="bem('submit')">
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 40 40">
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 40 40" v-if="!searchStore.isSearchStalled">
Copy link
Contributor

Choose a reason for hiding this comment

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

Works really nice 😄

Maybe have this as an option though

<title>{{ submitTitle }}</title>
<path
d="M26.804 29.01c-2.832 2.34-6.465 3.746-10.426 3.746C7.333 32.756 0 25.424 0 16.378 0 7.333 7.333 0 16.378 0c9.046 0 16.378 7.333 16.378 16.378 0 3.96-1.406 7.594-3.746 10.426l10.534 10.534c.607.607.61 1.59-.004 2.202-.61.61-1.597.61-2.202.004L26.804 29.01zm-10.426.627c7.323 0 13.26-5.936 13.26-13.26 0-7.32-5.937-13.257-13.26-13.257C9.056 3.12 3.12 9.056 3.12 16.378c0 7.323 5.936 13.26 13.258 13.26z"
fillRule="evenodd"
/>
</svg>
<svg width="1em" height="1em" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#000" v-if="searchStore.isSearchStalled">
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a slot I think

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

no more blockers now I think

<title>{{ submitTitle }}</title>
<path
d="M26.804 29.01c-2.832 2.34-6.465 3.746-10.426 3.746C7.333 32.756 0 25.424 0 16.378 0 7.333 7.333 0 16.378 0c9.046 0 16.378 7.333 16.378 16.378 0 3.96-1.406 7.594-3.746 10.426l10.534 10.534c.607.607.61 1.59-.004 2.202-.61.61-1.597.61-2.202.004L26.804 29.01zm-10.426.627c7.323 0 13.26-5.936 13.26-13.26 0-7.32-5.937-13.257-13.26-13.257C9.056 3.12 3.12 9.056 3.12 16.378c0 7.323 5.936 13.26 13.258 13.26z"
fillRule="evenodd"
/>
</svg>
<svg width="1em" height="1em" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#000" v-if="showLoadingIndicator && searchStore.isSearchStalled">
Copy link
Contributor

Choose a reason for hiding this comment

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

Would still be nice to have this as a slot :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Will make this happen :)

};

const onHelperSearch = function() {
if (!this._stalledSearchTimer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if this is a big deal, but maybe it could not be done only if the stalled search feature is enabled? Might be hard to find out about it here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The feature is always there, for simplicity sake.

@bobylito
Copy link
Contributor Author

bobylito commented Dec 8, 2017

I've updated this PR to be consistent with the other InstantSearch implementations.

Copy link
Member

@rayrutjes rayrutjes left a comment

Choose a reason for hiding this comment

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

Super nice @bobylito .
I made a few comments.

For me the only real thing I would change is remove the new options parameter introduced on all factory methods.

The reasoning being that the state should only originate from a single source of truth.

I hope that makes sense.

@@ -24,8 +44,7 @@
</form>
</template>

<script>
import algoliaComponent from '../component';
<script>import algoliaComponent from '../component';
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the weird syntax is coming back here @Haroenv . Expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

not expected, maybe @bobylito's vim setup, should be put on the new line IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll double check. Maybe I didn't update the packages that do the formating 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it's not an error from any linter / formatter. I might have just removed it by mistake :/

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure it's because of the linter or something.
Happens to me all the time but can't remember what the real issue was.

@@ -72,7 +76,8 @@ export default {
if (!this.searchStore) {
this._localSearchStore = createFromAlgoliaCredentials(
this.appId,
this.apiKey
this.apiKey,
{ stalledSearchDelay: this.stalledSearchDelay }
Copy link
Member

Choose a reason for hiding this comment

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

Can we consider not adding another "options" parameter, and introduce a getter instead?
So far, the Store is just proxying as much as possible.
Also, if tomorrow the stalledSearchDelay is added to the helper, we won't require the option anymore and it would be an issue to be able to have it in the helper + as an option, because we won't know which one to keep.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean. However my thinking behind choosing this as an option is that this is a feature in the scope of InstantSearch, not the helper. This might evolve but the way it is implemented right now is the way it is in the other libraries.

@@ -2,7 +2,27 @@
<form role="search" action="" @submit.prevent="onFormSubmit">
<slot>
<ais-input :search-store="searchStore" :placeholder="placeholder" :autofocus="autofocus"></ais-input>
<button type="submit" :class="bem('submit')">
<div v-if="showLoadingIndicator" :style="searchStore.isSearchStalled ? 'display:block;' : 'display:none;'" :class="bem('loading-indicator')" >
Copy link
Member

Choose a reason for hiding this comment

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

I would probably go for v-show="showLoadingIndicator && searchStore.isSearchStalled" and remove the style attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed for that it would make more sense given the vue-specifics. However I chose that in order to have consistency accross all implementations. This is the exact same markup and changes on it depending on the value of isSearchStalled in all implementations.

Copy link
Member

@rayrutjes rayrutjes left a comment

Choose a reason for hiding this comment

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

All good 🎸

@@ -2,7 +2,27 @@
<form role="search" action="" @submit.prevent="onFormSubmit">
<slot>
<ais-input :search-store="searchStore" :placeholder="placeholder" :autofocus="autofocus"></ais-input>
<button type="submit" :class="bem('submit')">
<div v-if="showLoadingIndicator" :style="searchStore.isSearchStalled ? 'display:block;' : 'display:none;'" :class="bem('loading-indicator')" >
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the hidden attribute, which implies display: none; but is better for a11y

Copy link
Contributor

Choose a reason for hiding this comment

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

:hidden="!searchStore.isSearchStalled"

@bobylito
Copy link
Contributor Author

Updated per your suggestion @Haroenv thanks :)

@bobylito bobylito merged commit 192ecee into master Jan 29, 2018
@bobylito bobylito deleted the feat/loading-indicator branch January 29, 2018 16:51
Haroenv pushed a commit to algolia/instantsearch that referenced this pull request Dec 28, 2022
…ading-indicator

feat: provide a loading indicator
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants