flash-notifications 0.0.25 → 0.0.27

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.
@@ -1,4 +1,10 @@
1
1
  declare const _default: React.MemoExoticComponent<any>;
2
2
  export default _default;
3
+ export type NotificationObjectType = {
4
+ count: number;
5
+ message: string;
6
+ title: string;
7
+ type: string;
8
+ };
3
9
  import React from "react";
4
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;kBAG8C,OAAO"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;;WAiBc,MAAM;aACN,MAAM;WACN,MAAM;UACN,MAAM;;kBAf0B,OAAO"}
@@ -1,34 +1,47 @@
1
+ // @ts-check
1
2
  import { digg } from "diggerize";
2
3
  import PropTypes from "prop-types";
3
4
  import propTypesExact from "prop-types-exact";
4
5
  import React, { memo, useEffect, useMemo } from "react";
5
- import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
6
- import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint";
7
- import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter";
6
+ import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
7
+ import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint.js";
8
+ import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter.js";
8
9
  import useEnvSense from "env-sense/src/use-env-sense.js";
9
10
  import { View } from "react-native";
10
- import events from "../events";
11
+ import events from "../events.js";
11
12
  import Notification from "./notification";
13
+ /**
14
+ * @typedef {object} NotificationObjectType
15
+ * @property {number} count
16
+ * @property {string} message
17
+ * @property {string} title
18
+ * @property {string} type
19
+ */
12
20
  export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
13
21
  static propTypes = propTypesExact({
14
22
  insets: PropTypes.object
15
23
  });
24
+ /** @type {number[]} */
16
25
  timeouts = [];
17
26
  setup() {
27
+ // @ts-expect-error
18
28
  this.useStates({
19
29
  count: 0,
20
30
  notifications: []
21
31
  });
22
- useEventEmitter(events, "pushNotification", this.tt.onPushNotification);
32
+ useEventEmitter(events, "pushNotification", this.onPushNotification);
23
33
  useEffect(() => {
24
34
  return () => {
25
- for (const timeout of this.tt.timeouts) {
35
+ for (const timeout of this.timeouts) {
26
36
  clearTimeout(timeout);
27
37
  }
28
38
  };
29
39
  }, []);
30
40
  }
31
41
  render() {
42
+ // @ts-expect-error
43
+ const { notifications } = this.s;
44
+ // @ts-expect-error
32
45
  const insets = this.props.insets || {};
33
46
  const { smDown, mdUp } = useBreakpoint();
34
47
  const { isNative } = useEnvSense();
@@ -58,23 +71,37 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
58
71
  };
59
72
  return style;
60
73
  }, [isNative, smDown, mdUp, insets.top, insets.right, insets.left]);
61
- return (React.createElement(View, { dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" }, style: viewStyle, testID: "flash-notificaitons/container" }, this.s.notifications.map((notification) => React.createElement(Notification, { count: notification.count, key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.tt.onRemovedClicked, title: notification.title, type: notification.type }))));
74
+ return (React.createElement(View
75
+ // @ts-expect-error
76
+ , {
77
+ // @ts-expect-error
78
+ dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" },
79
+ // @ts-expect-error
80
+ style: viewStyle, testID: "flash-notificaitons/container" }, notifications.map((notification) => React.createElement(Notification, { count: notification.count, key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.onRemovedClicked, title: notification.title, type: notification.type }))));
62
81
  }
82
+ /**
83
+ * @param {NotificationObjectType} detail
84
+ * @returns {void}
85
+ */
63
86
  onPushNotification = (detail) => {
87
+ // @ts-expect-error
64
88
  const count = this.s.count + 1;
65
89
  const timeout = setTimeout(() => this.removeNotification(count), 4000);
66
- this.tt.timeouts.push(timeout);
90
+ this.timeouts.push(timeout);
67
91
  const notification = {
68
92
  count,
69
93
  message: digg(detail, "message"),
70
94
  title: digg(detail, "title"),
71
95
  type: digg(detail, "type")
72
96
  };
97
+ // @ts-expect-error
73
98
  this.setState({ count, notifications: this.s.notifications.concat([notification]) });
74
99
  };
75
100
  onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"));
76
101
  removeNotification = (count) => {
102
+ // @ts-expect-error
77
103
  this.setState({
104
+ // @ts-expect-error
78
105
  notifications: this.s.notifications.filter((notification) => notification.count != count)
79
106
  });
80
107
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AACpF,OAAO,aAAa,MAAM,0CAA0C,CAAA;AACpE,OAAO,eAAe,MAAM,6CAA6C,CAAA;AACzE,OAAO,WAAW,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AAEjC,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,eAAe,IAAI,CAAC,cAAc,CAAC,MAAM,2BAA4B,SAAQ,cAAc;IACzF,MAAM,CAAC,SAAS,GAAG,cAAc,CAAC;QAChC,MAAM,EAAE,SAAS,CAAC,MAAM;KACzB,CAAC,CAAA;IAEF,QAAQ,GAAG,EAAE,CAAA;IAEb,KAAK;QACH,IAAI,CAAC,SAAS,CAAC;YACb,KAAK,EAAE,CAAC;YACR,aAAa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AE,OAAO,CAAC;YAC5B,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;SAC3B,CAAA;QAED,IAAI,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC,CAAA;IACpF,CAAC,CAAA;IAED,gBAAgB,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAEzF,kBAAkB,GAAG,CAAC,KAAK,EAAE,EAAE;QAC7B,IAAI,CAAC,QAAQ,CAAC;YACZ,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import {digg} from \"diggerize\"\nimport PropTypes from \"prop-types\"\nimport propTypesExact from \"prop-types-exact\"\nimport React, {memo, useEffect, useMemo} from \"react\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\nimport useBreakpoint from \"@kaspernj/api-maker/build/use-breakpoint\"\nimport useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter\"\nimport useEnvSense from \"env-sense/src/use-env-sense.js\"\nimport {View} from \"react-native\"\n\nimport events from \"../events\"\nimport Notification from \"./notification\"\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n static propTypes = propTypesExact({\n insets: PropTypes.object\n })\n\n timeouts = []\n\n setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.tt.onPushNotification)\n useEffect(() => {\n return () => {\n for (const timeout of this.tt.timeouts) {\n clearTimeout(timeout)\n }\n }\n }, [])\n }\n\n render() {\n const insets = this.props.insets || {}\n const {smDown, mdUp} = useBreakpoint()\n const {isNative} = useEnvSense()\n\n const viewStyle = useMemo(() => {\n let top = 20\n let right = 0\n let left = undefined\n\n if (insets.top) top += insets.top\n if (insets.right) right += insets.right\n\n if (smDown) {\n left = 20\n\n if (insets.left) left += insets.left\n\n right += 20\n } else if (mdUp) {\n right += 20\n }\n\n const style = {\n position: isNative ? \"absolute\" : \"fixed\",\n top,\n right,\n left,\n zIndex: 99999\n }\n\n return style\n }, [isNative, smDown, mdUp, insets.top, insets.right, insets.left])\n\n return (\n <View\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n style={viewStyle}\n testID=\"flash-notificaitons/container\"\n >\n {this.s.notifications.map((notification) =>\n <Notification\n count={notification.count}\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.tt.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n onPushNotification = (detail) => {\n const count = this.s.count + 1\n const timeout = setTimeout(() => this.removeNotification(count), 4000)\n\n this.tt.timeouts.push(timeout)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\n this.setState({count, notifications: this.s.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n this.setState({\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AACrD,OAA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CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["// @ts-check\n\nimport {digg} from \"diggerize\"\nimport PropTypes from \"prop-types\"\nimport propTypesExact from \"prop-types-exact\"\nimport React, {memo, useEffect, useMemo} from \"react\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport useBreakpoint from \"@kaspernj/api-maker/build/use-breakpoint.js\"\nimport useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter.js\"\nimport useEnvSense from \"env-sense/src/use-env-sense.js\"\nimport {View} from \"react-native\"\n\nimport events from \"../events.js\"\nimport Notification from \"./notification\"\n\n/**\n * @typedef {object} NotificationObjectType\n * @property {number} count\n * @property {string} message\n * @property {string} title\n * @property {string} type\n */\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n static propTypes = propTypesExact({\n insets: PropTypes.object\n })\n\n /** @type {number[]} */\n timeouts = []\n\n setup() {\n // @ts-expect-error\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.onPushNotification)\n useEffect(() => {\n return () => {\n for (const timeout of this.timeouts) {\n clearTimeout(timeout)\n }\n }\n }, [])\n }\n\n render() {\n // @ts-expect-error\n const {notifications} = this.s\n\n // @ts-expect-error\n const insets = this.props.insets || {}\n\n const {smDown, mdUp} = useBreakpoint()\n const {isNative} = useEnvSense()\n\n const viewStyle = useMemo(() => {\n let top = 20\n let right = 0\n let left = undefined\n\n if (insets.top) top += insets.top\n if (insets.right) right += insets.right\n\n if (smDown) {\n left = 20\n\n if (insets.left) left += insets.left\n\n right += 20\n } else if (mdUp) {\n right += 20\n }\n\n const style = {\n position: isNative ? \"absolute\" : \"fixed\",\n top,\n right,\n left,\n zIndex: 99999\n }\n\n return style\n }, [isNative, smDown, mdUp, insets.top, insets.right, insets.left])\n\n return (\n <View\n // @ts-expect-error\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n // @ts-expect-error\n style={viewStyle}\n testID=\"flash-notificaitons/container\"\n >\n {notifications.map((notification) =>\n <Notification\n count={notification.count}\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n /**\n * @param {NotificationObjectType} detail\n * @returns {void}\n */\n onPushNotification = (detail) => {\n // @ts-expect-error\n const count = this.s.count + 1\n const timeout = setTimeout(() => this.removeNotification(count), 4000)\n\n this.timeouts.push(timeout)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\n // @ts-expect-error\n this.setState({count, notifications: this.s.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n // @ts-expect-error\n this.setState({\n // @ts-expect-error\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
@@ -3,7 +3,7 @@ import PropTypes from "prop-types";
3
3
  import PropTypesExact from "prop-types-exact";
4
4
  import React, { memo, useMemo } from "react";
5
5
  import { Pressable, StyleSheet, Text, View } from "react-native";
6
- import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
6
+ import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
7
7
  import useStyles from "@kaspernj/api-maker/build/use-styles.js";
8
8
  const styles = StyleSheet.create({
9
9
  view: {
@@ -1 +1 @@
1
- {"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAA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AI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,oCAAoC,KAAK,UAAU,IACzF,OAAO,CACH,CACF,CACF,CACG,CACb,CAAA;IACH,CAAC;IAED,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;CACtE,CAAC,CAAC,CAAA","sourcesContent":["import classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\nimport React, {memo, useMemo} from \"react\"\nimport {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\nimport useStyles from \"@kaspernj/api-maker/build/use-styles.js\"\n\nconst styles = StyleSheet.create({\n view: {\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n },\n viewSmDown: {\n width: \"100%\"\n },\n viewMdUp: {\n width: 300,\n maxWidth: \"100%\"\n },\n viewError: {\n border: \"1px solid rgba(161, 34, 32, 0.95)\",\n backgroundColor: \"rgba(161, 34, 32, 0.87)\"\n },\n viewSuccess: {\n border: \"1px solid rgba(0, 0, 0, 0.95)\",\n backgroundColor: \"rgba(0, 0, 0, 0.87)\"\n },\n viewAlert: {\n border: \"1px solid rgba(204, 51, 0, 0.95)\",\n backgroundColor: \"rgba(204, 51, 0, 0.87)\"\n },\n titleview: {\n marginBottom: 5\n },\n titleText: {\n color: \"#fff\",\n fontWeight: \"bold\"\n },\n messageText: {\n color: \"#fff\"\n }\n})\n\nconst titleViewDataSet = {class: \"notification-title\"}\nconst messageViewDataSet = {class: \"notification-message\"}\n\nexport default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\n count: PropTypes.number.isRequired,\n message: PropTypes.string.isRequired,\n notification: PropTypes.object.isRequired,\n onRemovedClicked: PropTypes.func.isRequired,\n title: PropTypes.string.isRequired,\n type: PropTypes.string.isRequired\n })\n\n render() {\n const {count, message, title, type} = this.p\n const {className} = this.props\n\n const viewStyles = useStyles(styles, [\"view\", {\n viewError: type == \"error\",\n viewSuccess: type == \"success\",\n viewAlert: type == \"alert\"\n }])\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\n role: \"dialog\",\n type\n }),\n [className, type]\n )\n\n return (\n <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>\n <View style={viewStyles}>\n <View dataSet={titleViewDataSet} style={styles.titleview}>\n <Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
1
+ {"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0CAA0C,CAAA;AACvF,OAAO,SAAS,MAAM,yCAAyC,CAAA;AAE/D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EA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-types-exact\"\nimport React, {memo, useMemo} from \"react\"\nimport {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport useStyles from \"@kaspernj/api-maker/build/use-styles.js\"\n\nconst styles = StyleSheet.create({\n view: {\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n },\n viewSmDown: {\n width: \"100%\"\n },\n viewMdUp: {\n width: 300,\n maxWidth: \"100%\"\n },\n viewError: {\n border: \"1px solid rgba(161, 34, 32, 0.95)\",\n backgroundColor: \"rgba(161, 34, 32, 0.87)\"\n },\n viewSuccess: {\n border: \"1px solid rgba(0, 0, 0, 0.95)\",\n backgroundColor: \"rgba(0, 0, 0, 0.87)\"\n },\n viewAlert: {\n border: \"1px solid rgba(204, 51, 0, 0.95)\",\n backgroundColor: \"rgba(204, 51, 0, 0.87)\"\n },\n titleview: {\n marginBottom: 5\n },\n titleText: {\n color: \"#fff\",\n fontWeight: \"bold\"\n },\n messageText: {\n color: \"#fff\"\n }\n})\n\nconst titleViewDataSet = {class: \"notification-title\"}\nconst messageViewDataSet = {class: \"notification-message\"}\n\nexport default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\n count: PropTypes.number.isRequired,\n message: PropTypes.string.isRequired,\n notification: PropTypes.object.isRequired,\n onRemovedClicked: PropTypes.func.isRequired,\n title: PropTypes.string.isRequired,\n type: PropTypes.string.isRequired\n })\n\n render() {\n const {count, message, title, type} = this.p\n const {className} = this.props\n\n const viewStyles = useStyles(styles, [\"view\", {\n viewError: type == \"error\",\n viewSuccess: type == \"success\",\n viewAlert: type == \"alert\"\n }])\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\n role: \"dialog\",\n type\n }),\n [className, type]\n )\n\n return (\n <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>\n <View style={viewStyles}>\n <View dataSet={titleViewDataSet} style={styles.titleview}>\n <Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
@@ -1,8 +1,33 @@
1
1
  export default class FlashNotifications {
2
- static alert(message: any): void;
3
- static error(message: any): void;
4
- static errorResponse(error: any): void;
5
- static success(message: any): void;
6
- static show(args: any): void;
2
+ /**
3
+ * @param {string} message
4
+ * @returns {void}
5
+ */
6
+ static alert(message: string): void;
7
+ /**
8
+ * @param {string} message
9
+ * @returns {void}
10
+ */
11
+ static error(message: string): void;
12
+ /**
13
+ * @param {Error} error
14
+ * @returns {void}
15
+ */
16
+ static errorResponse(error: Error): void;
17
+ /**
18
+ * @param {string} message
19
+ * @returns {void}
20
+ */
21
+ static success(message: string): void;
22
+ /**
23
+ * @param {object} args
24
+ * @param {string} args.text
25
+ * @param {string} args.type
26
+ * @returns {void}
27
+ */
28
+ static show(args: {
29
+ text: string;
30
+ type: string;
31
+ }): void;
7
32
  }
8
33
  //# sourceMappingURL=flash-notifications.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAOA;IACE,iCAEC;IAED,iCAEC;IAED,uCA8BC;IAED,mCAEC;IAED,6BAkBC;CACF"}
1
+ {"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAOA;IACE;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,IAAI,CAqChB;IAED;;;OAGG;IACH,wBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;;OAKG;IACH,kBAJG;QAAqB,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAoBhB;CACF"}
@@ -1,18 +1,32 @@
1
- import BaseError from "@kaspernj/api-maker/build/base-error";
2
- import ValidationError from "@kaspernj/api-maker/build/validation-error";
1
+ // @ts-check
3
2
  import { digg } from "diggerize";
4
- import configuration from "./configuration";
5
- import events from "./events";
3
+ import configuration from "./configuration.js";
4
+ import events from "./events.js";
6
5
  export default class FlashNotifications {
6
+ /**
7
+ * @param {string} message
8
+ * @returns {void}
9
+ */
7
10
  static alert(message) {
8
11
  FlashNotifications.show({ type: "alert", text: message });
9
12
  }
13
+ /**
14
+ * @param {string} message
15
+ * @returns {void}
16
+ */
10
17
  static error(message) {
11
18
  FlashNotifications.show({ type: "error", text: message });
12
19
  }
20
+ /**
21
+ * @param {Error} error
22
+ * @returns {void}
23
+ */
13
24
  static errorResponse(error) {
14
- if (error instanceof ValidationError) {
25
+ // @ts-expect-error
26
+ if (error.apiMakerType == "ValidationError") {
27
+ // @ts-expect-error
15
28
  if (error.hasUnhandledErrors()) {
29
+ // @ts-expect-error
16
30
  const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat();
17
31
  FlashNotifications.error(unhandledErrorMessages.join(". "));
18
32
  }
@@ -20,10 +34,12 @@ export default class FlashNotifications {
20
34
  const defaultValue = "Couldn't submit because of validation errors.";
21
35
  FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", { defaultValue }));
22
36
  }
37
+ // @ts-expect-error
23
38
  }
24
- else if (error instanceof BaseError) {
39
+ else if (error.apiMakerType == "BaseError") {
40
+ // @ts-expect-error
25
41
  if (error.args.response && error.args.response.errors) {
26
- const errors = digg(error, "args", "response", "errors");
42
+ const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"));
27
43
  const errorMessages = errors.map((error) => {
28
44
  if (typeof error == "string") {
29
45
  return error;
@@ -37,13 +53,23 @@ export default class FlashNotifications {
37
53
  }
38
54
  }
39
55
  else {
40
- console.error("Didnt know what to do with that error", error);
56
+ console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`);
41
57
  throw error;
42
58
  }
43
59
  }
60
+ /**
61
+ * @param {string} message
62
+ * @returns {void}
63
+ */
44
64
  static success(message) {
45
65
  FlashNotifications.show({ type: "success", text: message });
46
66
  }
67
+ /**
68
+ * @param {object} args
69
+ * @param {string} args.text
70
+ * @param {string} args.type
71
+ * @returns {void}
72
+ */
47
73
  static show(args) {
48
74
  let title;
49
75
  if (args.type == "alert") {
@@ -1 +1 @@
1
- {"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,sCAAsC,CAAA;AAC5D,OAAO,eAAe,MAAM,4CAA4C,CAAA;AACxE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,MAAM,MAAM,UAAU,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,KAAK;QACxB,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAE,CAAC;gBAC/B,MAAM,sBAAsB,GAAG,KAAK,CAAC,kBAAkB,EAAE,CAAC,GAAG,CAAC,CAA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,OAAO,EAAC,CAAC,CAAA;IAC3D,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI;QACd,IAAI,KAAK,CAAA;QAET,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YACzB,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YAChC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAC,YAAY,EAAE,SAAS,EAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,wBAAwB,EAAE,EAAC,YAAY,EAAE,cAAc,EAAC,CAAC,CAAA;QAC3F,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import BaseError from \"@kaspernj/api-maker/build/base-error\"\nimport ValidationError from \"@kaspernj/api-maker/build/validation-error\"\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration\"\nimport events from \"./events\"\n\nexport default class FlashNotifications {\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n static error(message) {\n FlashNotifications.show({type: \"error\", text: message})\n }\n\n static errorResponse(error) {\n if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()\n\n FlashNotifications.error(unhandledErrorMessages.join(\". \"))\n } else {\n const defaultValue = \"Couldn't submit because of validation errors.\"\n\n FlashNotifications.alert(configuration.translate(\"js.notification.couldnt_submit_because_of_validation_errors\", {defaultValue}))\n }\n } else if (error instanceof BaseError) {\n if (error.args.response && error.args.response.errors) {\n const errors = digg(error, \"args\", \"response\", \"errors\")\n const errorMessages = errors.map((error) => {\n if (typeof error == \"string\") {\n return error\n }\n\n return digg(error, \"message\")\n })\n\n FlashNotifications.error(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else {\n console.error(\"Didnt know what to do with that error\", error)\n throw error\n }\n }\n\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\n\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = configuration.translate(\"js.shared.alert\", {defaultValue: \"Alert\"})\n } else if (args.type == \"error\") {\n title = configuration.translate(\"js.shared.error\", {defaultValue: \"Error\"})\n } else if (args.type == \"success\") {\n title = configuration.translate(\"js.shared.success\", {defaultValue: \"Success\"})\n } else {\n title = configuration.translate(\"js.shared.notification\", {defaultValue: \"Notification\"})\n }\n\n events.emit(\"pushNotification\", {\n message: args.text,\n title,\n type: args.type\n })\n }\n}\n"]}
1
+ {"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,MAAM,MAAM,aAAa,CAAA;AAEhC,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAk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CAAC;QAED,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["// @ts-check\n\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration.js\"\nimport events from \"./events.js\"\n\nexport default class FlashNotifications {\n /**\n * @param {string} message\n * @returns {void}\n */\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static error(message) {\n FlashNotifications.show({type: \"error\", text: message})\n }\n\n /**\n * @param {Error} error\n * @returns {void}\n */\n static errorResponse(error) {\n // @ts-expect-error\n if (error.apiMakerType == \"ValidationError\") {\n // @ts-expect-error\n if (error.hasUnhandledErrors()) {\n // @ts-expect-error\n const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()\n\n FlashNotifications.error(unhandledErrorMessages.join(\". \"))\n } else {\n const defaultValue = \"Couldn't submit because of validation errors.\"\n\n FlashNotifications.alert(configuration.translate(\"js.notification.couldnt_submit_because_of_validation_errors\", {defaultValue}))\n }\n // @ts-expect-error\n } else if (error.apiMakerType == \"BaseError\") {\n // @ts-expect-error\n if (error.args.response && error.args.response.errors) {\n const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, \"args\", \"response\", \"errors\"))\n const errorMessages = errors.map((error) => {\n if (typeof error == \"string\") {\n return error\n }\n\n return digg(error, \"message\")\n })\n\n FlashNotifications.error(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else {\n console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)\n throw error\n }\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\n\n /**\n * @param {object} args\n * @param {string} args.text\n * @param {string} args.type\n * @returns {void}\n */\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = configuration.translate(\"js.shared.alert\", {defaultValue: \"Alert\"})\n } else if (args.type == \"error\") {\n title = configuration.translate(\"js.shared.error\", {defaultValue: \"Error\"})\n } else if (args.type == \"success\") {\n title = configuration.translate(\"js.shared.success\", {defaultValue: \"Success\"})\n } else {\n title = configuration.translate(\"js.shared.notification\", {defaultValue: \"Notification\"})\n }\n\n events.emit(\"pushNotification\", {\n message: args.text,\n title,\n type: args.type\n })\n }\n}\n"]}
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import configuration from "./configuration";
1
+ import configuration from "./configuration.js";
2
2
  import Container from "./container";
3
- import FlashNotifications from "./flash-notifications";
3
+ import FlashNotifications from "./flash-notifications.js";
4
4
  export { configuration, Container, FlashNotifications };
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"0BAA0B,iBAAiB;sBACrB,aAAa;+BACJ,uBAAuB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"0BAE0B,oBAAoB;sBACxB,aAAa;+BACJ,0BAA0B"}
package/build/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import configuration from "./configuration";
1
+ // @ts-check
2
+ import configuration from "./configuration.js";
2
3
  import Container from "./container";
3
- import FlashNotifications from "./flash-notifications";
4
+ import FlashNotifications from "./flash-notifications.js";
4
5
  if (!configuration) {
5
6
  throw new Error("No configuration object given?");
6
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,kBAAkB,MAAM,uBAAuB,CAAA;AAEtD,IAAI,CAAC,aAAa,EAAE,CAAC;IACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;AACnD,CAAC;AAED,OAAO,EACL,aAAa,EACb,SAAS,EACT,kBAAkB,EACnB,CAAA","sourcesContent":["import configuration from \"./configuration\"\nimport Container from \"./container\"\nimport FlashNotifications from \"./flash-notifications\"\n\nif (!configuration) {\n throw new Error(\"No configuration object given?\")\n}\n\nexport {\n configuration,\n Container,\n FlashNotifications\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,kBAAkB,MAAM,0BAA0B,CAAA;AAEzD,IAAI,CAAC,aAAa,EAAE,CAAC;IACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;AACnD,CAAC;AAED,OAAO,EACL,aAAa,EACb,SAAS,EACT,kBAAkB,EACnB,CAAA","sourcesContent":["// @ts-check\n\nimport configuration from \"./configuration.js\"\nimport Container from \"./container\"\nimport FlashNotifications from \"./flash-notifications.js\"\n\nif (!configuration) {\n throw new Error(\"No configuration object given?\")\n}\n\nexport {\n configuration,\n Container,\n FlashNotifications\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-notifications",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -51,7 +51,7 @@
51
51
  "react-native": "~0.76.9"
52
52
  },
53
53
  "peerDependencies": {
54
- "@kaspernj/api-maker": ">= 1.0.2044",
54
+ "@kaspernj/api-maker": ">= 1.0.2053",
55
55
  "expo": "*",
56
56
  "react": "*",
57
57
  "react-native": "*"
@@ -1,33 +1,45 @@
1
+ // @ts-check
2
+
1
3
  import {digg} from "diggerize"
2
4
  import PropTypes from "prop-types"
3
5
  import propTypesExact from "prop-types-exact"
4
6
  import React, {memo, useEffect, useMemo} from "react"
5
- import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
6
- import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint"
7
- import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter"
7
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
8
+ import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint.js"
9
+ import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter.js"
8
10
  import useEnvSense from "env-sense/src/use-env-sense.js"
9
11
  import {View} from "react-native"
10
12
 
11
- import events from "../events"
13
+ import events from "../events.js"
12
14
  import Notification from "./notification"
13
15
 
16
+ /**
17
+ * @typedef {object} NotificationObjectType
18
+ * @property {number} count
19
+ * @property {string} message
20
+ * @property {string} title
21
+ * @property {string} type
22
+ */
23
+
14
24
  export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
15
25
  static propTypes = propTypesExact({
16
26
  insets: PropTypes.object
17
27
  })
18
28
 
29
+ /** @type {number[]} */
19
30
  timeouts = []
20
31
 
21
32
  setup() {
33
+ // @ts-expect-error
22
34
  this.useStates({
23
35
  count: 0,
24
36
  notifications: []
25
37
  })
26
38
 
27
- useEventEmitter(events, "pushNotification", this.tt.onPushNotification)
39
+ useEventEmitter(events, "pushNotification", this.onPushNotification)
28
40
  useEffect(() => {
29
41
  return () => {
30
- for (const timeout of this.tt.timeouts) {
42
+ for (const timeout of this.timeouts) {
31
43
  clearTimeout(timeout)
32
44
  }
33
45
  }
@@ -35,7 +47,12 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
35
47
  }
36
48
 
37
49
  render() {
50
+ // @ts-expect-error
51
+ const {notifications} = this.s
52
+
53
+ // @ts-expect-error
38
54
  const insets = this.props.insets || {}
55
+
39
56
  const {smDown, mdUp} = useBreakpoint()
40
57
  const {isNative} = useEnvSense()
41
58
 
@@ -70,17 +87,19 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
70
87
 
71
88
  return (
72
89
  <View
90
+ // @ts-expect-error
73
91
  dataSet={this.rootViewDataSet ||= {component: "flash-notifications-container"}}
92
+ // @ts-expect-error
74
93
  style={viewStyle}
75
94
  testID="flash-notificaitons/container"
76
95
  >
77
- {this.s.notifications.map((notification) =>
96
+ {notifications.map((notification) =>
78
97
  <Notification
79
98
  count={notification.count}
80
99
  key={`notification-${notification.count}`}
81
100
  message={notification.message}
82
101
  notification={notification}
83
- onRemovedClicked={this.tt.onRemovedClicked}
102
+ onRemovedClicked={this.onRemovedClicked}
84
103
  title={notification.title}
85
104
  type={notification.type}
86
105
  />
@@ -89,11 +108,16 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
89
108
  )
90
109
  }
91
110
 
111
+ /**
112
+ * @param {NotificationObjectType} detail
113
+ * @returns {void}
114
+ */
92
115
  onPushNotification = (detail) => {
116
+ // @ts-expect-error
93
117
  const count = this.s.count + 1
94
118
  const timeout = setTimeout(() => this.removeNotification(count), 4000)
95
119
 
96
- this.tt.timeouts.push(timeout)
120
+ this.timeouts.push(timeout)
97
121
 
98
122
  const notification = {
99
123
  count,
@@ -102,13 +126,16 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
102
126
  type: digg(detail, "type")
103
127
  }
104
128
 
129
+ // @ts-expect-error
105
130
  this.setState({count, notifications: this.s.notifications.concat([notification])})
106
131
  }
107
132
 
108
133
  onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"))
109
134
 
110
135
  removeNotification = (count) => {
136
+ // @ts-expect-error
111
137
  this.setState({
138
+ // @ts-expect-error
112
139
  notifications: this.s.notifications.filter((notification) => notification.count != count)
113
140
  })
114
141
  }
@@ -3,7 +3,7 @@ import PropTypes from "prop-types"
3
3
  import PropTypesExact from "prop-types-exact"
4
4
  import React, {memo, useMemo} from "react"
5
5
  import {Pressable, StyleSheet, Text, View} from "react-native"
6
- import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
6
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
7
7
  import useStyles from "@kaspernj/api-maker/build/use-styles.js"
8
8
 
9
9
  const styles = StyleSheet.create({
@@ -1,22 +1,37 @@
1
- import BaseError from "@kaspernj/api-maker/build/base-error"
2
- import ValidationError from "@kaspernj/api-maker/build/validation-error"
1
+ // @ts-check
2
+
3
3
  import {digg} from "diggerize"
4
4
 
5
- import configuration from "./configuration"
6
- import events from "./events"
5
+ import configuration from "./configuration.js"
6
+ import events from "./events.js"
7
7
 
8
8
  export default class FlashNotifications {
9
+ /**
10
+ * @param {string} message
11
+ * @returns {void}
12
+ */
9
13
  static alert(message) {
10
14
  FlashNotifications.show({type: "alert", text: message})
11
15
  }
12
16
 
17
+ /**
18
+ * @param {string} message
19
+ * @returns {void}
20
+ */
13
21
  static error(message) {
14
22
  FlashNotifications.show({type: "error", text: message})
15
23
  }
16
24
 
25
+ /**
26
+ * @param {Error} error
27
+ * @returns {void}
28
+ */
17
29
  static errorResponse(error) {
18
- if (error instanceof ValidationError) {
30
+ // @ts-expect-error
31
+ if (error.apiMakerType == "ValidationError") {
32
+ // @ts-expect-error
19
33
  if (error.hasUnhandledErrors()) {
34
+ // @ts-expect-error
20
35
  const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()
21
36
 
22
37
  FlashNotifications.error(unhandledErrorMessages.join(". "))
@@ -25,9 +40,11 @@ export default class FlashNotifications {
25
40
 
26
41
  FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", {defaultValue}))
27
42
  }
28
- } else if (error instanceof BaseError) {
43
+ // @ts-expect-error
44
+ } else if (error.apiMakerType == "BaseError") {
45
+ // @ts-expect-error
29
46
  if (error.args.response && error.args.response.errors) {
30
- const errors = digg(error, "args", "response", "errors")
47
+ const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"))
31
48
  const errorMessages = errors.map((error) => {
32
49
  if (typeof error == "string") {
33
50
  return error
@@ -41,15 +58,25 @@ export default class FlashNotifications {
41
58
  throw error
42
59
  }
43
60
  } else {
44
- console.error("Didnt know what to do with that error", error)
61
+ console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)
45
62
  throw error
46
63
  }
47
64
  }
48
65
 
66
+ /**
67
+ * @param {string} message
68
+ * @returns {void}
69
+ */
49
70
  static success(message) {
50
71
  FlashNotifications.show({type: "success", text: message})
51
72
  }
52
73
 
74
+ /**
75
+ * @param {object} args
76
+ * @param {string} args.text
77
+ * @param {string} args.type
78
+ * @returns {void}
79
+ */
53
80
  static show(args) {
54
81
  let title
55
82
 
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import configuration from "./configuration"
1
+ // @ts-check
2
+
3
+ import configuration from "./configuration.js"
2
4
  import Container from "./container"
3
- import FlashNotifications from "./flash-notifications"
5
+ import FlashNotifications from "./flash-notifications.js"
4
6
 
5
7
  if (!configuration) {
6
8
  throw new Error("No configuration object given?")