Skip to content

Commit

Permalink
add isMobile to store
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar committed Feb 12, 2025
1 parent 8302720 commit 7a7f61a
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {DEFAULT_MOBILE_BREAKPOINT} from '@/src/utils/replace-breakpoint';
import {InsightEngine} from '@coveo/headless/insight';
import {
FacetInfo,
Expand All @@ -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<FacetInfo>;
numericFacets: FacetStore<FacetInfo & FacetValueFormat<NumericFacetValue>>;
dateFacets: FacetStore<FacetInfo & FacetValueFormat<DateFacetValue>>;
Expand All @@ -30,6 +33,7 @@ interface Data {
}

export type InsightStore = BaseStore<Data> & {
isMobile(): boolean;
unsetLoadingFlag(loadingFlag: string): void;
setLoadingFlag(flag: string): void;
registerFacet<T extends FacetType, U extends string>(
Expand All @@ -46,6 +50,7 @@ export function createInsightStore(): InsightStore {
loadingFlags: [],
iconAssetsPath: '',
resultList: undefined,
mobileBreakpoint: DEFAULT_MOBILE_BREAKPOINT,
facets: {},
numericFacets: {},
dateFacets: {},
Expand All @@ -65,6 +70,11 @@ export function createInsightStore(): InsightStore {
setLoadingFlag(store, loadingFlag);
},

isMobile() {
return !window.matchMedia(makeDesktopQuery(store.state.mobileBreakpoint))
.matches;
},

registerFacet<T extends FacetType, U extends string>(
facetType: T,
data: Data[T][U] & {facetId: U; element: HTMLElement}
Expand Down

0 comments on commit 7a7f61a

Please sign in to comment.