Skip to content

Commit

Permalink
feat: use of popular searches as a QP fallback (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertjcuac authored Feb 13, 2024
1 parent 44604dc commit 90f71e2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
@XProvide('queriesPreviewInfo')
public get queriesPreviewInfo(): QueryPreviewInfo[] | undefined {
return this.snippetConfig.queriesPreview;
return this.snippetConfig.queriesPreview ?? [];
}
@Watch('snippetConfig.uiLang')
Expand Down
6 changes: 3 additions & 3 deletions src/components/desktop/desktop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<LocationProvider location="no_query">
<CustomQueryPreview class="x-mt-56" />
<PreSearchManager :maxPopularSearchesToRender="5" class="x-mt-56" />
</LocationProvider>

<LocationProvider location="results">
Expand Down Expand Up @@ -56,19 +56,18 @@
import { Component } from 'vue-property-decorator';
import { MainScroll, Scroll } from '@empathyco/x-components/scroll';
import Main from '../main.vue';
import CustomQueryPreview from '../pre-search/custom-query-preview.vue';
import ScrollToTop from '../scroll-to-top.vue';
import HasSearchedMixin from '../has-searched.mixin';
import MyHistoryAside from '../my-history/my-history-aside.vue';
import MyHistoryConfirmDisableModal from '../my-history/my-history-confirm-disable-modal.vue';
import MaxDesktopWidthItem from '../max-desktop-width-item.vue';
import PreSearchManager from '../pre-search/pre-search-manager.vue';
import DesktopTopSection from './desktop-top-section.vue';
@Component({
components: {
DesktopTopSection,
MaxDesktopWidthItem,
CustomQueryPreview,
BaseIdModal,
MyHistoryAside,
LocationProvider,
Expand All @@ -77,6 +76,7 @@
MyHistoryConfirmDisableModal,
Scroll,
ScrollToTop,
PreSearchManager,
DesktopAside: () => import('../search').then(m => m.DesktopAside),
NoResultsMessage: () => import('../search').then(m => m.NoResultsMessage),
SpellcheckMessage: () => import('../search').then(m => m.SpellcheckMessage),
Expand Down
8 changes: 4 additions & 4 deletions src/components/mobile/mobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<MainScroll>
<Scroll id="main-scroll" class="x-flex-1">
<LocationProvider location="no_query">
<CustomQueryPreview class="x-mt-16" />
<PreSearchManager class="x-mt-16" />
</LocationProvider>

<LocationProvider location="results">
Expand All @@ -44,7 +44,7 @@
</Scroll>
</MainScroll>

<div class="x-layout-item x-layout-overlap x-pointer-events-none">
<div class="x-layout-overlap x-layout-item x-pointer-events-none">
<div class="x-mb-32 x-grid x-grid-cols-12 x-gap-24">
<MobileOpenAside
v-if="$x.totalResults > 0"
Expand Down Expand Up @@ -89,7 +89,7 @@
import { Component } from 'vue-property-decorator';
import { MainScroll, Scroll } from '@empathyco/x-components/scroll';
import Main from '../main.vue';
import CustomQueryPreview from '../pre-search/custom-query-preview.vue';
import PreSearchManager from '../pre-search/pre-search-manager.vue';
import ScrollToTop from '../scroll-to-top.vue';
import PredictiveLayer from '../predictive-layer/predictive-layer.vue';
import SearchBox from '../search-box.vue';
Expand All @@ -104,7 +104,7 @@
ArrowLeftIcon,
BaseIdModal,
CloseMainModal,
CustomQueryPreview,
PreSearchManager,
LocationProvider,
MobileSubHeader,
Main,
Expand Down
7 changes: 3 additions & 4 deletions src/components/pre-search/custom-query-preview.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<QueryPreviewList
v-if="!$x.query.searchBox && queriesPreviewInfo"
v-if="queriesPreviewInfo"
:debounceTimeMs="250"
:queriesPreviewInfo="queriesPreviewInfo"
#default="{ queryPreviewInfo, totalResults, results }"
Expand Down Expand Up @@ -46,7 +46,6 @@
import {
BaseEventButton,
QueryFeature,
XInject,
ItemsList,
ArrowRightIcon
} from '@empathyco/x-components';
Expand All @@ -71,7 +70,7 @@
@Prop({ default: 'customer' })
protected queryFeature!: QueryFeature;
@XInject('queriesPreviewInfo')
public queriesPreviewInfo!: QueryPreviewInfo[];
@Prop()
protected queriesPreviewInfo!: QueryPreviewInfo[];
}
</script>
60 changes: 60 additions & 0 deletions src/components/pre-search/pre-search-manager.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<div v-if="!$x.query.searchBox">
<h1 v-if="!hasQueryPreviews" class="x-title1 max-desktop:x-title1-sm max-desktop:x-px-16">
{{ $t('popularSearches.title') }}
</h1>
<CustomQueryPreview :queriesPreviewInfo="queriesPreviewToRender" />
</div>
</template>

<script lang="ts">
import { computed, defineComponent, inject } from 'vue';
import { QueryPreviewInfo } from '@empathyco/x-components/queries-preview';
import { PopularSearchesState } from '@empathyco/x-components/types';
import { XPlugin } from '@empathyco/x-components';
import { popularSearchesXModule } from '@empathyco/x-components/popular-searches';
import { useStore } from '../../composables/use-store.composable';
import CustomQueryPreview from './custom-query-preview.vue';
export default defineComponent({
components: {
CustomQueryPreview
},
props: {
maxPopularSearchesToRender: {
type: Number,
default: 4
}
},
setup(props) {
XPlugin.registerXModule(popularSearchesXModule);
const injectedQueriesPreviewInfo = computed<QueryPreviewInfo[]>(() => {
const injectedQueriesPreview = inject<QueryPreviewInfo[] | { value: QueryPreviewInfo[] }>(
'queriesPreviewInfo',
[]
);
return 'value' in injectedQueriesPreview
? injectedQueriesPreview.value
: injectedQueriesPreview;
});
const hasQueryPreviews = computed<boolean>(
() => injectedQueriesPreviewInfo.value.length !== 0
);
const queriesPreviewToRender = computed<QueryPreviewInfo[]>(() => {
const popularSearches = (useStore('popularSearches') as PopularSearchesState)
.popularSearches;
const queryPreviewInfo: QueryPreviewInfo[] = popularSearches.map(item => ({
query: item.query
}));
return hasQueryPreviews.value
? injectedQueriesPreviewInfo.value
: queryPreviewInfo.slice(0, props.maxPopularSearchesToRender);
});
return { hasQueryPreviews, queriesPreviewToRender };
}
});
</script>

0 comments on commit 90f71e2

Please sign in to comment.