rockin 0.0.3 → 0.0.4
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/README.md +1 -1
- package/dist/chunk-C3RGHTDI.js +28 -0
- package/dist/cn.d.ts +3 -0
- package/dist/cn.js +5 -0
- package/dist/gravity.d.ts +0 -1
- package/dist/hooks/index.js +261 -8
- package/dist/ui/index.js +1 -2
- package/package.json +5 -1
- package/dist/chunk-TDCUCL6G.js +0 -292
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Focused entry points are also available:
|
|
|
23
23
|
```tsx
|
|
24
24
|
import { Button } from "rockin/ui"
|
|
25
25
|
import { useMounted } from "rockin/hooks"
|
|
26
|
-
import { cn } from "rockin/
|
|
26
|
+
import { cn } from "rockin/cn"
|
|
27
27
|
import { OpenAI } from "rockin/utils"
|
|
28
28
|
import { Loader } from "rockin/icon"
|
|
29
29
|
import * as Lucide from "rockin/lucide"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/hooks/useMediaQuery.ts
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
function useMediaQuery(query) {
|
|
4
|
+
const [matches, setMatches] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const mediaQuery = window.matchMedia(query);
|
|
7
|
+
const handleChange = () => setMatches(mediaQuery.matches);
|
|
8
|
+
handleChange();
|
|
9
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
10
|
+
return () => mediaQuery.removeEventListener("change", handleChange);
|
|
11
|
+
}, [query]);
|
|
12
|
+
return matches;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/hooks/useMounted.ts
|
|
16
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
17
|
+
function useMounted() {
|
|
18
|
+
const [mounted, setMounted] = useState2(false);
|
|
19
|
+
useEffect2(() => {
|
|
20
|
+
setMounted(true);
|
|
21
|
+
}, []);
|
|
22
|
+
return { mounted };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
useMediaQuery,
|
|
27
|
+
useMounted
|
|
28
|
+
};
|
package/dist/cn.d.ts
ADDED
package/dist/cn.js
ADDED
package/dist/gravity.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -1,14 +1,267 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
buildFlagSearchParamHref,
|
|
4
|
+
hasFlagSearchParam,
|
|
5
|
+
searchParamKeys,
|
|
6
|
+
searchParams
|
|
7
|
+
} from "../chunk-BDQJCK4S.js";
|
|
8
|
+
import {
|
|
5
9
|
useMediaQuery,
|
|
6
|
-
useMounted
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
useMounted
|
|
11
|
+
} from "../chunk-C3RGHTDI.js";
|
|
12
|
+
import {
|
|
13
|
+
isNativeApp
|
|
14
|
+
} from "../chunk-ATPUW3SQ.js";
|
|
15
|
+
|
|
16
|
+
// src/hooks/useNative.ts
|
|
17
|
+
import { useEffect, useState } from "react";
|
|
18
|
+
function useNative() {
|
|
19
|
+
const [native, setNative] = useState(void 0);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setNative(isNativeApp());
|
|
22
|
+
}, []);
|
|
23
|
+
return native;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/hooks/useSearchParams.ts
|
|
27
|
+
import {
|
|
28
|
+
usePathname,
|
|
29
|
+
useRouter,
|
|
30
|
+
useSearchParams as useNextSearchParams
|
|
31
|
+
} from "next/navigation";
|
|
32
|
+
import {
|
|
33
|
+
debounce,
|
|
34
|
+
useQueryStates
|
|
35
|
+
} from "nuqs";
|
|
36
|
+
import { NuqsAdapter } from "nuqs/adapters/next/app";
|
|
37
|
+
import * as React from "react";
|
|
38
|
+
var SEARCH_DELAY = 500;
|
|
39
|
+
var PRODUCT_SEARCH_DELAY = 800;
|
|
40
|
+
function isSearchPath(pathname) {
|
|
41
|
+
return pathname === "/" || pathname === "/pos" || pathname === "/orders" || pathname.startsWith("/pos/") || pathname.startsWith("/orders/");
|
|
42
|
+
}
|
|
43
|
+
var pendingSearchFocus = false;
|
|
44
|
+
function searchFocus() {
|
|
45
|
+
if (!pendingSearchFocus) return false;
|
|
46
|
+
pendingSearchFocus = false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function searchHref(query) {
|
|
50
|
+
const params = new URLSearchParams();
|
|
51
|
+
if (query) params.set(searchParamKeys.query, query);
|
|
52
|
+
const search = params.toString();
|
|
53
|
+
return search ? `/?${search}` : "/";
|
|
54
|
+
}
|
|
55
|
+
function useSearchParams() {
|
|
56
|
+
const pathname = usePathname();
|
|
57
|
+
const router = useRouter();
|
|
58
|
+
const nativeSearchParams = useNextSearchParams();
|
|
59
|
+
const [isPending, startTransition] = React.useTransition();
|
|
60
|
+
const [params, setParams] = useQueryStates(searchParams, {
|
|
61
|
+
urlKeys: searchParamKeys,
|
|
62
|
+
history: "replace",
|
|
63
|
+
shallow: false,
|
|
64
|
+
scroll: false,
|
|
65
|
+
startTransition
|
|
66
|
+
});
|
|
67
|
+
const productQueryRef = React.useRef(params.query);
|
|
68
|
+
const productNavigationQueuedRef = React.useRef(false);
|
|
69
|
+
const onSearchPath = isSearchPath(pathname);
|
|
70
|
+
const cart = hasFlagSearchParam(nativeSearchParams, "cart");
|
|
71
|
+
const notification = hasFlagSearchParam(nativeSearchParams, "notification");
|
|
72
|
+
const updateParams = React.useCallback(
|
|
73
|
+
(values, options) => {
|
|
74
|
+
void setParams(values, options);
|
|
75
|
+
},
|
|
76
|
+
[setParams]
|
|
77
|
+
);
|
|
78
|
+
const setQuery = React.useCallback(
|
|
79
|
+
(value) => {
|
|
80
|
+
const update = setParams(
|
|
81
|
+
{ query: value, page: 1 },
|
|
82
|
+
{
|
|
83
|
+
history: "replace",
|
|
84
|
+
scroll: false,
|
|
85
|
+
shallow: !onSearchPath,
|
|
86
|
+
limitUrlUpdates: debounce(
|
|
87
|
+
onSearchPath ? SEARCH_DELAY : PRODUCT_SEARCH_DELAY
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
if (onSearchPath) return;
|
|
92
|
+
productQueryRef.current = value;
|
|
93
|
+
if (productNavigationQueuedRef.current) return;
|
|
94
|
+
productNavigationQueuedRef.current = true;
|
|
95
|
+
void update.then(() => {
|
|
96
|
+
productNavigationQueuedRef.current = false;
|
|
97
|
+
const query = productQueryRef.current.trim();
|
|
98
|
+
if (!query) return;
|
|
99
|
+
pendingSearchFocus = true;
|
|
100
|
+
router.push(searchHref(query), { scroll: true });
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
[onSearchPath, router, setParams]
|
|
104
|
+
);
|
|
105
|
+
const commitQuery = React.useCallback(() => {
|
|
106
|
+
const query = params.query.trim();
|
|
107
|
+
if (!query || onSearchPath) return;
|
|
108
|
+
pendingSearchFocus = true;
|
|
109
|
+
router.push(searchHref(query), { scroll: true });
|
|
110
|
+
}, [onSearchPath, params.query, router]);
|
|
111
|
+
const setCategory = React.useCallback(
|
|
112
|
+
(value) => {
|
|
113
|
+
updateParams(
|
|
114
|
+
{ category: value, page: 1 },
|
|
115
|
+
{ history: "push", shallow: false, scroll: true }
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
[updateParams]
|
|
119
|
+
);
|
|
120
|
+
const setProductStatus = React.useCallback(
|
|
121
|
+
(value) => {
|
|
122
|
+
updateParams(
|
|
123
|
+
{ productStatus: value, page: 1 },
|
|
124
|
+
{ history: "push", shallow: false, scroll: true }
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
[updateParams]
|
|
128
|
+
);
|
|
129
|
+
const setUser = React.useCallback(
|
|
130
|
+
(value) => {
|
|
131
|
+
updateParams(
|
|
132
|
+
{ user: value },
|
|
133
|
+
{
|
|
134
|
+
history: "replace",
|
|
135
|
+
shallow: false,
|
|
136
|
+
scroll: false,
|
|
137
|
+
limitUrlUpdates: debounce(SEARCH_DELAY)
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
[updateParams]
|
|
142
|
+
);
|
|
143
|
+
const setPage = React.useCallback(
|
|
144
|
+
(value) => {
|
|
145
|
+
updateParams(
|
|
146
|
+
{ page: value },
|
|
147
|
+
{ history: "replace", shallow: true, scroll: false }
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
[updateParams]
|
|
151
|
+
);
|
|
152
|
+
const setUserTransaction = React.useCallback(
|
|
153
|
+
(value) => {
|
|
154
|
+
updateParams(
|
|
155
|
+
{ user: value, transaction: "", transactionPage: 1 },
|
|
156
|
+
{ history: "replace", shallow: false, scroll: false }
|
|
157
|
+
);
|
|
158
|
+
},
|
|
159
|
+
[updateParams]
|
|
160
|
+
);
|
|
161
|
+
const setTransactionDetail = React.useCallback(
|
|
162
|
+
(value) => {
|
|
163
|
+
updateParams(
|
|
164
|
+
{ transaction: value },
|
|
165
|
+
{ history: "replace", shallow: false, scroll: false }
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
[updateParams]
|
|
169
|
+
);
|
|
170
|
+
const clearTransactionDetail = React.useCallback(() => {
|
|
171
|
+
updateParams(
|
|
172
|
+
{ transaction: "" },
|
|
173
|
+
{ history: "replace", shallow: false, scroll: false }
|
|
174
|
+
);
|
|
175
|
+
}, [updateParams]);
|
|
176
|
+
const clearUserTransaction = React.useCallback(() => {
|
|
177
|
+
updateParams(
|
|
178
|
+
{ user: "", transaction: "", transactionPage: 1 },
|
|
179
|
+
{ history: "replace", shallow: false, scroll: false }
|
|
180
|
+
);
|
|
181
|
+
}, [updateParams]);
|
|
182
|
+
const clearAll = React.useCallback(() => {
|
|
183
|
+
updateParams(
|
|
184
|
+
{
|
|
185
|
+
query: "",
|
|
186
|
+
category: "",
|
|
187
|
+
productStatus: "active",
|
|
188
|
+
user: "",
|
|
189
|
+
transaction: "",
|
|
190
|
+
page: 1,
|
|
191
|
+
transactionPage: 1
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
history: "replace",
|
|
195
|
+
shallow: false,
|
|
196
|
+
scroll: true
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}, [updateParams]);
|
|
200
|
+
const setCart = React.useCallback(
|
|
201
|
+
(value) => {
|
|
202
|
+
window.history.replaceState(
|
|
203
|
+
null,
|
|
204
|
+
"",
|
|
205
|
+
buildFlagSearchParamHref(pathname, nativeSearchParams, "cart", value)
|
|
206
|
+
);
|
|
207
|
+
},
|
|
208
|
+
[nativeSearchParams, pathname]
|
|
209
|
+
);
|
|
210
|
+
const toggleCart = React.useCallback(() => {
|
|
211
|
+
setCart(!cart);
|
|
212
|
+
}, [cart, setCart]);
|
|
213
|
+
const setNotification = React.useCallback(
|
|
214
|
+
(value) => {
|
|
215
|
+
window.history.replaceState(
|
|
216
|
+
null,
|
|
217
|
+
"",
|
|
218
|
+
buildFlagSearchParamHref(
|
|
219
|
+
pathname,
|
|
220
|
+
nativeSearchParams,
|
|
221
|
+
"notification",
|
|
222
|
+
value
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
},
|
|
226
|
+
[nativeSearchParams, pathname]
|
|
227
|
+
);
|
|
228
|
+
return {
|
|
229
|
+
...params,
|
|
230
|
+
cart,
|
|
231
|
+
setCart,
|
|
232
|
+
openCart: () => setCart(true),
|
|
233
|
+
closeCart: () => setCart(false),
|
|
234
|
+
toggleCart,
|
|
235
|
+
notification,
|
|
236
|
+
setNotification,
|
|
237
|
+
openNotification: () => setNotification(true),
|
|
238
|
+
closeNotification: () => setNotification(false),
|
|
239
|
+
toggleNotification: () => setNotification(!notification),
|
|
240
|
+
setQuery,
|
|
241
|
+
setCategory,
|
|
242
|
+
setProductStatus,
|
|
243
|
+
setUser,
|
|
244
|
+
setPage,
|
|
245
|
+
setUserTransaction,
|
|
246
|
+
setTransactionDetail,
|
|
247
|
+
commitQuery,
|
|
248
|
+
clearQuery: () => setQuery(""),
|
|
249
|
+
clearCategory: () => setCategory(""),
|
|
250
|
+
clearProductStatus: () => setProductStatus("active"),
|
|
251
|
+
clearUser: () => setUser(""),
|
|
252
|
+
clearTransactionDetail,
|
|
253
|
+
clearUserTransaction,
|
|
254
|
+
clearPage: () => setPage(1),
|
|
255
|
+
clearAll,
|
|
256
|
+
isQueryPending: isPending,
|
|
257
|
+
isCategoryPending: isPending,
|
|
258
|
+
isUserPending: isPending,
|
|
259
|
+
setTab: (value) => updateParams(
|
|
260
|
+
{ tab: value },
|
|
261
|
+
{ history: "replace", shallow: false, scroll: false }
|
|
262
|
+
)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
12
265
|
export {
|
|
13
266
|
NuqsAdapter,
|
|
14
267
|
searchFocus,
|
package/dist/ui/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rockin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Shared React UI components, icons, hooks, utilities, and styles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"import": "./dist/index.js"
|
|
24
24
|
},
|
|
25
|
+
"./cn": {
|
|
26
|
+
"types": "./dist/cn.d.ts",
|
|
27
|
+
"import": "./dist/cn.js"
|
|
28
|
+
},
|
|
25
29
|
"./lucide": {
|
|
26
30
|
"types": "./dist/lucide.d.ts",
|
|
27
31
|
"import": "./dist/lucide.js"
|
package/dist/chunk-TDCUCL6G.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildFlagSearchParamHref,
|
|
3
|
-
hasFlagSearchParam,
|
|
4
|
-
searchParamKeys,
|
|
5
|
-
searchParams
|
|
6
|
-
} from "./chunk-BDQJCK4S.js";
|
|
7
|
-
import {
|
|
8
|
-
isNativeApp
|
|
9
|
-
} from "./chunk-ATPUW3SQ.js";
|
|
10
|
-
|
|
11
|
-
// src/hooks/useMediaQuery.ts
|
|
12
|
-
import { useEffect, useState } from "react";
|
|
13
|
-
function useMediaQuery(query) {
|
|
14
|
-
const [matches, setMatches] = useState(false);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const mediaQuery = window.matchMedia(query);
|
|
17
|
-
const handleChange = () => setMatches(mediaQuery.matches);
|
|
18
|
-
handleChange();
|
|
19
|
-
mediaQuery.addEventListener("change", handleChange);
|
|
20
|
-
return () => mediaQuery.removeEventListener("change", handleChange);
|
|
21
|
-
}, [query]);
|
|
22
|
-
return matches;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/hooks/useMounted.ts
|
|
26
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
27
|
-
function useMounted() {
|
|
28
|
-
const [mounted, setMounted] = useState2(false);
|
|
29
|
-
useEffect2(() => {
|
|
30
|
-
setMounted(true);
|
|
31
|
-
}, []);
|
|
32
|
-
return { mounted };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/hooks/useNative.ts
|
|
36
|
-
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
37
|
-
function useNative() {
|
|
38
|
-
const [native, setNative] = useState3(void 0);
|
|
39
|
-
useEffect3(() => {
|
|
40
|
-
setNative(isNativeApp());
|
|
41
|
-
}, []);
|
|
42
|
-
return native;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/hooks/useSearchParams.ts
|
|
46
|
-
import {
|
|
47
|
-
usePathname,
|
|
48
|
-
useRouter,
|
|
49
|
-
useSearchParams as useNextSearchParams
|
|
50
|
-
} from "next/navigation";
|
|
51
|
-
import {
|
|
52
|
-
debounce,
|
|
53
|
-
useQueryStates
|
|
54
|
-
} from "nuqs";
|
|
55
|
-
import { NuqsAdapter } from "nuqs/adapters/next/app";
|
|
56
|
-
import * as React from "react";
|
|
57
|
-
var SEARCH_DELAY = 500;
|
|
58
|
-
var PRODUCT_SEARCH_DELAY = 800;
|
|
59
|
-
function isSearchPath(pathname) {
|
|
60
|
-
return pathname === "/" || pathname === "/pos" || pathname === "/orders" || pathname.startsWith("/pos/") || pathname.startsWith("/orders/");
|
|
61
|
-
}
|
|
62
|
-
var pendingSearchFocus = false;
|
|
63
|
-
function searchFocus() {
|
|
64
|
-
if (!pendingSearchFocus) return false;
|
|
65
|
-
pendingSearchFocus = false;
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
function searchHref(query) {
|
|
69
|
-
const params = new URLSearchParams();
|
|
70
|
-
if (query) params.set(searchParamKeys.query, query);
|
|
71
|
-
const search = params.toString();
|
|
72
|
-
return search ? `/?${search}` : "/";
|
|
73
|
-
}
|
|
74
|
-
function useSearchParams() {
|
|
75
|
-
const pathname = usePathname();
|
|
76
|
-
const router = useRouter();
|
|
77
|
-
const nativeSearchParams = useNextSearchParams();
|
|
78
|
-
const [isPending, startTransition] = React.useTransition();
|
|
79
|
-
const [params, setParams] = useQueryStates(searchParams, {
|
|
80
|
-
urlKeys: searchParamKeys,
|
|
81
|
-
history: "replace",
|
|
82
|
-
shallow: false,
|
|
83
|
-
scroll: false,
|
|
84
|
-
startTransition
|
|
85
|
-
});
|
|
86
|
-
const productQueryRef = React.useRef(params.query);
|
|
87
|
-
const productNavigationQueuedRef = React.useRef(false);
|
|
88
|
-
const onSearchPath = isSearchPath(pathname);
|
|
89
|
-
const cart = hasFlagSearchParam(nativeSearchParams, "cart");
|
|
90
|
-
const notification = hasFlagSearchParam(nativeSearchParams, "notification");
|
|
91
|
-
const updateParams = React.useCallback(
|
|
92
|
-
(values, options) => {
|
|
93
|
-
void setParams(values, options);
|
|
94
|
-
},
|
|
95
|
-
[setParams]
|
|
96
|
-
);
|
|
97
|
-
const setQuery = React.useCallback(
|
|
98
|
-
(value) => {
|
|
99
|
-
const update = setParams(
|
|
100
|
-
{ query: value, page: 1 },
|
|
101
|
-
{
|
|
102
|
-
history: "replace",
|
|
103
|
-
scroll: false,
|
|
104
|
-
shallow: !onSearchPath,
|
|
105
|
-
limitUrlUpdates: debounce(
|
|
106
|
-
onSearchPath ? SEARCH_DELAY : PRODUCT_SEARCH_DELAY
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
if (onSearchPath) return;
|
|
111
|
-
productQueryRef.current = value;
|
|
112
|
-
if (productNavigationQueuedRef.current) return;
|
|
113
|
-
productNavigationQueuedRef.current = true;
|
|
114
|
-
void update.then(() => {
|
|
115
|
-
productNavigationQueuedRef.current = false;
|
|
116
|
-
const query = productQueryRef.current.trim();
|
|
117
|
-
if (!query) return;
|
|
118
|
-
pendingSearchFocus = true;
|
|
119
|
-
router.push(searchHref(query), { scroll: true });
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
[onSearchPath, router, setParams]
|
|
123
|
-
);
|
|
124
|
-
const commitQuery = React.useCallback(() => {
|
|
125
|
-
const query = params.query.trim();
|
|
126
|
-
if (!query || onSearchPath) return;
|
|
127
|
-
pendingSearchFocus = true;
|
|
128
|
-
router.push(searchHref(query), { scroll: true });
|
|
129
|
-
}, [onSearchPath, params.query, router]);
|
|
130
|
-
const setCategory = React.useCallback(
|
|
131
|
-
(value) => {
|
|
132
|
-
updateParams(
|
|
133
|
-
{ category: value, page: 1 },
|
|
134
|
-
{ history: "push", shallow: false, scroll: true }
|
|
135
|
-
);
|
|
136
|
-
},
|
|
137
|
-
[updateParams]
|
|
138
|
-
);
|
|
139
|
-
const setProductStatus = React.useCallback(
|
|
140
|
-
(value) => {
|
|
141
|
-
updateParams(
|
|
142
|
-
{ productStatus: value, page: 1 },
|
|
143
|
-
{ history: "push", shallow: false, scroll: true }
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
[updateParams]
|
|
147
|
-
);
|
|
148
|
-
const setUser = React.useCallback(
|
|
149
|
-
(value) => {
|
|
150
|
-
updateParams(
|
|
151
|
-
{ user: value },
|
|
152
|
-
{
|
|
153
|
-
history: "replace",
|
|
154
|
-
shallow: false,
|
|
155
|
-
scroll: false,
|
|
156
|
-
limitUrlUpdates: debounce(SEARCH_DELAY)
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
[updateParams]
|
|
161
|
-
);
|
|
162
|
-
const setPage = React.useCallback(
|
|
163
|
-
(value) => {
|
|
164
|
-
updateParams(
|
|
165
|
-
{ page: value },
|
|
166
|
-
{ history: "replace", shallow: true, scroll: false }
|
|
167
|
-
);
|
|
168
|
-
},
|
|
169
|
-
[updateParams]
|
|
170
|
-
);
|
|
171
|
-
const setUserTransaction = React.useCallback(
|
|
172
|
-
(value) => {
|
|
173
|
-
updateParams(
|
|
174
|
-
{ user: value, transaction: "", transactionPage: 1 },
|
|
175
|
-
{ history: "replace", shallow: false, scroll: false }
|
|
176
|
-
);
|
|
177
|
-
},
|
|
178
|
-
[updateParams]
|
|
179
|
-
);
|
|
180
|
-
const setTransactionDetail = React.useCallback(
|
|
181
|
-
(value) => {
|
|
182
|
-
updateParams(
|
|
183
|
-
{ transaction: value },
|
|
184
|
-
{ history: "replace", shallow: false, scroll: false }
|
|
185
|
-
);
|
|
186
|
-
},
|
|
187
|
-
[updateParams]
|
|
188
|
-
);
|
|
189
|
-
const clearTransactionDetail = React.useCallback(() => {
|
|
190
|
-
updateParams(
|
|
191
|
-
{ transaction: "" },
|
|
192
|
-
{ history: "replace", shallow: false, scroll: false }
|
|
193
|
-
);
|
|
194
|
-
}, [updateParams]);
|
|
195
|
-
const clearUserTransaction = React.useCallback(() => {
|
|
196
|
-
updateParams(
|
|
197
|
-
{ user: "", transaction: "", transactionPage: 1 },
|
|
198
|
-
{ history: "replace", shallow: false, scroll: false }
|
|
199
|
-
);
|
|
200
|
-
}, [updateParams]);
|
|
201
|
-
const clearAll = React.useCallback(() => {
|
|
202
|
-
updateParams(
|
|
203
|
-
{
|
|
204
|
-
query: "",
|
|
205
|
-
category: "",
|
|
206
|
-
productStatus: "active",
|
|
207
|
-
user: "",
|
|
208
|
-
transaction: "",
|
|
209
|
-
page: 1,
|
|
210
|
-
transactionPage: 1
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
history: "replace",
|
|
214
|
-
shallow: false,
|
|
215
|
-
scroll: true
|
|
216
|
-
}
|
|
217
|
-
);
|
|
218
|
-
}, [updateParams]);
|
|
219
|
-
const setCart = React.useCallback(
|
|
220
|
-
(value) => {
|
|
221
|
-
window.history.replaceState(
|
|
222
|
-
null,
|
|
223
|
-
"",
|
|
224
|
-
buildFlagSearchParamHref(pathname, nativeSearchParams, "cart", value)
|
|
225
|
-
);
|
|
226
|
-
},
|
|
227
|
-
[nativeSearchParams, pathname]
|
|
228
|
-
);
|
|
229
|
-
const toggleCart = React.useCallback(() => {
|
|
230
|
-
setCart(!cart);
|
|
231
|
-
}, [cart, setCart]);
|
|
232
|
-
const setNotification = React.useCallback(
|
|
233
|
-
(value) => {
|
|
234
|
-
window.history.replaceState(
|
|
235
|
-
null,
|
|
236
|
-
"",
|
|
237
|
-
buildFlagSearchParamHref(
|
|
238
|
-
pathname,
|
|
239
|
-
nativeSearchParams,
|
|
240
|
-
"notification",
|
|
241
|
-
value
|
|
242
|
-
)
|
|
243
|
-
);
|
|
244
|
-
},
|
|
245
|
-
[nativeSearchParams, pathname]
|
|
246
|
-
);
|
|
247
|
-
return {
|
|
248
|
-
...params,
|
|
249
|
-
cart,
|
|
250
|
-
setCart,
|
|
251
|
-
openCart: () => setCart(true),
|
|
252
|
-
closeCart: () => setCart(false),
|
|
253
|
-
toggleCart,
|
|
254
|
-
notification,
|
|
255
|
-
setNotification,
|
|
256
|
-
openNotification: () => setNotification(true),
|
|
257
|
-
closeNotification: () => setNotification(false),
|
|
258
|
-
toggleNotification: () => setNotification(!notification),
|
|
259
|
-
setQuery,
|
|
260
|
-
setCategory,
|
|
261
|
-
setProductStatus,
|
|
262
|
-
setUser,
|
|
263
|
-
setPage,
|
|
264
|
-
setUserTransaction,
|
|
265
|
-
setTransactionDetail,
|
|
266
|
-
commitQuery,
|
|
267
|
-
clearQuery: () => setQuery(""),
|
|
268
|
-
clearCategory: () => setCategory(""),
|
|
269
|
-
clearProductStatus: () => setProductStatus("active"),
|
|
270
|
-
clearUser: () => setUser(""),
|
|
271
|
-
clearTransactionDetail,
|
|
272
|
-
clearUserTransaction,
|
|
273
|
-
clearPage: () => setPage(1),
|
|
274
|
-
clearAll,
|
|
275
|
-
isQueryPending: isPending,
|
|
276
|
-
isCategoryPending: isPending,
|
|
277
|
-
isUserPending: isPending,
|
|
278
|
-
setTab: (value) => updateParams(
|
|
279
|
-
{ tab: value },
|
|
280
|
-
{ history: "replace", shallow: false, scroll: false }
|
|
281
|
-
)
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export {
|
|
286
|
-
useMediaQuery,
|
|
287
|
-
useMounted,
|
|
288
|
-
useNative,
|
|
289
|
-
NuqsAdapter,
|
|
290
|
-
searchFocus,
|
|
291
|
-
useSearchParams
|
|
292
|
-
};
|