nextemos 4.0.7 → 4.0.8
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/dist/config.d.ts +16 -0
- package/dist/config.js +37 -0
- package/dist/{helpers → src/helpers}/cdn.js +8 -8
- package/dist/{helpers → src/helpers}/fetchRequest.js +4 -3
- package/dist/{index.d.ts → src/index.d.ts} +1 -1
- package/dist/{index.js → src/index.js} +1 -1
- package/package.json +4 -10
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.js +0 -13
- package/dist/hooks/useFetch.d.ts +0 -24
- package/dist/hooks/useFetch.js +0 -88
- package/dist/hooks/useLocalStorage.d.ts +0 -9
- package/dist/hooks/useLocalStorage.js +0 -48
- package/dist/hooks/useMediaQuery.d.ts +0 -37
- package/dist/hooks/useMediaQuery.js +0 -71
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -18
- /package/dist/{enums → src/enums}/addressPartTypeId.d.ts +0 -0
- /package/dist/{enums → src/enums}/addressPartTypeId.js +0 -0
- /package/dist/{enums → src/enums}/httpMethods.d.ts +0 -0
- /package/dist/{enums → src/enums}/httpMethods.js +0 -0
- /package/dist/{enums → src/enums}/httpStatusCode.d.ts +0 -0
- /package/dist/{enums → src/enums}/httpStatusCode.js +0 -0
- /package/dist/{enums → src/enums}/index.d.ts +0 -0
- /package/dist/{enums → src/enums}/index.js +0 -0
- /package/dist/{enums → src/enums}/productDocumentTypes.d.ts +0 -0
- /package/dist/{enums → src/enums}/productDocumentTypes.js +0 -0
- /package/dist/{enums → src/enums}/productFlags.d.ts +0 -0
- /package/dist/{enums → src/enums}/productFlags.js +0 -0
- /package/dist/{enums → src/enums}/scopeTypes.d.ts +0 -0
- /package/dist/{enums → src/enums}/scopeTypes.js +0 -0
- /package/dist/{helpers → src/helpers}/cdn.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/decodeHTML.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/decodeHTML.js +0 -0
- /package/dist/{helpers → src/helpers}/fetchRequest.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/index.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/index.js +0 -0
- /package/dist/{helpers → src/helpers}/toIntArray.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/toIntArray.js +0 -0
- /package/dist/{helpers → src/helpers}/toQueryString.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/toQueryString.js +0 -0
- /package/dist/{interfaces → src/interfaces}/address.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/address.js +0 -0
- /package/dist/{interfaces → src/interfaces}/banner.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/banner.js +0 -0
- /package/dist/{interfaces → src/interfaces}/blog.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/blog.js +0 -0
- /package/dist/{interfaces → src/interfaces}/elements.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/elements.js +0 -0
- /package/dist/{interfaces → src/interfaces}/environment.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/environment.js +0 -0
- /package/dist/{interfaces → src/interfaces}/index.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/index.js +0 -0
- /package/dist/{interfaces → src/interfaces}/keycloack.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/keycloack.js +0 -0
- /package/dist/{interfaces → src/interfaces}/localization.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/localization.js +0 -0
- /package/dist/{interfaces → src/interfaces}/member.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/member.js +0 -0
- /package/dist/{interfaces → src/interfaces}/prediction.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/prediction.js +0 -0
- /package/dist/{interfaces → src/interfaces}/product.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/product.js +0 -0
- /package/dist/{interfaces → src/interfaces}/response.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/response.js +0 -0
- /package/dist/{interfaces → src/interfaces}/route.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/route.js +0 -0
- /package/dist/{interfaces → src/interfaces}/stock.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/stock.js +0 -0
- /package/dist/{services → src/services}/address/address.types.d.ts +0 -0
- /package/dist/{services → src/services}/address/address.types.js +0 -0
- /package/dist/{services → src/services}/address/index.d.ts +0 -0
- /package/dist/{services → src/services}/address/index.js +0 -0
- /package/dist/{services → src/services}/banner/banner.types.d.ts +0 -0
- /package/dist/{services → src/services}/banner/banner.types.js +0 -0
- /package/dist/{services → src/services}/banner/index.d.ts +0 -0
- /package/dist/{services → src/services}/banner/index.js +0 -0
- /package/dist/{services → src/services}/blog/blog.types.d.ts +0 -0
- /package/dist/{services → src/services}/blog/blog.types.js +0 -0
- /package/dist/{services → src/services}/blog/index.d.ts +0 -0
- /package/dist/{services → src/services}/blog/index.js +0 -0
- /package/dist/{services → src/services}/environment/environment.types.d.ts +0 -0
- /package/dist/{services → src/services}/environment/environment.types.js +0 -0
- /package/dist/{services → src/services}/environment/index.d.ts +0 -0
- /package/dist/{services → src/services}/environment/index.js +0 -0
- /package/dist/{services → src/services}/index.d.ts +0 -0
- /package/dist/{services → src/services}/index.js +0 -0
- /package/dist/{services → src/services}/keycloak/index.d.ts +0 -0
- /package/dist/{services → src/services}/keycloak/index.js +0 -0
- /package/dist/{services → src/services}/keycloak/keycloak.types.d.ts +0 -0
- /package/dist/{services → src/services}/keycloak/keycloak.types.js +0 -0
- /package/dist/{services → src/services}/localization/index.d.ts +0 -0
- /package/dist/{services → src/services}/localization/index.js +0 -0
- /package/dist/{services → src/services}/localization/localization.types.d.ts +0 -0
- /package/dist/{services → src/services}/localization/localization.types.js +0 -0
- /package/dist/{services → src/services}/member/index.d.ts +0 -0
- /package/dist/{services → src/services}/member/index.js +0 -0
- /package/dist/{services → src/services}/member/member.types.d.ts +0 -0
- /package/dist/{services → src/services}/member/member.types.js +0 -0
- /package/dist/{services → src/services}/prediction/index.d.ts +0 -0
- /package/dist/{services → src/services}/prediction/index.js +0 -0
- /package/dist/{services → src/services}/prediction/prediction.types.d.ts +0 -0
- /package/dist/{services → src/services}/prediction/prediction.types.js +0 -0
- /package/dist/{services → src/services}/product/index.d.ts +0 -0
- /package/dist/{services → src/services}/product/index.js +0 -0
- /package/dist/{services → src/services}/product/product.types.d.ts +0 -0
- /package/dist/{services → src/services}/product/product.types.js +0 -0
- /package/dist/{services → src/services}/route/index.d.ts +0 -0
- /package/dist/{services → src/services}/route/index.js +0 -0
- /package/dist/{services → src/services}/route/route.types.d.ts +0 -0
- /package/dist/{services → src/services}/route/route.types.js +0 -0
- /package/dist/{services → src/services}/stock/index.d.ts +0 -0
- /package/dist/{services → src/services}/stock/index.js +0 -0
- /package/dist/{services → src/services}/stock/stock.types.d.ts +0 -0
- /package/dist/{services → src/services}/stock/stock.types.js +0 -0
- /package/dist/{services → src/services}/urls.d.ts +0 -0
- /package/dist/{services → src/services}/urls.js +0 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface IConfig {
|
|
2
|
+
cacheStrategy: "default" | "no-store" | "no-cache" | "force-cache" | "reload" | "only-if-cached";
|
|
3
|
+
apiUrl: string | null;
|
|
4
|
+
cdnUrl: string;
|
|
5
|
+
videoCdnUrl: string | null;
|
|
6
|
+
cdnProvider: string | null;
|
|
7
|
+
thumborSource: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const getConfig: () => {
|
|
10
|
+
cacheStrategy: "default" | "no-store" | "no-cache" | "force-cache" | "reload" | "only-if-cached";
|
|
11
|
+
apiUrl: string | null;
|
|
12
|
+
cdnUrl: string;
|
|
13
|
+
videoCdnUrl: string | null;
|
|
14
|
+
cdnProvider: string | null;
|
|
15
|
+
thumborSource: string | null;
|
|
16
|
+
};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfig = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const rc_config_loader_1 = require("rc-config-loader");
|
|
6
|
+
const defaultConfigs = {
|
|
7
|
+
"cacheStrategy": "no-store",
|
|
8
|
+
"apiUrl": null,
|
|
9
|
+
"cdnUrl": "https://images.proj-e.com",
|
|
10
|
+
"videoCdnUrl": null,
|
|
11
|
+
"cdnProvider": "medianova",
|
|
12
|
+
"thumborSource": null
|
|
13
|
+
};
|
|
14
|
+
function loadRcFile() {
|
|
15
|
+
try {
|
|
16
|
+
const results = (0, rc_config_loader_1.rcFile)("nextemos", {
|
|
17
|
+
configFileName: (0, path_1.join)(process.cwd(), '.nextemosrc')
|
|
18
|
+
});
|
|
19
|
+
// Not Found
|
|
20
|
+
if (!results) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return results.config;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.log("ERRRR!!!!❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌", error);
|
|
27
|
+
// Found it, but it is parsing error
|
|
28
|
+
return {}; // default value
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Config'i döndür
|
|
32
|
+
const getConfig = () => {
|
|
33
|
+
// load config
|
|
34
|
+
const config = loadRcFile();
|
|
35
|
+
return Object.assign(Object.assign({}, defaultConfigs), config);
|
|
36
|
+
};
|
|
37
|
+
exports.getConfig = getConfig;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("config");
|
|
3
4
|
const html_entities_1 = require("html-entities");
|
|
4
|
-
|
|
5
|
-
const CDN_URL = process.env.CDN_URL ||
|
|
6
|
-
const VIDEO_CDN_URL = process.env.VIDEO_CDN_URL || CDN_URL;
|
|
7
|
-
|
|
8
|
-
const
|
|
5
|
+
const { cdnUrl, cdnProvider, videoCdnUrl, thumborSource } = (0, config_1.getConfig)();
|
|
6
|
+
const CDN_URL = process.env.CDN_URL || cdnUrl;
|
|
7
|
+
const VIDEO_CDN_URL = process.env.VIDEO_CDN_URL || videoCdnUrl || CDN_URL;
|
|
8
|
+
const CDN_PROVIDER = process.env.CDN_PROVIDER || cdnProvider;
|
|
9
|
+
const THUMBOR_SOURCE = process.env.THUMBOR_SOURCE || thumborSource;
|
|
9
10
|
// CDN işlemleri için kullanılan nesne
|
|
10
11
|
const cdn = {
|
|
11
12
|
// CDN URL'sini döndüren özellik
|
|
@@ -93,9 +94,8 @@ const thumborImageProcessor = (props) => {
|
|
|
93
94
|
// Filtreler birleştirilerek URL'ye ekleniyor
|
|
94
95
|
thumbUrl.push(filters.join(''));
|
|
95
96
|
// Ortam değişkeninden Thumbor kaynağı alınıyor, eğer tanımlıysa URL'ye ekleniyor
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
thumbUrl.push(source);
|
|
97
|
+
if (THUMBOR_SOURCE)
|
|
98
|
+
thumbUrl.push(THUMBOR_SOURCE);
|
|
99
99
|
// Görüntü yolu ekleniyor
|
|
100
100
|
thumbUrl.push(encodeURI((0, html_entities_1.decode)(props.path)));
|
|
101
101
|
// Sonuç olarak oluşturulan URL döndürülüyor
|
|
@@ -34,14 +34,16 @@ const fetchRequest = () => {
|
|
|
34
34
|
*/
|
|
35
35
|
const request = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
36
|
var { url, method, params } = _a, options = __rest(_a, ["url", "method", "params"]);
|
|
37
|
+
const { cacheStrategy } = (0, __1.getConfig)();
|
|
37
38
|
const apiURL = new URL(url);
|
|
38
39
|
if (params)
|
|
39
40
|
Object.keys(params).forEach(key => apiURL.searchParams.append(key, params[key]));
|
|
40
41
|
if (method === __1.HTTPMethod.POST)
|
|
41
42
|
options.headers = Object.assign({ ['Content-Type']: 'application/json' }, options.headers);
|
|
42
|
-
|
|
43
|
+
const requestOptions = Object.assign(Object.assign({ cache: cacheStrategy }, options), { method });
|
|
44
|
+
console.log(`Fetch Request: ${method} - ${apiURL} - ${JSON.stringify(requestOptions)}`);
|
|
43
45
|
try {
|
|
44
|
-
const response = yield fetch(apiURL.toString(),
|
|
46
|
+
const response = yield fetch(apiURL.toString(), requestOptions);
|
|
45
47
|
// Headers nesnesini Object'e dönüştürme
|
|
46
48
|
const headers = {};
|
|
47
49
|
if (response === null || response === void 0 ? void 0 : response.headers) {
|
|
@@ -56,7 +58,6 @@ const fetchRequest = () => {
|
|
|
56
58
|
errorMessage: errorDetail,
|
|
57
59
|
headers
|
|
58
60
|
};
|
|
59
|
-
// throw new Error(`Fetch Request HTTP Error: ${response.status} - ${apiURL} - ${errorDetail}`);
|
|
60
61
|
}
|
|
61
62
|
// response data nesnesini JSON'a dönüştürme.
|
|
62
63
|
const responseData = yield response.json().catch(() => ({}));
|
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./helpers"), exports);
|
|
18
|
-
__exportStar(require("./hooks"), exports);
|
|
19
18
|
__exportStar(require("./interfaces"), exports);
|
|
20
19
|
__exportStar(require("./enums"), exports);
|
|
21
20
|
__exportStar(require("./services"), exports);
|
|
21
|
+
__exportStar(require("../config"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextemos",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
4
4
|
"description": "For helpers and hooks used in NextJS projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,26 +26,20 @@
|
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^20.14.2",
|
|
29
|
-
"@types/react": "^18.3.3",
|
|
30
|
-
"react": "^18.3.1",
|
|
31
|
-
"react-dom": "^18.3.1",
|
|
32
29
|
"rimraf": "^5.0.7",
|
|
30
|
+
"ts-node": "^10.9.2",
|
|
33
31
|
"typescript": "^5.4.5"
|
|
34
32
|
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"react": ">=18"
|
|
37
|
-
},
|
|
38
33
|
"repository": {
|
|
39
34
|
"type": "git",
|
|
40
35
|
"url": "git+https://PROJE-INC@dev.azure.com/PROJE-INC/FrontEnd/_git/nextemos"
|
|
41
36
|
},
|
|
42
37
|
"keywords": [
|
|
43
|
-
"react",
|
|
44
|
-
"nextjs",
|
|
45
38
|
"typescript",
|
|
46
39
|
"nextemos"
|
|
47
40
|
],
|
|
48
41
|
"dependencies": {
|
|
49
|
-
"html-entities": "^2.5.2"
|
|
42
|
+
"html-entities": "^2.5.2",
|
|
43
|
+
"rc-config-loader": "^4.1.3"
|
|
50
44
|
}
|
|
51
45
|
}
|
package/dist/hooks/index.d.ts
DELETED
package/dist/hooks/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useMediaQuery = exports.useLocalStorage = exports.useFetch = void 0;
|
|
7
|
-
/// hooks
|
|
8
|
-
var useFetch_1 = require("./useFetch");
|
|
9
|
-
Object.defineProperty(exports, "useFetch", { enumerable: true, get: function () { return __importDefault(useFetch_1).default; } });
|
|
10
|
-
var useLocalStorage_1 = require("./useLocalStorage");
|
|
11
|
-
Object.defineProperty(exports, "useLocalStorage", { enumerable: true, get: function () { return __importDefault(useLocalStorage_1).default; } });
|
|
12
|
-
var useMediaQuery_1 = require("./useMediaQuery");
|
|
13
|
-
Object.defineProperty(exports, "useMediaQuery", { enumerable: true, get: function () { return __importDefault(useMediaQuery_1).default; } });
|
package/dist/hooks/useFetch.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for the fetch props.
|
|
3
|
-
*/
|
|
4
|
-
interface IFetchProps {
|
|
5
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
6
|
-
url: string;
|
|
7
|
-
requestOptions?: RequestInit;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Custom hook for making HTTP requests using the fetch API.
|
|
11
|
-
*
|
|
12
|
-
* @param {IFetchProps} param0 - The fetch props.
|
|
13
|
-
* @returns {Object} - An object containing the response, headers, loading state, error, and refetch function.
|
|
14
|
-
*/
|
|
15
|
-
declare const useFetch: <T>({ method, url, requestOptions }: IFetchProps) => {
|
|
16
|
-
response: T | null;
|
|
17
|
-
loading: boolean;
|
|
18
|
-
error: string | null;
|
|
19
|
-
headers: {
|
|
20
|
-
[key: string]: string;
|
|
21
|
-
};
|
|
22
|
-
refetch: () => void;
|
|
23
|
-
};
|
|
24
|
-
export default useFetch;
|
package/dist/hooks/useFetch.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const react_1 = require("react");
|
|
13
|
-
/**
|
|
14
|
-
* Custom hook for making HTTP requests using the fetch API.
|
|
15
|
-
*
|
|
16
|
-
* @param {IFetchProps} param0 - The fetch props.
|
|
17
|
-
* @returns {Object} - An object containing the response, headers, loading state, error, and refetch function.
|
|
18
|
-
*/
|
|
19
|
-
const useFetch = ({ method = "GET", url, requestOptions = {} }) => {
|
|
20
|
-
// State for storing the response data.
|
|
21
|
-
const [response, setResponse] = (0, react_1.useState)(null);
|
|
22
|
-
// State for tracking the loading state.
|
|
23
|
-
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
24
|
-
// State for storing the error message.
|
|
25
|
-
const [error, setError] = (0, react_1.useState)(null);
|
|
26
|
-
// State for storing the response headers.
|
|
27
|
-
const [headers, setHeader] = (0, react_1.useState)({});
|
|
28
|
-
// State for triggering a refetch.
|
|
29
|
-
const [reload, setReload] = (0, react_1.useState)(0);
|
|
30
|
-
/**
|
|
31
|
-
* Function for triggering a refetch.
|
|
32
|
-
*/
|
|
33
|
-
const refetch = () => setReload((prev) => prev + 1);
|
|
34
|
-
(0, react_1.useEffect)(() => {
|
|
35
|
-
// Create an AbortController instance to cancel the fetch request if needed.
|
|
36
|
-
const controller = new AbortController();
|
|
37
|
-
const signal = controller.signal;
|
|
38
|
-
/**
|
|
39
|
-
* Function for fetching the data.
|
|
40
|
-
*/
|
|
41
|
-
const fetchData = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
setLoading(true);
|
|
43
|
-
try {
|
|
44
|
-
// Make the fetch request with the provided method, URL, and options.
|
|
45
|
-
const res = yield fetch(url, Object.assign(Object.assign({ method: method.toUpperCase() }, requestOptions), { signal }));
|
|
46
|
-
// Check if the response is not OK and throw an error.
|
|
47
|
-
if (!res.ok) {
|
|
48
|
-
throw new Error(`Error: ${res.statusText}`);
|
|
49
|
-
}
|
|
50
|
-
// Parse the response headers as JSON
|
|
51
|
-
const _headers = {};
|
|
52
|
-
res.headers.forEach((value, name) => {
|
|
53
|
-
_headers[name] = value;
|
|
54
|
-
});
|
|
55
|
-
setHeader(_headers);
|
|
56
|
-
// Parse the response data as JSON.
|
|
57
|
-
const data = yield res.json();
|
|
58
|
-
// Update the response state with the fetched data.
|
|
59
|
-
setResponse(data);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
// Handle any errors that occur during the fetch request.
|
|
63
|
-
if (error instanceof Error) {
|
|
64
|
-
setError(error.message);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
setError('An unknown error occurred');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
setLoading(false);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
// Call the fetchData function.
|
|
75
|
-
fetchData();
|
|
76
|
-
// Cleanup function to abort the fetch request if the component unmounts or the dependencies change.
|
|
77
|
-
return () => controller.abort();
|
|
78
|
-
}, [url, reload]);
|
|
79
|
-
// Return the response, loading state, error, and refetch function.
|
|
80
|
-
return {
|
|
81
|
-
response,
|
|
82
|
-
loading,
|
|
83
|
-
error,
|
|
84
|
-
headers,
|
|
85
|
-
refetch
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
exports.default = useFetch;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook that synchronizes state with localStorage.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} key - The key to store the value under in localStorage.
|
|
5
|
-
* @param {any} initialValue - The initial value to use if the key does not exist in localStorage.
|
|
6
|
-
* @returns {[any, function]} - The current value stored in localStorage and a function to update it.
|
|
7
|
-
*/
|
|
8
|
-
declare const useLocalStorage: (key: string, initialValue: any) => any[];
|
|
9
|
-
export default useLocalStorage;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("react");
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook that synchronizes state with localStorage.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} key - The key to store the value under in localStorage.
|
|
8
|
-
* @param {any} initialValue - The initial value to use if the key does not exist in localStorage.
|
|
9
|
-
* @returns {[any, function]} - The current value stored in localStorage and a function to update it.
|
|
10
|
-
*/
|
|
11
|
-
const useLocalStorage = (key, initialValue) => {
|
|
12
|
-
// Initialize the state with a function to read from localStorage or use the initial value
|
|
13
|
-
const [storedValue, setStoredValue] = (0, react_1.useState)(() => {
|
|
14
|
-
try {
|
|
15
|
-
// Attempt to get the item from localStorage using the key
|
|
16
|
-
const item = window.localStorage.getItem(key);
|
|
17
|
-
// If the item exists, parse it from JSON; otherwise, return the initial value
|
|
18
|
-
return item ? JSON.parse(item) : initialValue;
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
// Log any errors and return the initial value
|
|
22
|
-
console.error(error);
|
|
23
|
-
return initialValue;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Function to update the state and localStorage.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} value - The new value to store, or a function that returns the new value.
|
|
30
|
-
*/
|
|
31
|
-
const setValue = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
// Determine the new value to store, supporting functional updates
|
|
34
|
-
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
35
|
-
// Update the state with the new value
|
|
36
|
-
setStoredValue(valueToStore);
|
|
37
|
-
// Store the new value in localStorage as a JSON string
|
|
38
|
-
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
// Log any errors that occur during the update
|
|
42
|
-
console.error(error);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
// Return the current value and the function to update it
|
|
46
|
-
return [storedValue, setValue];
|
|
47
|
-
};
|
|
48
|
-
exports.default = useLocalStorage;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
interface IWindowSize {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* useMediaQuery Hook
|
|
7
|
-
*
|
|
8
|
-
* @description
|
|
9
|
-
* A custom React hook that listens for the window size and checks if it matches a specified media query.
|
|
10
|
-
*
|
|
11
|
-
* This hook is particularly useful in responsive design scenarios where you need to render different components
|
|
12
|
-
* or apply different styles based on the screen size (e.g., mobile vs desktop).
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} options - The options for the hook.
|
|
15
|
-
* @param {string} options.query - The media query string to be matched (e.g., '(max-width: 960px)').
|
|
16
|
-
* If not provided, it defaults to a common mobile screen width.
|
|
17
|
-
*
|
|
18
|
-
* @returns {Object} An object containing:
|
|
19
|
-
* - `width` (number): The current width of the window.
|
|
20
|
-
* - `height` (number): The current height of the window.
|
|
21
|
-
* - `isMobile` (boolean): Whether the screen matches the provided media query (typically for mobile screens).
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { width, height, isMobile } = useMediaQuery({ query: '(max-width: 768px)' });
|
|
25
|
-
*
|
|
26
|
-
* if (isMobile) {
|
|
27
|
-
* // Render mobile-specific component or apply mobile-specific styles
|
|
28
|
-
* } else {
|
|
29
|
-
* // Render desktop-specific component or apply desktop-specific styles
|
|
30
|
-
* }
|
|
31
|
-
*/
|
|
32
|
-
declare const useMediaQuery: ({ query }?: {
|
|
33
|
-
query?: string;
|
|
34
|
-
}) => IWindowSize & {
|
|
35
|
-
isMobile: boolean;
|
|
36
|
-
};
|
|
37
|
-
export default useMediaQuery;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("react");
|
|
4
|
-
/**
|
|
5
|
-
* useMediaQuery Hook
|
|
6
|
-
*
|
|
7
|
-
* @description
|
|
8
|
-
* A custom React hook that listens for the window size and checks if it matches a specified media query.
|
|
9
|
-
*
|
|
10
|
-
* This hook is particularly useful in responsive design scenarios where you need to render different components
|
|
11
|
-
* or apply different styles based on the screen size (e.g., mobile vs desktop).
|
|
12
|
-
*
|
|
13
|
-
* @param {Object} options - The options for the hook.
|
|
14
|
-
* @param {string} options.query - The media query string to be matched (e.g., '(max-width: 960px)').
|
|
15
|
-
* If not provided, it defaults to a common mobile screen width.
|
|
16
|
-
*
|
|
17
|
-
* @returns {Object} An object containing:
|
|
18
|
-
* - `width` (number): The current width of the window.
|
|
19
|
-
* - `height` (number): The current height of the window.
|
|
20
|
-
* - `isMobile` (boolean): Whether the screen matches the provided media query (typically for mobile screens).
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { width, height, isMobile } = useMediaQuery({ query: '(max-width: 768px)' });
|
|
24
|
-
*
|
|
25
|
-
* if (isMobile) {
|
|
26
|
-
* // Render mobile-specific component or apply mobile-specific styles
|
|
27
|
-
* } else {
|
|
28
|
-
* // Render desktop-specific component or apply desktop-specific styles
|
|
29
|
-
* }
|
|
30
|
-
*/
|
|
31
|
-
const useMediaQuery = ({ query = process.env.NEXT_PUBLIC_MAX_MATCHES || '(max-width: 960px)' } = {}) => {
|
|
32
|
-
const [windowSize, setWindowSize] = (0, react_1.useState)({ width: 0, height: 0 });
|
|
33
|
-
const [isMobile, setIsMobile] = (0, react_1.useState)(false);
|
|
34
|
-
/**
|
|
35
|
-
* handleResize
|
|
36
|
-
*
|
|
37
|
-
* @description
|
|
38
|
-
* Updates the window size state when the window is resized.
|
|
39
|
-
*/
|
|
40
|
-
const handleResize = () => {
|
|
41
|
-
const { innerWidth, innerHeight } = window;
|
|
42
|
-
setWindowSize({ width: innerWidth, height: innerHeight });
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* handleChange
|
|
46
|
-
*
|
|
47
|
-
* @description
|
|
48
|
-
* Updates the isMobile state when the media query status changes.
|
|
49
|
-
*/
|
|
50
|
-
const handleChange = (event) => {
|
|
51
|
-
setIsMobile(event.matches);
|
|
52
|
-
};
|
|
53
|
-
(0, react_1.useEffect)(() => {
|
|
54
|
-
if (typeof window !== 'undefined') {
|
|
55
|
-
// Initialize window size and media query match
|
|
56
|
-
handleResize();
|
|
57
|
-
const mediaQuery = window.matchMedia(query);
|
|
58
|
-
setIsMobile(mediaQuery.matches);
|
|
59
|
-
// Add event listeners
|
|
60
|
-
mediaQuery.addEventListener('change', handleChange);
|
|
61
|
-
window.addEventListener('resize', handleResize);
|
|
62
|
-
// Cleanup event listeners on component unmount
|
|
63
|
-
return () => {
|
|
64
|
-
mediaQuery.removeEventListener('change', handleChange);
|
|
65
|
-
window.removeEventListener('resize', handleResize);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}, [query]);
|
|
69
|
-
return Object.assign(Object.assign({}, windowSize), { isMobile });
|
|
70
|
-
};
|
|
71
|
-
exports.default = useMediaQuery;
|
package/dist/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function test(): void;
|
package/dist/test.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = test;
|
|
4
|
-
const hooks_1 = require("./hooks");
|
|
5
|
-
const services_1 = require("./services");
|
|
6
|
-
function test() {
|
|
7
|
-
const res = services_1.Service.Blog.GetBlogCategoryTreeRequest({ categoryId: 11 });
|
|
8
|
-
const resp = (0, hooks_1.useFetch)({
|
|
9
|
-
url: 'https://api.example.com/blog/categories',
|
|
10
|
-
method: 'GET',
|
|
11
|
-
requestOptions: {
|
|
12
|
-
headers: {
|
|
13
|
-
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|