cloudcommerce 0.36.2 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
- package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
- package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/barra-doce/package.json +2 -2
- package/package.json +5 -5
- package/packages/api/package.json +1 -1
- package/packages/apps/affilate-program/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +1 -1
- package/packages/apps/fb-conversions/package.json +2 -2
- package/packages/apps/flash-courier/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/galaxpay/package.json +1 -1
- package/packages/apps/google-analytics/package.json +1 -1
- package/packages/apps/jadlog/package.json +1 -1
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mandae/package.json +1 -1
- package/packages/apps/melhor-envio/package.json +1 -1
- package/packages/apps/mercadopago/package.json +1 -1
- package/packages/apps/pagarme/package.json +1 -1
- package/packages/apps/pagarme-v5/package.json +1 -1
- package/packages/apps/paghiper/package.json +1 -1
- package/packages/apps/pix/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/apps/webhooks/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +1 -1
- package/packages/eslint/package.json +5 -5
- package/packages/events/package.json +1 -1
- package/packages/feeds/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +4 -4
- package/packages/storefront/package.json +11 -10
- package/packages/storefront/src/lib/components/CarouselControl.vue +1 -1
- package/packages/storefront/src/lib/composables/use-search-modal.ts +86 -0
- package/packages/storefront/src/lib/state/search-engine.ts +23 -13
- package/packages/storefront/src/lib/state/shopping-cart.ts +2 -1
- package/packages/test-base/package.json +1 -1
- package/packages/types/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.37.0](https://github.com/ecomplus/cloud-commerce/compare/v0.36.2...v0.37.0) (2023-12-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* **storefront:** Search engine constructor does not receive nor mantain `url` option anymore, forcing it to `search/v1`, params should be set separately
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **storefront:** Add `isFetching` ref to search engine class ([014640e](https://github.com/ecomplus/cloud-commerce/commit/014640e4e659d1a6b8a3d48113c9fbfe529a08ac))
|
|
15
|
+
* **storefront:** Handling count and faceted search on `SearchEngine` with new public attributes ([e609e88](https://github.com/ecomplus/cloud-commerce/commit/e609e88749c23ec5ac77f410683f2abe41f13602))
|
|
16
|
+
* **storefront:** New `useSearchModal` composable ([91d21d5](https://github.com/ecomplus/cloud-commerce/commit/91d21d5aef738d9570c951b041b7c720851f6b7e))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **deps:** Update non-major dependencies ([#282](https://github.com/ecomplus/cloud-commerce/issues/282)) ([0b5eb14](https://github.com/ecomplus/cloud-commerce/commit/0b5eb148ca758240045812eca5c04a5dd6b6b435))
|
|
22
|
+
* **storefront:** Bump astro to v3.6.4 ([#284](https://github.com/ecomplus/cloud-commerce/issues/284)) ([04c8b55](https://github.com/ecomplus/cloud-commerce/commit/04c8b557bda1aa618e974351d7471210a25e7ff3))
|
|
23
|
+
* **storefront:** Bump Vue to v3.3.10 ([6dc5924](https://github.com/ecomplus/cloud-commerce/commit/6dc5924c4de100dc62ec1e116cc83a3cd92d759e))
|
|
24
|
+
* **storefront:** Ensure `shoppingCart` state type with subtotal defined (number) ([47aedfe](https://github.com/ecomplus/cloud-commerce/commit/47aedfede02499cd62d9e7b0c50861284c5e8650))
|
|
25
|
+
* **storefront:** Minor edit `SearchEngine` to ensure current term is on top of history list ([6a893c1](https://github.com/ecomplus/cloud-commerce/commit/6a893c19034afd4e8aa866adf4a22b60a483b626))
|
|
26
|
+
* **storefront:** Properly handling `SearchEngine` fetching state ([1fabf0a](https://github.com/ecomplus/cloud-commerce/commit/1fabf0a9b57dd565bc7157501a4da788f2d40aba))
|
|
27
|
+
* **storefront:** Set `CarouselControl>` default zindex to 11 ([fb82ef0](https://github.com/ecomplus/cloud-commerce/commit/fb82ef0c8998754a1fd131afcc553410517ed176))
|
|
28
|
+
|
|
5
29
|
### [0.36.2](https://github.com/ecomplus/cloud-commerce/compare/v0.36.1...v0.36.2) (2023-12-03)
|
|
6
30
|
|
|
7
31
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "index.js",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@cloudcommerce/feeds": "^0.36.
|
|
19
|
-
"@cloudcommerce/firebase": "^0.36.
|
|
20
|
-
"@cloudcommerce/passport": "^0.36.
|
|
18
|
+
"@cloudcommerce/feeds": "^0.36.2",
|
|
19
|
+
"@cloudcommerce/firebase": "^0.36.2",
|
|
20
|
+
"@cloudcommerce/passport": "^0.36.2"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "index.js",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cloudcommerce/api": "^0.36.
|
|
21
|
-
"@cloudcommerce/firebase": "^0.36.
|
|
22
|
-
"@cloudcommerce/ssr": "^0.36.
|
|
20
|
+
"@cloudcommerce/api": "^0.36.2",
|
|
21
|
+
"@cloudcommerce/firebase": "^0.36.2",
|
|
22
|
+
"@cloudcommerce/ssr": "^0.36.2",
|
|
23
23
|
"@headlessui/vue": "^1.7.16"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@cloudcommerce/i18n": "^0.36.
|
|
27
|
-
"@cloudcommerce/storefront": "^0.36.
|
|
28
|
-
"@cloudcommerce/types": "^0.36.
|
|
26
|
+
"@cloudcommerce/i18n": "^0.36.2",
|
|
27
|
+
"@cloudcommerce/storefront": "^0.36.2",
|
|
28
|
+
"@cloudcommerce/types": "^0.36.2",
|
|
29
29
|
"@fontsource/croissant-one": "^5.0.17",
|
|
30
30
|
"@iconify-json/mingcute": "^1.1.11",
|
|
31
31
|
"photoswipe": "^5.4.2"
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "index.js",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@cloudcommerce/events": "^0.36.
|
|
19
|
-
"@cloudcommerce/firebase": "^0.36.
|
|
20
|
-
"@cloudcommerce/modules": "^0.36.
|
|
18
|
+
"@cloudcommerce/events": "^0.36.2",
|
|
19
|
+
"@cloudcommerce/firebase": "^0.36.2",
|
|
20
|
+
"@cloudcommerce/modules": "^0.36.2"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"url": "https://github.com/ecomplus/cloud-commerce/issues"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@cloudcommerce/cli": "^0.36.
|
|
26
|
+
"@cloudcommerce/cli": "^0.36.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@cloudcommerce/eslint": "^0.36.
|
|
29
|
+
"@cloudcommerce/eslint": "^0.36.2"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcommerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
|
|
6
6
|
"main": "packages/api/lib/index.js",
|
|
7
7
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"@commitlint/cli": "^18.4.3",
|
|
20
20
|
"@commitlint/config-conventional": "^18.4.3",
|
|
21
21
|
"@commitlint/rules": "^18.4.3",
|
|
22
|
-
"@types/node": "^18.
|
|
23
|
-
"eslint": "^8.
|
|
22
|
+
"@types/node": "^18.19.2",
|
|
23
|
+
"eslint": "^8.55.0",
|
|
24
24
|
"husky": "^8.0.3",
|
|
25
25
|
"standard-version": "^9.5.0",
|
|
26
26
|
"ts-node": "^10.9.1",
|
|
27
27
|
"turbo": "^1.10.16",
|
|
28
28
|
"typescript": "~5.2.2",
|
|
29
29
|
"uglify-js": "^3.17.4",
|
|
30
|
-
"vite": "^4.5.
|
|
30
|
+
"vite": "^4.5.1",
|
|
31
31
|
"vitest": "^0.34.6",
|
|
32
32
|
"zx": "^7.2.3",
|
|
33
|
-
"@cloudcommerce/eslint": "0.
|
|
33
|
+
"@cloudcommerce/eslint": "0.37.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"fix-install": "bash scripts/pre-install.sh && pnpm i",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-fb-conversions",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app to send carts/orders to Facebook Conversions API",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@cloudcommerce/api": "workspace:*",
|
|
23
23
|
"@cloudcommerce/firebase": "workspace:*",
|
|
24
|
-
"facebook-nodejs-business-sdk": "^18.0.
|
|
24
|
+
"facebook-nodejs-business-sdk": "^18.0.4",
|
|
25
25
|
"firebase-admin": "^11.11.1",
|
|
26
26
|
"firebase-functions": "^4.5.0"
|
|
27
27
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/eslint",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce ESLint config",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"build": "echo '@ecomplus/eslint'"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
23
|
-
"@typescript-eslint/parser": "^6.
|
|
24
|
-
"eslint": "^8.
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
|
23
|
+
"@typescript-eslint/parser": "^6.13.1",
|
|
24
|
+
"eslint": "^8.55.0",
|
|
25
25
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
26
26
|
"eslint-plugin-import": "^2.29.0",
|
|
27
27
|
"eslint-plugin-tailwindcss": "3.13.0",
|
|
28
|
-
"eslint-plugin-vue": "^9.
|
|
28
|
+
"eslint-plugin-vue": "^9.19.2"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront SSR",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"build:workers": "npx tsc -p src/cloudflare --outDir cloudflare && npx eslint --ext .js cloudflare --fix"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@astrojs/node": "6.0
|
|
28
|
+
"@astrojs/node": "6.1.0",
|
|
29
29
|
"@cloudcommerce/api": "workspace:*",
|
|
30
30
|
"@cloudcommerce/firebase": "workspace:*",
|
|
31
31
|
"@cloudcommerce/i18n": "workspace:*",
|
|
32
32
|
"@ecomplus/utils": "1.5.0-rc.5",
|
|
33
33
|
"@vueuse/core": "10.6.1",
|
|
34
|
-
"astro": "3.6.
|
|
34
|
+
"astro": "3.6.4",
|
|
35
35
|
"astro-capo": "^0.0.1",
|
|
36
36
|
"axios": "^1.6.2",
|
|
37
37
|
"firebase-admin": "^11.11.1",
|
|
38
38
|
"firebase-functions": "^4.5.0",
|
|
39
39
|
"mitt": "^3.0.1",
|
|
40
|
-
"vue": "3.3.
|
|
40
|
+
"vue": "3.3.10"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@cloudcommerce/types": "workspace:*",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/storefront",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront with Astro",
|
|
6
6
|
"bin": {
|
|
7
7
|
"storefront": "./scripts/build-prod.sh"
|
|
@@ -29,24 +29,25 @@
|
|
|
29
29
|
"prepare-monorepo": "bash scripts/prepare-monorepo.sh"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@astrojs/node": "6.0
|
|
32
|
+
"@astrojs/node": "6.1.0",
|
|
33
33
|
"@astrojs/vue": "3.0.4",
|
|
34
34
|
"@cloudcommerce/api": "workspace:*",
|
|
35
35
|
"@cloudcommerce/config": "workspace:*",
|
|
36
36
|
"@cloudcommerce/i18n": "workspace:*",
|
|
37
37
|
"@ecomplus/utils": "1.5.0-rc.5",
|
|
38
38
|
"@fastify/deepmerge": "^1.3.0",
|
|
39
|
-
"@iconify-json/fa6-brands": "^1.1.
|
|
40
|
-
"@iconify-json/heroicons": "^1.1.
|
|
41
|
-
"@iconify-json/logos": "^1.1.
|
|
39
|
+
"@iconify-json/fa6-brands": "^1.1.17",
|
|
40
|
+
"@iconify-json/heroicons": "^1.1.15",
|
|
41
|
+
"@iconify-json/logos": "^1.1.40",
|
|
42
|
+
"@orama/orama": "2.0.0-beta.8",
|
|
42
43
|
"@types/gtag.js": "^0.0.18",
|
|
43
|
-
"@vite-pwa/astro": "^0.1.
|
|
44
|
+
"@vite-pwa/astro": "^0.1.6",
|
|
44
45
|
"@vueuse/core": "10.6.1",
|
|
45
|
-
"astro": "3.6.
|
|
46
|
+
"astro": "3.6.4",
|
|
46
47
|
"astro-capo": "^0.0.1",
|
|
47
48
|
"chroma-js": "^2.4.2",
|
|
48
49
|
"dotenv": "^16.3.1",
|
|
49
|
-
"firebase": "^10.
|
|
50
|
+
"firebase": "^10.7.0",
|
|
50
51
|
"image-size": "^1.0.2",
|
|
51
52
|
"mime": "^3.0.0",
|
|
52
53
|
"mitt": "^3.0.1",
|
|
@@ -55,9 +56,9 @@
|
|
|
55
56
|
"tailwindcss": "^3.3.5",
|
|
56
57
|
"unocss": "^0.57.7",
|
|
57
58
|
"unplugin-auto-import": "^0.16.7",
|
|
58
|
-
"vite": "^4.5.
|
|
59
|
+
"vite": "^4.5.1",
|
|
59
60
|
"vite-plugin-pwa": "^0.17.2",
|
|
60
|
-
"vue": "3.3.
|
|
61
|
+
"vue": "3.3.10"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@cloudcommerce/eslint": "workspace:*",
|
|
@@ -18,7 +18,7 @@ const isX = axis === 'x';
|
|
|
18
18
|
type="button"
|
|
19
19
|
:aria-label="!isPrev ? $t.i19next : $t.i19previous"
|
|
20
20
|
@click="changeSlide(!isPrev ? 1 : -1)"
|
|
21
|
-
class="group absolute z-[
|
|
21
|
+
class="group absolute z-[11]"
|
|
22
22
|
:class="isX
|
|
23
23
|
? `${(!isPrev ? 'right-0' : 'left-0')} top-0`
|
|
24
24
|
: `${(!isPrev ? 'bottom-0' : 'top-0')} left-0`"
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Categories,
|
|
3
|
+
Brands,
|
|
4
|
+
Collections,
|
|
5
|
+
} from '@cloudcommerce/api/types';
|
|
6
|
+
import type { Orama } from '@orama/orama';
|
|
7
|
+
import { ref, watch, toRef } from 'vue';
|
|
8
|
+
import {
|
|
9
|
+
create as oramaCreate,
|
|
10
|
+
search as oramaSearch,
|
|
11
|
+
insert as oramaInsert,
|
|
12
|
+
} from '@orama/orama';
|
|
13
|
+
import { SearchEngine, searchHistory } from '@@sf/state/search-engine';
|
|
14
|
+
|
|
15
|
+
export interface Props {
|
|
16
|
+
term: string;
|
|
17
|
+
fetchDebounce?: number;
|
|
18
|
+
productsLimit?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const oramaDocSchema = {
|
|
22
|
+
name: 'string',
|
|
23
|
+
slug: 'string',
|
|
24
|
+
short_description: 'string',
|
|
25
|
+
} as const;
|
|
26
|
+
const oramaDocs: Array<{ [k:string]:any } & { name: string, slug: string }> = [];
|
|
27
|
+
const storefrontData = globalThis.$storefront.data as {
|
|
28
|
+
categories?: Array<Partial<Categories>>,
|
|
29
|
+
brands?: Array<Partial<Brands>>,
|
|
30
|
+
collections?: Array<Partial<Collections>>,
|
|
31
|
+
};
|
|
32
|
+
(['categories', 'brands', 'collections'] as const).forEach((resource) => {
|
|
33
|
+
const docsList = storefrontData[resource];
|
|
34
|
+
if (docsList) {
|
|
35
|
+
for (let i = 0; i < docsList.length; i++) {
|
|
36
|
+
const doc = docsList[i];
|
|
37
|
+
const { name, slug } = doc;
|
|
38
|
+
if (name && slug) {
|
|
39
|
+
oramaDocs.push({ ...doc, name, slug });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let oramaDb: Orama<typeof oramaDocSchema> | undefined;
|
|
45
|
+
if (oramaDocs.length) {
|
|
46
|
+
(async () => {
|
|
47
|
+
const _oramaDb = await oramaCreate({ schema: oramaDocSchema });
|
|
48
|
+
oramaDocs.forEach((doc) => oramaInsert(_oramaDb, doc));
|
|
49
|
+
oramaDb = _oramaDb;
|
|
50
|
+
})();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const useSearchModal = (props: Props) => {
|
|
54
|
+
const searchEngine = new SearchEngine({
|
|
55
|
+
debounce: props.fetchDebounce || 300,
|
|
56
|
+
});
|
|
57
|
+
searchEngine.pageSize.value = props.productsLimit || 12;
|
|
58
|
+
searchEngine.isWithCount.value = true;
|
|
59
|
+
searchEngine.isWithBuckets.value = false;
|
|
60
|
+
const productCount = ref(0);
|
|
61
|
+
const linkHits = ref<Array<{ title: string, href: string }>>([]);
|
|
62
|
+
watch(toRef(props, 'term'), async (term) => {
|
|
63
|
+
searchEngine.fetch(term);
|
|
64
|
+
if (oramaDb) {
|
|
65
|
+
const { hits } = await oramaSearch(oramaDb, { term });
|
|
66
|
+
linkHits.value = hits.map(({ document: { name, slug } }) => {
|
|
67
|
+
return { title: name, href: `/${slug}` };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
immediate: true,
|
|
72
|
+
});
|
|
73
|
+
watch(searchEngine.meta, () => {
|
|
74
|
+
productCount.value = searchEngine.meta.count || 0;
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
searchHistory,
|
|
78
|
+
searchEngine,
|
|
79
|
+
isFetching: searchEngine.isFetching,
|
|
80
|
+
productHits: searchEngine.products,
|
|
81
|
+
productCount,
|
|
82
|
+
linkHits,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default useSearchModal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SearchItem } from '@cloudcommerce/types';
|
|
1
|
+
import type { SearchItem, SearchResult } from '@cloudcommerce/types';
|
|
2
2
|
import { ref, watch, shallowReactive } from 'vue';
|
|
3
3
|
import { useDebounceFn } from '@vueuse/core';
|
|
4
4
|
import api from '@cloudcommerce/api';
|
|
@@ -30,13 +30,12 @@ export const search = async ({
|
|
|
30
30
|
term,
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
|
-
if (response.data.result.length
|
|
33
|
+
if (response.data.result.length) {
|
|
34
34
|
const termIndex = searchHistory.findIndex((_term) => term.startsWith(_term));
|
|
35
35
|
if (termIndex > -1) {
|
|
36
|
-
searchHistory
|
|
37
|
-
} else {
|
|
38
|
-
searchHistory.unshift(term);
|
|
36
|
+
searchHistory.splice(termIndex, 1);
|
|
39
37
|
}
|
|
38
|
+
searchHistory.unshift(term);
|
|
40
39
|
while (searchHistory.length > 20) {
|
|
41
40
|
searchHistory.pop();
|
|
42
41
|
}
|
|
@@ -45,27 +44,35 @@ export const search = async ({
|
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
export class SearchEngine {
|
|
48
|
-
url: 'search/v1' | `search/v1?${string}`;
|
|
49
47
|
fields?: readonly string[];
|
|
50
48
|
term = ref('');
|
|
49
|
+
isWithCount = ref(true);
|
|
50
|
+
isWithBuckets = ref(true);
|
|
51
51
|
params = shallowReactive<Record<string, any>>({});
|
|
52
52
|
pageSize = ref(24);
|
|
53
53
|
pageNumber = ref(1);
|
|
54
|
+
isFetching = ref(false);
|
|
54
55
|
products = shallowReactive<SearchItem[]>([]);
|
|
56
|
+
meta = shallowReactive<SearchResult<'v1'>['meta']>({
|
|
57
|
+
offset: 0,
|
|
58
|
+
limit: 0,
|
|
59
|
+
fields: [],
|
|
60
|
+
sort: [],
|
|
61
|
+
query: {},
|
|
62
|
+
});
|
|
55
63
|
#search: ReturnType<typeof useDebounceFn<typeof search>>;
|
|
56
64
|
constructor({
|
|
57
65
|
fields,
|
|
58
|
-
url = 'search/v1',
|
|
59
66
|
debounce = 150,
|
|
60
67
|
}: {
|
|
61
68
|
fields?: readonly string[],
|
|
62
|
-
url?: 'search/v1' | `search/v1?${string}`,
|
|
63
69
|
debounce?: number,
|
|
64
70
|
} = {}) {
|
|
65
71
|
this.fields = fields;
|
|
66
|
-
this
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
this.#search = useDebounceFn((opts) => {
|
|
73
|
+
this.isFetching.value = true;
|
|
74
|
+
return search(opts);
|
|
75
|
+
}, debounce);
|
|
69
76
|
watch([this.term, this.params], () => {
|
|
70
77
|
this.pageNumber.value = 1;
|
|
71
78
|
});
|
|
@@ -81,17 +88,20 @@ export class SearchEngine {
|
|
|
81
88
|
const response = await this.#search({
|
|
82
89
|
term: this.term.value,
|
|
83
90
|
params: {
|
|
91
|
+
...this.params,
|
|
84
92
|
limit,
|
|
85
93
|
offset,
|
|
86
|
-
|
|
94
|
+
count: this.isWithCount.value || undefined,
|
|
95
|
+
buckets: this.isWithBuckets.value || undefined,
|
|
87
96
|
},
|
|
88
|
-
url: this.url,
|
|
89
97
|
fields: this.fields,
|
|
90
98
|
});
|
|
91
99
|
if (response) {
|
|
100
|
+
this.isFetching.value = false;
|
|
92
101
|
const { data } = response;
|
|
93
102
|
if (data.meta) {
|
|
94
103
|
this.products.splice(0);
|
|
104
|
+
Object.assign(this.meta, data.meta);
|
|
95
105
|
}
|
|
96
106
|
data.result.forEach((item) => this.products.push(item));
|
|
97
107
|
}
|
|
@@ -9,9 +9,10 @@ import parseProduct from '@@sf/state/shopping-cart/parse-product';
|
|
|
9
9
|
type CartItem = CartSet['items'][0];
|
|
10
10
|
const storageKey = 'ecomShoppingCart';
|
|
11
11
|
const emptyCart = {
|
|
12
|
+
subtotal: 0,
|
|
12
13
|
items: [],
|
|
13
14
|
};
|
|
14
|
-
const shoppingCart = useStorage<CartSet>(storageKey, emptyCart);
|
|
15
|
+
const shoppingCart = useStorage<CartSet & { subtotal: number }>(storageKey, emptyCart);
|
|
15
16
|
const totalItems = computed(() => {
|
|
16
17
|
return shoppingCart.items.reduce((acc, item) => {
|
|
17
18
|
return acc + item.quantity;
|