Skip to content

Commit 8eeb520

Browse files
author
Herve Tribouilloy
committed
Added a spinner to block the widget when AI search is happening
1 parent 5fb4a8f commit 8eeb520

6 files changed

Lines changed: 65 additions & 32 deletions

File tree

vite_project/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite_project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "widget-intent-discovery",
33
"private": true,
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

vite_project/src/components/IntentDiscovery.tsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {AttributeLayer} from "./AttributeLayer.tsx";
99
import {IntentDiscoveryOptions} from "./IntentDiscoveryOptions.tsx";
1010
import {ProductRecommendations} from "./ProductRecommendations.tsx";
1111
import {activity} from "../activity";
12+
import {useIntentDecision} from "../hooks/domain/useIntentDecision.tsx";
1213

1314
export interface Props {
1415
config: IntentDiscoveryDataConfig
@@ -21,6 +22,7 @@ export const IntentDiscovery = ({ config, categoryData }: Props) => {
2122
useFindAttributeLayer(categoryData);
2223

2324
const [showRightColumn, setShowRightColumn] = useState(false)
25+
const { shouldSearch } = useIntentDecision(attributeLayerData, config)
2426

2527
useEffect(() => {
2628
if (!attributeLayerData?.aggregations) return
@@ -34,28 +36,36 @@ export const IntentDiscovery = ({ config, categoryData }: Props) => {
3436
activity('attribute-layer', 'Attribute Layer', attributeLayerData);
3537

3638
return (
37-
<div className={showRightColumn ? "re-intent-layout re-intent-layout--two" : "re-intent-layout"}>
38-
<div className="re-intent-col re-intent-col--left">
39-
<AttributeLayer
40-
config={config}
41-
categoryData={categoryData}
42-
attributeLayerData={attributeLayerData}
43-
/>
44-
<IntentDiscoveryOptions
45-
config={config}
46-
categoryData={categoryData}
47-
attributeLayerData={attributeLayerData}
48-
/>
49-
</div>
39+
<>
40+
{shouldSearch && (
41+
<div className="intent-evaluation-overlay">
42+
<Spinner />
43+
<p>Evaluating your preferences…</p>
44+
</div>
45+
)}
46+
<div className={showRightColumn ? "re-intent-layout re-intent-layout--two" : "re-intent-layout"}>
47+
<div className="re-intent-col re-intent-col--left">
48+
<AttributeLayer
49+
config={config}
50+
categoryData={categoryData}
51+
attributeLayerData={attributeLayerData}
52+
/>
53+
<IntentDiscoveryOptions
54+
config={config}
55+
categoryData={categoryData}
56+
attributeLayerData={attributeLayerData}
57+
/>
58+
</div>
5059

51-
<div className="re-intent-col re-intent-col--right">
52-
<ProductRecommendations
53-
config={config}
54-
categoryData={categoryData}
55-
attributeLayerData={attributeLayerData}
56-
onVisibilityChange={setShowRightColumn}
57-
/>
60+
<div className="re-intent-col re-intent-col--right">
61+
<ProductRecommendations
62+
categoryData={categoryData}
63+
attributeLayerData={attributeLayerData}
64+
onVisibilityChange={setShowRightColumn}
65+
shouldSearch={shouldSearch}
66+
/>
67+
</div>
5868
</div>
59-
</div>
69+
</>
6070
);
6171
};

vite_project/src/components/ProductRecommendations.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
import type {MagentoProducts} from "../hooks/infra/useProductAttributeLayer.tsx";
2-
import type {IntentDiscoveryDataConfig} from "../domain/intent-discovery.types.ts";
32
import {useAnalyseSearch} from "../hooks/domain/useAnalyseSearch.tsx";
43
import type {MagentoCategory} from "../types/infra/magento/category.types.ts";
54
import {Spinner} from "./global/Spinner.tsx";
65
import {SuggestionContainer} from "./Suggestions/SuggestionContainer.tsx";
76
import {useEffect} from "react";
87

98
export interface Props {
10-
config: IntentDiscoveryDataConfig
119
categoryData: MagentoCategory
1210
attributeLayerData: MagentoProducts
1311
onVisibilityChange?: (visible: boolean) => void
12+
shouldSearch: boolean
1413
}
1514

1615
export const ProductRecommendations = ({
17-
config,
1816
categoryData,
1917
attributeLayerData,
20-
onVisibilityChange
18+
onVisibilityChange,
19+
shouldSearch
2120
}: Props) => {
22-
const threshold = config.ai.matchThreshold
23-
const total = attributeLayerData?.total_count ?? 0
24-
const shouldSearch = total <= threshold;
25-
2621
const { aiRecommendation, searchLoading, error } =
2722
useAnalyseSearch(
2823
attributeLayerData?.aggregations,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {MagentoProducts} from "../infra/useProductAttributeLayer.tsx";
2+
import type {IntentDiscoveryDataConfig} from "../../domain/intent-discovery.types.ts";
3+
4+
export const useIntentDecision = (attributeLayerData: MagentoProducts | undefined, config: IntentDiscoveryDataConfig) => {
5+
const threshold = config.ai.matchThreshold
6+
const total = attributeLayerData?.total_count ?? 0
7+
8+
return {
9+
total,
10+
shouldSearch: total <= threshold
11+
}
12+
}

vite_project/src/styles/intent-discovery.suggestions.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,20 @@
160160
font-size: 13px;
161161
color: #4b5563;
162162
line-height: 1.35;
163+
}
164+
165+
.intent-evaluation-container {
166+
position: relative;
167+
}
168+
169+
.intent-evaluation-overlay {
170+
position: absolute;
171+
inset: 0;
172+
background: rgba(255,255,255,0.85);
173+
display: flex;
174+
flex-direction: column;
175+
align-items: center;
176+
justify-content: center;
177+
z-index: 10;
178+
font-size: 16px;
163179
}

0 commit comments

Comments
 (0)