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

Commit

Permalink
feat(smartSort): add widget
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee committed Feb 25, 2021
1 parent 5d79990 commit 9d192a5
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"algoliasearch-helper": "^3.1.0",
"instantsearch.js": "^4.11.0"
"instantsearch.js": "https://pkg.csb.dev/algolia/instantsearch.js/commit/c939bfc4/instantsearch.js"
},
"peerDependencies": {
"algoliasearch": ">= 3.32.0 < 5",
Expand Down
53 changes: 53 additions & 0 deletions src/components/SmartSort.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<div
v-if="state"
:class="suit()"
>
<slot
:is-smart-sorted="state.isSmartSorted"
:is-virtual-replica="state.isVirtualReplica"
:refine="state.refine"
>
<div
:class="suit('text')"
>
<slot
name="text"
/>
</div>
<button
type="button"
:class="suit('button')"
@click="refine()"
>
<slot
name="button"
:is-smart-sorted="state.isSmartSorted"
>{{ state.isSmartSorted ? 'See all results' : 'See relevant results' }}</slot>
</button>
</slot>
</div>
</template>

<script>
import { connectSmartSort } from 'instantsearch.js/es/connectors';
import { createWidgetMixin } from '../mixins/widget';
import { createSuitMixin } from '../mixins/suit';
export default {
name: 'AisSmartSort',
mixins: [
createSuitMixin({ name: 'SmartSort' }),
createWidgetMixin({ connector: connectSmartSort }),
],
methods: {
refine() {
if (this.state.isSmartSorted) {
this.state.refine(0);
} else {
this.state.refine(undefined);
}
},
},
};
</script>
1 change: 1 addition & 0 deletions src/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export {
default as AisToggleRefinement,
} from './components/ToggleRefinement.vue';
export { default as AisVoiceSearch } from './components/VoiceSearch.vue';
export { default as AisSmartSort } from './components/SmartSort.vue';
17 changes: 17 additions & 0 deletions stories/SmartSort.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import algoliasearch from 'algoliasearch/lite';
import { storiesOf } from '@storybook/vue';
import { previewWrapper } from './utils';

storiesOf('ais-smart-sort', module)
.addDecorator(
previewWrapper({
searchClient: algoliasearch(
'C7RIRJRYR9',
'77af6d5ffb27caa5ff4937099fcb92e8'
),
indexName: 'test_Bestbuy_vr_price_asc',
})
)
.add('default', () => ({
template: '<ais-smart-sort></ais-smart-sort>',
}));
17 changes: 8 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ algoliasearch-helper@^3.1.0:
dependencies:
events "^1.1.1"

algoliasearch-helper@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-3.3.4.tgz#4a3c56d42a2a81589d5722b73653b2deaf3e7064"
integrity sha512-1Ts2XcgGdjGlDrp3v6zbY8VW+X9+jJ5rBmtPBmXOQLd4b5t/LpJlaBdxoAnlMfVFjywP7KSAdmyFUNNYVHDyRQ==
algoliasearch-helper@^3.4.4:
version "3.4.4"
resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-3.4.4.tgz#f2eb46bc4d2f6fed82c7201b8ac4ce0a1988ae67"
integrity sha512-OjyVLjykaYKCMxxRMZNiwLp8CS310E0qAeIY2NaublcmLAh8/SL19+zYHp7XCLtMem2ZXwl3ywMiA32O9jszuw==
dependencies:
events "^1.1.1"

Expand Down Expand Up @@ -7878,13 +7878,12 @@ instantsearch.css@7.3.1:
resolved "https://registry.yarnpkg.com/instantsearch.css/-/instantsearch.css-7.3.1.tgz#7ab74a8f355091ae040947a9cf5438f379026622"
integrity sha512-/kaMDna5D+Q9mImNBHEhb9HgHATDOFKYii7N1Iwvrj+lmD9gBJLqVhUw67gftq2O0QI330pFza+CRscIwB1wQQ==

instantsearch.js@^4.11.0:
version "4.11.0"
resolved "https://registry.yarnpkg.com/instantsearch.js/-/instantsearch.js-4.11.0.tgz#9e55426fbcf1929df9a772c53eeae282575e1a13"
integrity sha512-SVdS63S7skry5ebttPOq9D/BB2H61lYL2qdRiGdeuxsbrkwNssvpmtt/kAKxrnySUNxiSI2ZKTH2wa2WaMU98A==
"instantsearch.js@https://pkg.csb.dev/algolia/instantsearch.js/commit/c939bfc4/instantsearch.js":
version "4.15.0"
resolved "https://pkg.csb.dev/algolia/instantsearch.js/commit/c939bfc4/instantsearch.js#25ca342afe3926762e49341405de1bb86c3546e7"
dependencies:
"@types/googlemaps" "^3.39.6"
algoliasearch-helper "^3.3.4"
algoliasearch-helper "^3.4.4"
classnames "^2.2.5"
events "^1.1.0"
hogan.js "^3.0.2"
Expand Down

0 comments on commit 9d192a5

Please sign in to comment.