namirasoft-account-react 1.3.15 → 1.3.16

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.
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import { INSARouterProps } from "./INSARouterProps";
3
+ export interface INSARouterMaker {
4
+ on401(): void;
5
+ onRenderOnLogin(props: INSARouterProps): React.JSX.Element;
6
+ onRenderOnLogout(props: INSARouterProps, banned: boolean): React.JSX.Element;
7
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IRouterMaker.js.map
3
+ //# sourceMappingURL=INSARouterMaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"INSARouterMaker.js","sourceRoot":"","sources":["../src/INSARouterMaker.ts"],"names":[],"mappings":""}
@@ -1,13 +1,12 @@
1
1
  import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
- import { Messenger } from "./Messenger";
3
2
  import { ParsedNameValue } from "namirasoft-core";
3
+ import { INSRouterProps } from "namirasoft-site-react";
4
4
  import { ParsedQuery } from "query-string";
5
- export interface IAccountProps {
5
+ export interface INSARouterProps extends INSRouterProps {
6
6
  account: {
7
7
  token_manager: TokenManager;
8
8
  server: NamirasoftAccountServer;
9
9
  };
10
- messenger: Messenger;
11
10
  url: {
12
11
  getQueryStrings(): ParsedQuery;
13
12
  getQuery(name: string): string;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IAccountProps.js.map
3
+ //# sourceMappingURL=INSARouterProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"INSARouterProps.js","sourceRoot":"","sources":["../src/INSARouterProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { INSRouterState } from "namirasoft-site-react";
2
+ export interface INSARouterState extends INSRouterState {
3
+ inited?: boolean;
4
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IRouterState.js.map
3
+ //# sourceMappingURL=INSARouterState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"INSARouterState.js","sourceRoot":"","sources":["../src/INSARouterState.ts"],"names":[],"mappings":""}
@@ -1,16 +1,17 @@
1
1
  /// <reference types="react" />
2
2
  import { ParsedQuery } from 'query-string';
3
3
  import { ParsedNameValue } from "namirasoft-core";
4
- import { IRouterMaker } from "./IRouterMaker";
4
+ import { INSARouterMaker } from "./INSARouterMaker";
5
5
  import rrd from 'react-router-dom';
6
- import { IRouterState } from "./IRouterState";
7
- export declare class RouterMaker {
6
+ import { INSARouterState } from "./INSARouterState";
7
+ export declare class NSARouterMaker {
8
+ private ns_router_maker_props;
8
9
  private state;
9
10
  private setState;
10
11
  private location;
11
12
  private navigate;
12
13
  private component;
13
- constructor(state: IRouterState | undefined, setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>, location: rrd.Location, navigate: rrd.NavigateFunction, component: IRouterMaker);
14
+ constructor(state: INSARouterState | undefined, setState: React.Dispatch<React.SetStateAction<INSARouterState | undefined>>, location: rrd.Location, navigate: rrd.NavigateFunction, component: INSARouterMaker);
14
15
  private init;
15
16
  getQueryStrings(): ParsedQuery;
16
17
  getQuery(name: string): string;
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RouterMaker = void 0;
6
+ exports.NSARouterMaker = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const query_string_1 = __importDefault(require("query-string"));
9
9
  const namirasoft_core_1 = require("namirasoft-core");
10
- const Messenger_1 = require("./Messenger");
11
10
  const namirasoft_account_1 = require("namirasoft-account");
12
11
  const axios_1 = __importDefault(require("axios"));
13
- class RouterMaker {
12
+ const namirasoft_site_react_1 = require("namirasoft-site-react");
13
+ class NSARouterMaker {
14
14
  constructor(state, setState, location, navigate, component) {
15
15
  this.state = state;
16
16
  this.setState = setState;
@@ -27,7 +27,6 @@ class RouterMaker {
27
27
  }
28
28
  init() {
29
29
  var _a, _b;
30
- let messenger = new Messenger_1.Messenger(this.state, this.setState);
31
30
  let qStorage = this.getQuery("location");
32
31
  let qAPI = this.getQuery("api");
33
32
  let qToken = this.getQuery("token");
@@ -51,21 +50,17 @@ class RouterMaker {
51
50
  this.component.on401();
52
51
  return;
53
52
  }
54
- messenger.onError(error);
53
+ this.ns_router_maker_props.notifier.onError(error);
55
54
  });
56
- let props = {
57
- account: {
55
+ let props = Object.assign({ account: {
58
56
  token_manager,
59
57
  server,
60
- },
61
- url: {
58
+ }, url: {
62
59
  getLink: this.getLink,
63
60
  redirect: this.redirect,
64
61
  getQueryStrings: this.getQueryStrings,
65
62
  getQuery: this.getQuery,
66
- },
67
- messenger,
68
- };
63
+ } }, this.ns_router_maker_props);
69
64
  let inited = true;
70
65
  if (qToken)
71
66
  inited = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.inited) !== null && _b !== void 0 ? _b : false;
@@ -108,18 +103,24 @@ class RouterMaker {
108
103
  }
109
104
  }
110
105
  onRender() {
111
- let { inited, props } = this.init();
112
- if (!inited)
113
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
114
- let banned = false;
115
- if (props.account.token_manager.exists()) {
116
- banned = props.account.token_manager.getUserData(user => user.banned, false);
117
- if (!banned)
118
- return this.component.onRenderOnLogin(props);
119
- }
120
- return this.component.onRenderOnLogout(props, banned);
106
+ let maker = new namirasoft_site_react_1.NSRouterMaker(this.state, this.setState, {
107
+ onRender: (ns_router_maker_props) => {
108
+ this.ns_router_maker_props = ns_router_maker_props;
109
+ let { inited, props } = this.init();
110
+ if (!inited)
111
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
112
+ let banned = false;
113
+ if (props.account.token_manager.exists()) {
114
+ banned = props.account.token_manager.getUserData(user => user.banned, false);
115
+ if (!banned)
116
+ return this.component.onRenderOnLogin(props);
117
+ }
118
+ return this.component.onRenderOnLogout(props, banned);
119
+ }
120
+ });
121
+ return maker.onRender();
121
122
  }
122
123
  }
123
- exports.RouterMaker = RouterMaker;
124
+ exports.NSARouterMaker = NSARouterMaker;
124
125
  ;
125
- //# sourceMappingURL=RouterMaker.js.map
126
+ //# sourceMappingURL=NSARouterMaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NSARouterMaker.js","sourceRoot":"","sources":["../src/NSARouterMaker.tsx"],"names":[],"mappings":";;;;;;;AAAA,gEAAwD;AACxD,qDAAwH;AACxH,2DAA2E;AAI3E,kDAA0B;AAE1B,iEAAsE;AAEtE,MAAa,cAAc;IAQvB,YAAY,KAAkC,EAAE,QAA2E,EACvH,QAAsB,EAAE,QAA8B,EACtD,SAA0B;QAE1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,I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,MAAM;oBACP,OAAO,kDAAK,CAAC;gBACjB,IAAI,MAAM,GAAG,KAAK,CAAC;gBACnB,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,EACxC;oBACI,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC7E,IAAI,CAAC,MAAM;wBACP,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;iBACpD;gBACD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC1D,CAAC;SACJ,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;CACJ;AA1ID,wCA0IC;AAAA,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export * from "./IAccountProps";
2
1
  export * from "./Info";
3
- export * from "./IRouterMaker";
4
- export * from "./IRouterState";
5
- export * from "./Messenger";
6
- export * from "./RouterMaker";
2
+ export * from "./INSARouterMaker";
3
+ export * from "./INSARouterProps";
4
+ export * from "./INSARouterState";
5
+ export * from "./NSARouterMaker";
package/dist/index.js CHANGED
@@ -14,10 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./IAccountProps"), exports);
18
17
  __exportStar(require("./Info"), exports);
19
- __exportStar(require("./IRouterMaker"), exports);
20
- __exportStar(require("./IRouterState"), exports);
21
- __exportStar(require("./Messenger"), exports);
22
- __exportStar(require("./RouterMaker"), exports);
18
+ __exportStar(require("./INSARouterMaker"), exports);
19
+ __exportStar(require("./INSARouterProps"), exports);
20
+ __exportStar(require("./INSARouterState"), exports);
21
+ __exportStar(require("./NSARouterMaker"), exports);
23
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,yCAAuB;AACvB,iDAA+B;AAC/B,iDAA+B;AAC/B,8CAA4B;AAC5B,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC;AAClC,mDAAiC"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.3.15",
11
+ "version": "1.3.16",
12
12
  "author": "Amir Abolhasani",
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "device-uuid": "^1.0.4",
23
23
  "namirasoft-account": "^1.3.8",
24
24
  "namirasoft-core": "^1.3.19",
25
- "namirasoft-site-react": "^1.3.66",
25
+ "namirasoft-site-react": "^1.3.68",
26
26
  "query-string": "^9.0.0",
27
27
  "react": "^18.2.0",
28
28
  "react-router-dom": "^6.22.3",
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { INSARouterProps } from "./INSARouterProps";
3
+
4
+ export interface INSARouterMaker
5
+ {
6
+ on401(): void;
7
+ onRenderOnLogin(props: INSARouterProps): React.JSX.Element;
8
+ onRenderOnLogout(props: INSARouterProps, banned: boolean): React.JSX.Element;
9
+ }
@@ -1,15 +1,14 @@
1
1
  import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
- import { Messenger } from "./Messenger";
3
2
  import { ParsedNameValue } from "namirasoft-core";
3
+ import { INSRouterProps } from "namirasoft-site-react";
4
4
  import { ParsedQuery } from "query-string";
5
5
 
6
- export interface IAccountProps
6
+ export interface INSARouterProps extends INSRouterProps
7
7
  {
8
8
  account: {
9
9
  token_manager: TokenManager
10
10
  server: NamirasoftAccountServer;
11
11
  },
12
- messenger: Messenger;
13
12
  url: {
14
13
  getQueryStrings(): ParsedQuery;
15
14
  getQuery(name: string): string;
@@ -0,0 +1,6 @@
1
+ import { INSRouterState } from "namirasoft-site-react";
2
+
3
+ export interface INSARouterState extends INSRouterState
4
+ {
5
+ inited?: boolean;
6
+ }
@@ -1,23 +1,24 @@
1
1
  import queryString, { ParsedQuery } from 'query-string';
2
2
  import { IStorage, IStorageLocal, IStorageMemory, ObjectService, ParsedNameValue, URLOperation } from "namirasoft-core";
3
- import { Messenger } from "./Messenger";
4
3
  import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
5
- import { IAccountProps } from "./IAccountProps";
6
- import { IRouterMaker } from "./IRouterMaker";
4
+ import { INSARouterProps } from "./INSARouterProps";
5
+ import { INSARouterMaker } from "./INSARouterMaker";
7
6
  import rrd from 'react-router-dom';
8
7
  import axios from "axios";
9
- import { IRouterState } from "./IRouterState";
8
+ import { INSARouterState } from "./INSARouterState";
9
+ import { INSRouterProps, NSRouterMaker } from 'namirasoft-site-react';
10
10
 
11
- export class RouterMaker
11
+ export class NSARouterMaker
12
12
  {
13
- private state: IRouterState | undefined;
14
- private setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>;
13
+ private ns_router_maker_props!: INSRouterProps;
14
+ private state: INSARouterState | undefined;
15
+ private setState: React.Dispatch<React.SetStateAction<INSARouterState | undefined>>;
15
16
  private location: rrd.Location;
16
17
  private navigate: rrd.NavigateFunction;
17
- private component: IRouterMaker;
18
- constructor(state: IRouterState | undefined, setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>,
18
+ private component: INSARouterMaker;
19
+ constructor(state: INSARouterState | undefined, setState: React.Dispatch<React.SetStateAction<INSARouterState | undefined>>,
19
20
  location: rrd.Location, navigate: rrd.NavigateFunction,
20
- component: IRouterMaker)
21
+ component: INSARouterMaker)
21
22
  {
22
23
  this.state = state;
23
24
  this.setState = setState;
@@ -32,9 +33,8 @@ export class RouterMaker
32
33
  this.onComponentDidMount = this.onComponentDidMount.bind(this);
33
34
  this.onRender = this.onRender.bind(this);
34
35
  }
35
- private init(): { props: IAccountProps, inited: boolean }
36
+ private init(): { props: INSARouterProps, inited: boolean }
36
37
  {
37
- let messenger: Messenger = new Messenger(this.state, this.setState);
38
38
  let qStorage: string = this.getQuery("location");
39
39
  let qAPI: string = this.getQuery("api");
40
40
  let qToken: string = this.getQuery("token");
@@ -59,9 +59,9 @@ export class RouterMaker
59
59
  this.component.on401();
60
60
  return;
61
61
  }
62
- messenger.onError(error);
62
+ this.ns_router_maker_props.notifier.onError(error);
63
63
  });
64
- let props: IAccountProps = {
64
+ let props: INSARouterProps = {
65
65
  account: {
66
66
  token_manager,
67
67
  server,
@@ -72,7 +72,7 @@ export class RouterMaker
72
72
  getQueryStrings: this.getQueryStrings,
73
73
  getQuery: this.getQuery,
74
74
  },
75
- messenger,
75
+ ...this.ns_router_maker_props
76
76
  };
77
77
  let inited = true;
78
78
  if (qToken)
@@ -126,16 +126,24 @@ export class RouterMaker
126
126
  }
127
127
  onRender(): React.JSX.Element
128
128
  {
129
- let { inited, props } = this.init();
130
- if (!inited)
131
- return <></>;
132
- let banned = false;
133
- if (props.account.token_manager.exists())
134
- {
135
- banned = props.account.token_manager.getUserData(user => user.banned, false);
136
- if (!banned)
137
- return this.component.onRenderOnLogin(props);
138
- }
139
- return this.component.onRenderOnLogout(props, banned);
129
+ let maker = new NSRouterMaker(this.state, this.setState, {
130
+ onRender: (ns_router_maker_props: INSRouterProps) =>
131
+ {
132
+ this.ns_router_maker_props = ns_router_maker_props;
133
+ let { inited, props } = this.init();
134
+ if (!inited)
135
+ return <></>;
136
+ let banned = false;
137
+ if (props.account.token_manager.exists())
138
+ {
139
+ banned = props.account.token_manager.getUserData(user => user.banned, false);
140
+ if (!banned)
141
+ return this.component.onRenderOnLogin(props);
142
+ }
143
+ return this.component.onRenderOnLogout(props, banned);
144
+ }
145
+ });
146
+
147
+ return maker.onRender();
140
148
  }
141
149
  };
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
- export * from "./IAccountProps";
2
1
  export * from "./Info";
3
- export * from "./IRouterMaker";
4
- export * from "./IRouterState";
5
- export * from "./Messenger";
6
- export * from "./RouterMaker";
2
+ export * from "./INSARouterMaker";
3
+ export * from "./INSARouterProps";
4
+ export * from "./INSARouterState";
5
+ export * from "./NSARouterMaker";
@@ -1 +0,0 @@
1
- {"version":3,"file":"IAccountProps.js","sourceRoot":"","sources":["../src/IAccountProps.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- import { IAccountProps } from "./IAccountProps";
3
- export interface IRouterMaker {
4
- on401(): void;
5
- onRenderOnLogin(props: IAccountProps): React.JSX.Element;
6
- onRenderOnLogout(props: IAccountProps, banned: boolean): React.JSX.Element;
7
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRouterMaker.js","sourceRoot":"","sources":["../src/IRouterMaker.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import { NSNotificationProps } from "namirasoft-site-react";
2
- export interface IRouterState {
3
- inited?: boolean;
4
- notifications?: NSNotificationProps[];
5
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRouterState.js","sourceRoot":"","sources":["../src/IRouterState.ts"],"names":[],"mappings":""}
@@ -1,16 +0,0 @@
1
- /// <reference types="react" />
2
- import { IRouterState } from "./IRouterState";
3
- import { NSNotificationProps } from "namirasoft-site-react";
4
- export declare class Messenger {
5
- private static Counter;
6
- private state;
7
- private setState;
8
- constructor(state: IRouterState | undefined, setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>);
9
- private notify;
10
- onInformation(text: string): void;
11
- onSuccess(text: string): void;
12
- onWarning(text: string): void;
13
- onError(error: Error | string): void;
14
- delNotification(id: string): void;
15
- getNotifications(): NSNotificationProps[];
16
- }
package/dist/Messenger.js DELETED
@@ -1,78 +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.Messenger = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const namirasoft_site_react_1 = require("namirasoft-site-react");
9
- class Messenger {
10
- constructor(state, setState) {
11
- this.state = state;
12
- this.setState = setState;
13
- this.notify = this.notify.bind(this);
14
- this.onInformation = this.onInformation.bind(this);
15
- this.onSuccess = this.onSuccess.bind(this);
16
- this.onWarning = this.onWarning.bind(this);
17
- this.onError = this.onError.bind(this);
18
- this.delNotification = this.delNotification.bind(this);
19
- this.getNotifications = this.getNotifications.bind(this);
20
- }
21
- notify(message) {
22
- var _a, _b, _c;
23
- let inited = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.inited) !== null && _b !== void 0 ? _b : false;
24
- let notifications = [];
25
- if ((_c = this.state) === null || _c === void 0 ? void 0 : _c.notifications)
26
- notifications.push(...this.state.notifications);
27
- notifications.push(message);
28
- this.setState({ inited, notifications });
29
- setTimeout(() => {
30
- message.onClose();
31
- }, 5000);
32
- window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
33
- }
34
- onInformation(text) {
35
- let id = Messenger.Counter++ + "";
36
- this.notify({ id, text, type: namirasoft_site_react_1.NotificationType.Information, color: namirasoft_site_react_1.NSNotificationColor.GRAY, onClose: () => this.delNotification(id) });
37
- }
38
- onSuccess(text) {
39
- let id = Messenger.Counter++ + "";
40
- this.notify({ id, text, type: namirasoft_site_react_1.NotificationType.Success, color: namirasoft_site_react_1.NSNotificationColor.GREEN, onClose: () => this.delNotification(id) });
41
- }
42
- onWarning(text) {
43
- let id = Messenger.Counter++ + "";
44
- this.notify({ id, text, type: namirasoft_site_react_1.NotificationType.Warning, color: namirasoft_site_react_1.NSNotificationColor.YELLOW, onClose: () => this.delNotification(id) });
45
- }
46
- onError(error) {
47
- var _a;
48
- let id = Messenger.Counter++ + "";
49
- let text = "";
50
- if (error instanceof Error) {
51
- text = error.message;
52
- if (axios_1.default.isAxiosError(error))
53
- if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)
54
- text = error.response.data;
55
- }
56
- else
57
- text = error;
58
- this.notify({ id, text, type: namirasoft_site_react_1.NotificationType.Error, color: namirasoft_site_react_1.NSNotificationColor.RED, onClose: () => this.delNotification(id) });
59
- }
60
- delNotification(id) {
61
- var _a;
62
- if (!this.state)
63
- return;
64
- let inited = (_a = this.state.inited) !== null && _a !== void 0 ? _a : false;
65
- let notifications = [];
66
- if (this.state.notifications)
67
- notifications.push(...this.state.notifications);
68
- notifications = notifications.filter(x => x.id !== id);
69
- this.setState({ inited, notifications });
70
- }
71
- getNotifications() {
72
- var _a, _b;
73
- return (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a.notifications) !== null && _b !== void 0 ? _b : [];
74
- }
75
- }
76
- exports.Messenger = Messenger;
77
- Messenger.Counter = 1;
78
- //# sourceMappingURL=Messenger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Messenger.js","sourceRoot":"","sources":["../src/Messenger.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,iEAAmG;AAEnG,MAAa,SAAS;IAKlB,YAAY,KAA+B,EAAE,QAAwE;QAEjH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAA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MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBACpC,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBAER,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBACpC,CAAC,CAAC,CAAC;aACV;SACJ;IACL,CAAC;IACD,QAAQ;QAEJ,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM;YACP,OAAO,kDAAK,CAAC;QACjB,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,EACxC;YACI,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC7E,IAAI,CAAC,MAAM;gBACP,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACJ;AAlID,kCAkIC;AAAA,CAAC"}
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- import { IAccountProps } from "./IAccountProps";
3
- export interface IRouterMaker
4
- {
5
- on401(): void;
6
- onRenderOnLogin(props: IAccountProps): React.JSX.Element;
7
- onRenderOnLogout(props: IAccountProps, banned: boolean): React.JSX.Element;
8
- }
@@ -1,7 +0,0 @@
1
- import { NSNotificationProps } from "namirasoft-site-react";
2
-
3
- export interface IRouterState
4
- {
5
- inited?: boolean;
6
- notifications?: NSNotificationProps[];
7
- }
package/src/Messenger.ts DELETED
@@ -1,82 +0,0 @@
1
- import axios from "axios";
2
- import { IRouterState } from "./IRouterState";
3
- import { NSNotificationColor, NSNotificationProps, NotificationType } from "namirasoft-site-react";
4
-
5
- export class Messenger
6
- {
7
- private static Counter: number = 1;
8
- private state: IRouterState | undefined;
9
- private setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>;
10
- constructor(state: IRouterState | undefined, setState: React.Dispatch<React.SetStateAction<IRouterState | undefined>>)
11
- {
12
- this.state = state;
13
- this.setState = setState;
14
- this.notify = this.notify.bind(this);
15
- this.onInformation = this.onInformation.bind(this);
16
- this.onSuccess = this.onSuccess.bind(this);
17
- this.onWarning = this.onWarning.bind(this);
18
- this.onError = this.onError.bind(this);
19
- this.delNotification = this.delNotification.bind(this);
20
- this.getNotifications = this.getNotifications.bind(this);
21
- }
22
- private notify(message: NSNotificationProps)
23
- {
24
- let inited = this.state?.inited ?? false;
25
- let notifications: NSNotificationProps[] = [];
26
- if (this.state?.notifications)
27
- notifications.push(...this.state.notifications);
28
- notifications.push(message);
29
- this.setState({ inited, notifications });
30
- setTimeout(() =>
31
- {
32
- message.onClose();
33
- }, 5000);
34
- window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
35
- }
36
- onInformation(text: string)
37
- {
38
- let id = Messenger.Counter++ + "";
39
- this.notify({ id, text, type: NotificationType.Information, color: NSNotificationColor.GRAY, onClose: () => this.delNotification(id) });
40
- }
41
- onSuccess(text: string)
42
- {
43
- let id = Messenger.Counter++ + "";
44
- this.notify({ id, text, type: NotificationType.Success, color: NSNotificationColor.GREEN, onClose: () => this.delNotification(id) });
45
- }
46
- onWarning(text: string)
47
- {
48
- let id = Messenger.Counter++ + "";
49
- this.notify({ id, text, type: NotificationType.Warning, color: NSNotificationColor.YELLOW, onClose: () => this.delNotification(id) });
50
- }
51
- onError(error: Error | string)
52
- {
53
- let id = Messenger.Counter++ + "";
54
- let text: string = "";
55
- if (error instanceof Error)
56
- {
57
- text = error.message;
58
- if (axios.isAxiosError(error))
59
- if (error.response?.data)
60
- text = error.response.data;
61
- }
62
- else
63
- text = error;
64
- this.notify({ id, text, type: NotificationType.Error, color: NSNotificationColor.RED, onClose: () => this.delNotification(id) });
65
- }
66
- delNotification(id: string): void
67
- {
68
- if (!this.state)
69
- return;
70
-
71
- let inited = this.state.inited ?? false;
72
- let notifications: NSNotificationProps[] = [];
73
- if (this.state.notifications)
74
- notifications.push(...this.state.notifications);
75
- notifications = notifications.filter(x => x.id !== id);
76
- this.setState({ inited, notifications });
77
- }
78
- getNotifications(): NSNotificationProps[]
79
- {
80
- return this.state?.notifications ?? [];
81
- }
82
- }