From 7a7f61ad04095891b6e5a94108b73021fc57503e Mon Sep 17 00:00:00 2001 From: ylakhdar Date: Wed, 12 Feb 2025 09:26:20 -0500 Subject: [PATCH] add isMobile to store https://coveord.atlassian.net/browse/KIT-3959 --- .../insight/atomic-insight-interface/store.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/atomic/src/components/insight/atomic-insight-interface/store.ts b/packages/atomic/src/components/insight/atomic-insight-interface/store.ts index 333ce4a1413..a41d5e70d0d 100644 --- a/packages/atomic/src/components/insight/atomic-insight-interface/store.ts +++ b/packages/atomic/src/components/insight/atomic-insight-interface/store.ts @@ -1,3 +1,4 @@ +import {DEFAULT_MOBILE_BREAKPOINT} from '@/src/utils/replace-breakpoint'; import {InsightEngine} from '@coveo/headless/insight'; import { FacetInfo, @@ -16,11 +17,13 @@ import { waitUntilAppLoaded, } from '../../common/interface/store'; import {DateFacetValue, NumericFacetValue} from '../../common/types'; +import {makeDesktopQuery} from '../atomic-insight-layout/insight-layout'; interface Data { loadingFlags: string[]; iconAssetsPath: string; resultList: ResultListInfo | undefined; + mobileBreakpoint: string; facets: FacetStore; numericFacets: FacetStore>; dateFacets: FacetStore>; @@ -30,6 +33,7 @@ interface Data { } export type InsightStore = BaseStore & { + isMobile(): boolean; unsetLoadingFlag(loadingFlag: string): void; setLoadingFlag(flag: string): void; registerFacet( @@ -46,6 +50,7 @@ export function createInsightStore(): InsightStore { loadingFlags: [], iconAssetsPath: '', resultList: undefined, + mobileBreakpoint: DEFAULT_MOBILE_BREAKPOINT, facets: {}, numericFacets: {}, dateFacets: {}, @@ -65,6 +70,11 @@ export function createInsightStore(): InsightStore { setLoadingFlag(store, loadingFlag); }, + isMobile() { + return !window.matchMedia(makeDesktopQuery(store.state.mobileBreakpoint)) + .matches; + }, + registerFacet( facetType: T, data: Data[T][U] & {facetId: U; element: HTMLElement}