flash-notifications 0.0.16 → 0.0.17
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/build/configuration.d.ts.map +1 -1
- package/build/configuration.js +3 -1
- package/build/configuration.js.map +1 -1
- package/build/container/index.d.ts.map +1 -1
- package/build/container/index.js +13 -4
- package/build/container/index.js.map +1 -1
- package/build/container/notification.js +5 -3
- package/build/container/notification.js.map +1 -1
- package/build/flash-notifications.js +2 -2
- package/build/flash-notifications.js.map +1 -1
- package/package.json +14 -4
- package/peak_flow.yml +1 -0
- package/src/configuration.js +3 -1
- package/src/container/index.jsx +16 -4
- package/src/container/notification.jsx +5 -3
- package/src/flash-notifications.js +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":";AAMA,iCAAgE"}
|
package/build/configuration.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
if (!globalThis.flashNotificationsConfiguration) {
|
|
2
|
-
globalThis.flashNotificationsConfiguration = {
|
|
2
|
+
globalThis.flashNotificationsConfiguration = {
|
|
3
|
+
translate: (msgId) => msgId
|
|
4
|
+
};
|
|
3
5
|
}
|
|
4
6
|
const configuration = globalThis.flashNotificationsConfiguration;
|
|
5
7
|
export default configuration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":"AAAA,IAAI,CAAC,UAAU,CAAC,+BAA+B,EAAE,CAAC;IAChD,UAAU,CAAC,+BAA+B,GAAG,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":"AAAA,IAAI,CAAC,UAAU,CAAC,+BAA+B,EAAE,CAAC;IAChD,UAAU,CAAC,+BAA+B,GAAG;QAC3C,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;KAC5B,CAAA;AACH,CAAC;AAED,MAAM,aAAa,GAAG,UAAU,CAAC,+BAA+B,CAAA;AAEhE,eAAe,aAAa,CAAA","sourcesContent":["if (!globalThis.flashNotificationsConfiguration) {\n globalThis.flashNotificationsConfiguration = {\n translate: (msgId) => msgId\n }\n}\n\nconst configuration = globalThis.flashNotificationsConfiguration\n\nexport default configuration\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;kBAEqC,OAAO"}
|
package/build/container/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import useEventEmitter from "@kaspernj/api-maker/
|
|
1
|
+
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter";
|
|
2
2
|
import { digg } from "diggerize";
|
|
3
|
-
import React, { memo } from "react";
|
|
3
|
+
import React, { memo, useEffect } from "react";
|
|
4
4
|
import { StyleSheet, View } from "react-native";
|
|
5
5
|
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
|
|
6
6
|
import events from "../events";
|
|
@@ -14,19 +14,28 @@ const styles = StyleSheet.create({
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
17
|
+
timeouts = [];
|
|
17
18
|
setup() {
|
|
18
19
|
this.useStates({
|
|
19
20
|
count: 0,
|
|
20
21
|
notifications: []
|
|
21
22
|
});
|
|
22
23
|
useEventEmitter(events, "pushNotification", this.tt.onPushNotification);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
return () => {
|
|
26
|
+
for (const timeout of this.tt.timeouts) {
|
|
27
|
+
clearTimeout(timeout);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
23
31
|
}
|
|
24
32
|
render() {
|
|
25
|
-
return (React.createElement(View, { dataSet: this.rootViewDataSet ||= {
|
|
33
|
+
return (React.createElement(View, { dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" }, style: styles.view, 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 }))));
|
|
26
34
|
}
|
|
27
35
|
onPushNotification = (detail) => {
|
|
28
36
|
const count = this.s.count + 1;
|
|
29
|
-
setTimeout(() => this.removeNotification(count), 4000);
|
|
37
|
+
const timeout = setTimeout(() => this.removeNotification(count), 4000);
|
|
38
|
+
this.tt.timeouts.push(timeout);
|
|
30
39
|
const notification = {
|
|
31
40
|
count,
|
|
32
41
|
message: digg(detail, "message"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,6CAA6C,CAAA;AACzE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AAEpF,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,Q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AAkB,GAAG,CAAC,MAAM,EAAE,EAAE;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAA;QAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAA;QAEtE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAE9B,MAAM,YAAY,GAAG;YACnB,KAAK;YACL,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC;YAChC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,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 useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter\"\nimport {digg} from \"diggerize\"\nimport React, {memo, useEffect} from \"react\"\nimport {StyleSheet, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\n\nimport events from \"../events\"\nimport Notification from \"./notification\"\n\nconst styles = StyleSheet.create({\n view: {\n position: \"fixed\",\n zIndex: 99999,\n top: 20,\n right: 20\n }\n})\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\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 return (\n <View\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n style={styles.view}\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"]}
|
|
@@ -41,6 +41,7 @@ const messageViewDataSet = { class: "notification-message" };
|
|
|
41
41
|
export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
|
|
42
42
|
static propTypes = PropTypesExact({
|
|
43
43
|
className: PropTypes.string,
|
|
44
|
+
count: PropTypes.number.isRequired,
|
|
44
45
|
message: PropTypes.string.isRequired,
|
|
45
46
|
notification: PropTypes.object.isRequired,
|
|
46
47
|
onRemovedClicked: PropTypes.func.isRequired,
|
|
@@ -48,7 +49,8 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
48
49
|
type: PropTypes.string.isRequired
|
|
49
50
|
});
|
|
50
51
|
render() {
|
|
51
|
-
const {
|
|
52
|
+
const { count, message, title, type } = this.p;
|
|
53
|
+
const { className } = this.props;
|
|
52
54
|
const viewStyles = useMemo(() => {
|
|
53
55
|
const viewStyles = [styles.view];
|
|
54
56
|
if (type == "error")
|
|
@@ -66,9 +68,9 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
66
68
|
return (React.createElement(Pressable, { dataSet: pressableDataSet, onPress: this.tt.onRemovedClicked },
|
|
67
69
|
React.createElement(View, { style: viewStyles },
|
|
68
70
|
React.createElement(View, { dataSet: titleViewDataSet, style: styles.titleview },
|
|
69
|
-
React.createElement(Text, { style: styles.titleText }, title)),
|
|
71
|
+
React.createElement(Text, { style: styles.titleText, testID: `flash-notifications/notification-${count}/title` }, title)),
|
|
70
72
|
React.createElement(View, { dataSet: messageViewDataSet },
|
|
71
|
-
React.createElement(Text, { style: styles.messageText }, message)))));
|
|
73
|
+
React.createElement(Text, { style: styles.messageText, testID: `flash-notifications/notification-${count}/message` }, message)))));
|
|
72
74
|
}
|
|
73
75
|
onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification);
|
|
74
76
|
}));
|
|
@@ -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,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,uC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O,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB;YACrE,oBAAC,IAAI,IAAC,KAAK,EAAE,UAAU;gBACrB,oBAAC,IAAI,IAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS;oBACtD,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,oCAAoC,KAAK,QAAQ,IACrF,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,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\"\n\nconst styles = StyleSheet.create({\n view: {\n width: 300,\n maxWidth: \"100%\",\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\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 NotificationsNotification 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 = useMemo(\n () => {\n const viewStyles = [styles.view]\n\n if (type == \"error\") viewStyles.push(styles.viewError)\n if (type == \"success\") viewStyles.push(styles.viewSuccess)\n if (type == \"alert\") viewStyles.push(styles.viewAlert)\n\n return viewStyles\n },\n [type]\n )\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\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,5 +1,5 @@
|
|
|
1
|
-
import BaseError from "@kaspernj/api-maker/
|
|
2
|
-
import ValidationError from "@kaspernj/api-maker/
|
|
1
|
+
import BaseError from "@kaspernj/api-maker/build/base-error";
|
|
2
|
+
import ValidationError from "@kaspernj/api-maker/build/validation-error";
|
|
3
3
|
import { digg } from "diggerize";
|
|
4
4
|
import configuration from "./configuration";
|
|
5
5
|
import events from "./events";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,
|
|
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,KAAK;QAChB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;gBACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;gBACxD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBACzC,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;wBAC7B,OAAO,KAAK,CAAA;oBACd,CAAC;oBAED,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;gBAC/B,CAAC,CAAC,CAAA;gBAEF,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;YACpD,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;aAAM,IAAI,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C,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(error) {\n 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.alert(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n FlashNotifications.alert(error.message)\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 {\n console.error(\"Didnt know what to do with that error\", error)\n throw error\n }\n }\n\n static errorResponse(error) {\n this.error(error)\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flash-notifications",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "My new module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"build": "expo-module build",
|
|
9
9
|
"clean": "expo-module clean",
|
|
10
10
|
"lint": "expo-module lint",
|
|
11
|
-
"test": "
|
|
11
|
+
"test": "jest --detectOpenHandles",
|
|
12
|
+
"test-expo": "expo-module test",
|
|
12
13
|
"prepare": "expo-module prepare",
|
|
13
14
|
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
15
|
"expo-module": "expo-module",
|
|
@@ -28,19 +29,28 @@
|
|
|
28
29
|
"author": "kaspernj <kasper@diestoeckels.de> (https://github.com/kaspernj)",
|
|
29
30
|
"license": "MIT",
|
|
30
31
|
"homepage": "https://github.com/kaspernj/flash-notifications#readme",
|
|
32
|
+
"jest": {
|
|
33
|
+
"preset": "jest-expo",
|
|
34
|
+
"transformIgnorePatterns": [
|
|
35
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|diggerize|fetching-object|set-state-compare|@kaspernj/api-maker)"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
31
38
|
"dependencies": {
|
|
32
39
|
"classnames": "^2.5.1",
|
|
33
|
-
"diggerize": "
|
|
40
|
+
"diggerize": "^1.0.9",
|
|
41
|
+
"fetching-object": "^1.0.3",
|
|
34
42
|
"prop-types-exact": "*",
|
|
35
|
-
"set-state-compare": "
|
|
43
|
+
"set-state-compare": "^1.0.57"
|
|
36
44
|
},
|
|
37
45
|
"devDependencies": {
|
|
46
|
+
"@testing-library/react-native": "~13.0.1",
|
|
38
47
|
"@types/react": "~18.3.12",
|
|
39
48
|
"expo": "~53.0.9",
|
|
40
49
|
"expo-module-scripts": "^4.0.2",
|
|
41
50
|
"react-native": "~0.76.9"
|
|
42
51
|
},
|
|
43
52
|
"peerDependencies": {
|
|
53
|
+
"@kaspernj/api-maker": "*",
|
|
44
54
|
"expo": "*",
|
|
45
55
|
"react": "*",
|
|
46
56
|
"react-native": "*"
|
package/peak_flow.yml
CHANGED
package/src/configuration.js
CHANGED
package/src/container/index.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import useEventEmitter from "@kaspernj/api-maker/
|
|
1
|
+
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter"
|
|
2
2
|
import {digg} from "diggerize"
|
|
3
|
-
import React, {memo} from "react"
|
|
3
|
+
import React, {memo, useEffect} from "react"
|
|
4
4
|
import {StyleSheet, View} from "react-native"
|
|
5
5
|
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
6
6
|
|
|
@@ -17,6 +17,8 @@ const styles = StyleSheet.create({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
20
|
+
timeouts = []
|
|
21
|
+
|
|
20
22
|
setup() {
|
|
21
23
|
this.useStates({
|
|
22
24
|
count: 0,
|
|
@@ -24,16 +26,25 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
24
26
|
})
|
|
25
27
|
|
|
26
28
|
useEventEmitter(events, "pushNotification", this.tt.onPushNotification)
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
for (const timeout of this.tt.timeouts) {
|
|
32
|
+
clearTimeout(timeout)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [])
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
render() {
|
|
30
39
|
return (
|
|
31
40
|
<View
|
|
32
|
-
dataSet={this.rootViewDataSet ||= {
|
|
41
|
+
dataSet={this.rootViewDataSet ||= {component: "flash-notifications-container"}}
|
|
33
42
|
style={styles.view}
|
|
43
|
+
testID="flash-notificaitons/container"
|
|
34
44
|
>
|
|
35
45
|
{this.s.notifications.map((notification) =>
|
|
36
46
|
<Notification
|
|
47
|
+
count={notification.count}
|
|
37
48
|
key={`notification-${notification.count}`}
|
|
38
49
|
message={notification.message}
|
|
39
50
|
notification={notification}
|
|
@@ -48,8 +59,9 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
48
59
|
|
|
49
60
|
onPushNotification = (detail) => {
|
|
50
61
|
const count = this.s.count + 1
|
|
62
|
+
const timeout = setTimeout(() => this.removeNotification(count), 4000)
|
|
51
63
|
|
|
52
|
-
|
|
64
|
+
this.tt.timeouts.push(timeout)
|
|
53
65
|
|
|
54
66
|
const notification = {
|
|
55
67
|
count,
|
|
@@ -44,6 +44,7 @@ const messageViewDataSet = {class: "notification-message"}
|
|
|
44
44
|
export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
|
|
45
45
|
static propTypes = PropTypesExact({
|
|
46
46
|
className: PropTypes.string,
|
|
47
|
+
count: PropTypes.number.isRequired,
|
|
47
48
|
message: PropTypes.string.isRequired,
|
|
48
49
|
notification: PropTypes.object.isRequired,
|
|
49
50
|
onRemovedClicked: PropTypes.func.isRequired,
|
|
@@ -52,7 +53,8 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
52
53
|
})
|
|
53
54
|
|
|
54
55
|
render() {
|
|
55
|
-
const {
|
|
56
|
+
const {count, message, title, type} = this.p
|
|
57
|
+
const {className} = this.props
|
|
56
58
|
|
|
57
59
|
const viewStyles = useMemo(
|
|
58
60
|
() => {
|
|
@@ -79,12 +81,12 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
79
81
|
<Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>
|
|
80
82
|
<View style={viewStyles}>
|
|
81
83
|
<View dataSet={titleViewDataSet} style={styles.titleview}>
|
|
82
|
-
<Text style={styles.titleText}>
|
|
84
|
+
<Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>
|
|
83
85
|
{title}
|
|
84
86
|
</Text>
|
|
85
87
|
</View>
|
|
86
88
|
<View dataSet={messageViewDataSet}>
|
|
87
|
-
<Text style={styles.messageText}>
|
|
89
|
+
<Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>
|
|
88
90
|
{message}
|
|
89
91
|
</Text>
|
|
90
92
|
</View>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import BaseError from "@kaspernj/api-maker/
|
|
2
|
-
import ValidationError from "@kaspernj/api-maker/
|
|
1
|
+
import BaseError from "@kaspernj/api-maker/build/base-error"
|
|
2
|
+
import ValidationError from "@kaspernj/api-maker/build/validation-error"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
4
|
|
|
5
5
|
import configuration from "./configuration"
|