flash-notifications 0.0.12 → 0.0.14
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/container/index.d.ts +2 -1
- package/build/container/index.d.ts.map +1 -1
- package/build/container/index.js +20 -14
- package/build/container/index.js.map +1 -1
- package/build/container/notification.d.ts +2 -1
- package/build/container/notification.d.ts.map +1 -1
- package/build/container/notification.js +59 -32
- package/build/container/notification.js.map +1 -1
- package/build/flash-notifications.js +1 -1
- package/build/flash-notifications.js.map +1 -1
- package/link.sh +5 -0
- package/package.json +1 -1
- package/src/container/index.jsx +25 -17
- package/src/container/notification.jsx +64 -33
- package/src/flash-notifications.js +1 -1
|
@@ -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":";;kBAA0B,OAAO"}
|
package/build/container/index.js
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
import { memo } from "react";
|
|
1
|
+
import React, { memo } from "react";
|
|
2
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
2
4
|
import { digg } from "diggerize";
|
|
3
5
|
import Notification from "./notification";
|
|
4
|
-
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
5
6
|
import useEventListener from "@kaspernj/api-maker/src/use-event-listener";
|
|
6
|
-
|
|
7
|
+
const dataSets = {
|
|
8
|
+
view: { class: "flash-notifications-container" }
|
|
9
|
+
};
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
view: {
|
|
12
|
+
position: "fixed",
|
|
13
|
+
zIndex: 99999,
|
|
14
|
+
top: 20,
|
|
15
|
+
right: 20
|
|
16
|
+
}
|
|
17
|
+
});
|
|
7
18
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
8
19
|
setup() {
|
|
9
20
|
this.useStates({
|
|
10
21
|
count: 0,
|
|
11
22
|
notifications: []
|
|
12
23
|
});
|
|
13
|
-
useEventListener(
|
|
24
|
+
useEventListener(globalThis, "pushNotification", this.tt.onPushNotification);
|
|
14
25
|
}
|
|
15
26
|
render() {
|
|
16
|
-
return (React.createElement(View, { dataSet:
|
|
17
|
-
position: "fixed",
|
|
18
|
-
zIndex: 99999,
|
|
19
|
-
top: 20,
|
|
20
|
-
right: 20
|
|
21
|
-
} }, this.state.notifications.map((notification) => React.createElement(Notification, { key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.onRemovedClicked, title: notification.title, type: notification.type }))));
|
|
27
|
+
return (React.createElement(View, { dataSet: dataSets.view, style: styles.view }, this.s.notifications.map((notification) => React.createElement(Notification, { key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.tt.onRemovedClicked, title: notification.title, type: notification.type }))));
|
|
22
28
|
}
|
|
23
29
|
onPushNotification = (event) => {
|
|
24
30
|
const detail = digg(event, "detail");
|
|
25
|
-
const count = this.
|
|
26
|
-
setTimeout(() => this.removeNotification(count), 4000)
|
|
31
|
+
const count = this.s.count + 1;
|
|
32
|
+
// setTimeout(() => this.removeNotification(count), 4000)
|
|
27
33
|
const notification = {
|
|
28
34
|
count,
|
|
29
35
|
message: digg(detail, "message"),
|
|
30
36
|
title: digg(detail, "title"),
|
|
31
37
|
type: digg(detail, "type")
|
|
32
38
|
};
|
|
33
|
-
this.setState({ count, notifications: this.
|
|
39
|
+
this.setState({ count, notifications: this.s.notifications.concat([notification]) });
|
|
34
40
|
};
|
|
35
41
|
onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"));
|
|
36
42
|
removeNotification = (count) => {
|
|
37
43
|
this.setState({
|
|
38
|
-
notifications: this.
|
|
44
|
+
notifications: this.s.notifications.filter((notification) => notification.count != count)
|
|
39
45
|
});
|
|
40
46
|
};
|
|
41
47
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,IAAI,EAAC,MAAM,OAAO,CAAA;AACjC,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0CAA0C,CAAA;AACvF,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,gBAAgB,MAAM,4CAA4C,CAAA;AAEzE,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,EAAC,KAAK,EAAE,+BAA+B,EAAC;CAC/C,CAAA;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,QAAQ,EAAE,OAAO;QACjB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,EAAE;KACV;CACF,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,cAAc,CAAC,MAAM,2BAA4B,SAAQ,cAAc;IACzF,KAAK;QACH,IAAI,CAAC,SAAS,CAAC;YACb,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,EAAE;SAClB,CAAC,CAAA;QAEF,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAA;IAC9E,CAAC;IAED,MAAM;QACJ,OAAO,CACL,oBAAC,IAAI,IACH,OAAO,EAAE,QAAQ,CAAC,IAAI,EACtB,KAAK,EAAE,MAAM,CAAC,IAAI,IAEjB,IAAI,CAAC,CAAC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AY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import React, {memo} from \"react\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport {StyleSheet, View} from \"react-native\"\nimport {digg} from \"diggerize\"\nimport Notification from \"./notification\"\nimport useEventListener from \"@kaspernj/api-maker/src/use-event-listener\"\n\nconst dataSets = {\n view: {class: \"flash-notifications-container\"}\n}\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 setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventListener(globalThis, \"pushNotification\", this.tt.onPushNotification)\n }\n\n render() {\n return (\n <View\n dataSet={dataSets.view}\n style={styles.view}\n >\n {this.s.notifications.map((notification) =>\n <Notification\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 = (event) => {\n const detail = digg(event, \"detail\")\n const count = this.s.count + 1\n\n // setTimeout(() => this.removeNotification(count), 4000)\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":";;kBAEmC,OAAO"}
|
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { Pressable, Text, View } from "react-native";
|
|
2
|
-
import {
|
|
1
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
2
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
3
|
+
import React, { memo, useMemo } from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
3
5
|
import PropTypes from "prop-types";
|
|
4
6
|
import PropTypesExact from "prop-types-exact";
|
|
5
|
-
|
|
7
|
+
const styles = StyleSheet.create({
|
|
8
|
+
view: {
|
|
9
|
+
width: 300,
|
|
10
|
+
maxWidth: "100%",
|
|
11
|
+
marginBottom: 15,
|
|
12
|
+
padding: 15,
|
|
13
|
+
borderRadius: 11,
|
|
14
|
+
cursor: "pointer"
|
|
15
|
+
},
|
|
16
|
+
viewError: {
|
|
17
|
+
border: "1px solid rgba(161, 34, 32, 0.95)",
|
|
18
|
+
backgroundColor: "rgba(161, 34, 32, 0.87)"
|
|
19
|
+
},
|
|
20
|
+
viewSuccess: {
|
|
21
|
+
border: "1px solid rgba(0, 0, 0, 0.95)",
|
|
22
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)"
|
|
23
|
+
},
|
|
24
|
+
viewAlert: {
|
|
25
|
+
border: "1px solid rgba(204, 51, 0, 0.95)",
|
|
26
|
+
backgroundColor: "rgba(204, 51, 0, 0.87)"
|
|
27
|
+
},
|
|
28
|
+
titleview: {
|
|
29
|
+
marginBottom: 5
|
|
30
|
+
},
|
|
31
|
+
titleText: {
|
|
32
|
+
color: "#fff",
|
|
33
|
+
fontWeight: "bold"
|
|
34
|
+
},
|
|
35
|
+
messageText: {
|
|
36
|
+
color: "#fff"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const titleViewDataSet = { class: "notification-title" };
|
|
40
|
+
const messageViewDataSet = { class: "notification-message" };
|
|
6
41
|
export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
|
|
7
42
|
static propTypes = PropTypesExact({
|
|
8
43
|
className: PropTypes.string,
|
|
@@ -14,35 +49,27 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
14
49
|
});
|
|
15
50
|
render() {
|
|
16
51
|
const { className, message, title, type } = this.props;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return (React.createElement(Pressable, { dataSet: { class: classNames("flash-notifications-notification", className), type }, onPress: this.onRemovedClicked },
|
|
38
|
-
React.createElement(View, { style: style },
|
|
39
|
-
React.createElement(View, { dataSet: { class: "notification-title" }, style: { marginBottom: 5 } },
|
|
40
|
-
React.createElement(Text, { style: { color: "#fff", fontWeight: "bold" } }, title)),
|
|
41
|
-
React.createElement(View, { dataSet: { class: "notification-message" } },
|
|
42
|
-
React.createElement(Text, { style: { color: "#fff" } }, message)))));
|
|
52
|
+
const viewStyles = useMemo(() => {
|
|
53
|
+
const viewStyles = [styles.view];
|
|
54
|
+
if (type == "error")
|
|
55
|
+
viewStyles.push(styles.viewError);
|
|
56
|
+
if (type == "success")
|
|
57
|
+
viewStyles.push(styles.viewSuccess);
|
|
58
|
+
if (type == "alert")
|
|
59
|
+
viewStyles.push(styles.viewAlert);
|
|
60
|
+
return viewStyles;
|
|
61
|
+
}, [type]);
|
|
62
|
+
const pressableDataSet = useMemo(() => ({
|
|
63
|
+
class: classNames("flash-notifications-notification", className),
|
|
64
|
+
type
|
|
65
|
+
}), [className, type]);
|
|
66
|
+
return (React.createElement(Pressable, { dataSet: pressableDataSet, onPress: this.tt.onRemovedClicked },
|
|
67
|
+
React.createElement(View, { style: viewStyles },
|
|
68
|
+
React.createElement(View, { dataSet: titleViewDataSet, style: styles.titleview },
|
|
69
|
+
React.createElement(Text, { style: styles.titleText }, title)),
|
|
70
|
+
React.createElement(View, { dataSet: messageViewDataSet },
|
|
71
|
+
React.createElement(Text, { style: styles.messageText }, message)))));
|
|
43
72
|
}
|
|
44
|
-
onRemovedClicked = () =>
|
|
45
|
-
this.props.onRemovedClicked(this.props.notification);
|
|
46
|
-
};
|
|
73
|
+
onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification);
|
|
47
74
|
}));
|
|
48
75
|
//# sourceMappingURL=notification.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,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,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,MAAM;QAChB,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS;KAClB;IACD,SAAS,EAAE;QACT,MAAM,EAAE,mCAAmC;QAC3C,eAAe,EAAE,yBAAyB;KAC3C;IACD,WAAW,EAAE;QACX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CAAC,CAAA;YAC1D,IAAI,IAAI,IAAI,OAAO;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAEtD,OAAO,UAAU,CAAA;QACnB,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAA;QAED,MAAM,gBAAgB,GAAG,OAAO,CAC9B,GAAG,EAAE,CAAC,CAAC;YACL,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE,SAAS,CAAC;YAChE,IAAI;SACL,CAAC,EACF,CAAC,SAAS,EAAE,IAAI,CAAC,CAClB,CAAA;QAED,OAAO,CACL,oBAAC,SAAS,IAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,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,IAC1B,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,IAC5B,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 {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport React, {memo, useMemo} from \"react\"\nimport classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\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 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 {className, message, title, type} = 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}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AAuC,EAAE,KAAK,CAAC,CAAA;YAC7D,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,KAAK;QACxB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAAO;QACpB,YAAY,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI;QACd,IAAI,KAAK,CAAA;QAET,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YACzB,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;QACnC,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YAChC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;QACnC,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAA;QAC1C,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,kBAAkB,EAAE;YAChD,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI,CAAC,IAAI;gBAClB,KAAK;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;SACF,CAAC,CAAA;QAEF,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;CACF","sourcesContent":["import BaseError from \"@kaspernj/api-maker/src/base-error\"\nimport ValidationError from \"@kaspernj/api-maker/src/validation-error\"\n\nexport default class FlashMessage {\n static alert(message) {\n FlashMessage.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 FlashMessage.alert(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n FlashMessage.alert(error.message)\n } else {\n FlashMessage.alert(I18n.t(\"js.notification.couldnt_submit_because_of_validation_errors\"))\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 FlashMessage.show({type: \"success\", text: message})\n }\n\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = I18n.t(\"js.shared.alert\")\n } else if (args.type == \"error\") {\n title = I18n.t(\"js.shared.error\")\n } else if (args.type == \"success\") {\n title = I18n.t(\"js.shared.success\")\n } else {\n title = I18n.t(\"js.shared.notification\")\n }\n\n const event = new CustomEvent(\"pushNotification\", {\n detail: {\n message: args.text,\n title,\n type: args.type\n }\n })\n\n globalThis.dispatchEvent(event)\n }\n}\n"]}
|
package/link.sh
ADDED
package/package.json
CHANGED
package/src/container/index.jsx
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import {memo} from "react"
|
|
1
|
+
import React, {memo} from "react"
|
|
2
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
3
|
+
import {StyleSheet, View} from "react-native"
|
|
2
4
|
import {digg} from "diggerize"
|
|
3
5
|
import Notification from "./notification"
|
|
4
|
-
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
5
6
|
import useEventListener from "@kaspernj/api-maker/src/use-event-listener"
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
const dataSets = {
|
|
9
|
+
view: {class: "flash-notifications-container"}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const styles = StyleSheet.create({
|
|
13
|
+
view: {
|
|
14
|
+
position: "fixed",
|
|
15
|
+
zIndex: 99999,
|
|
16
|
+
top: 20,
|
|
17
|
+
right: 20
|
|
18
|
+
}
|
|
19
|
+
})
|
|
7
20
|
|
|
8
21
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
9
22
|
setup() {
|
|
@@ -12,26 +25,21 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
12
25
|
notifications: []
|
|
13
26
|
})
|
|
14
27
|
|
|
15
|
-
useEventListener(
|
|
28
|
+
useEventListener(globalThis, "pushNotification", this.tt.onPushNotification)
|
|
16
29
|
}
|
|
17
30
|
|
|
18
31
|
render() {
|
|
19
32
|
return (
|
|
20
33
|
<View
|
|
21
|
-
dataSet={
|
|
22
|
-
style={
|
|
23
|
-
position: "fixed",
|
|
24
|
-
zIndex: 99999,
|
|
25
|
-
top: 20,
|
|
26
|
-
right: 20
|
|
27
|
-
}}
|
|
34
|
+
dataSet={dataSets.view}
|
|
35
|
+
style={styles.view}
|
|
28
36
|
>
|
|
29
|
-
{this.
|
|
37
|
+
{this.s.notifications.map((notification) =>
|
|
30
38
|
<Notification
|
|
31
39
|
key={`notification-${notification.count}`}
|
|
32
40
|
message={notification.message}
|
|
33
41
|
notification={notification}
|
|
34
|
-
onRemovedClicked={this.onRemovedClicked}
|
|
42
|
+
onRemovedClicked={this.tt.onRemovedClicked}
|
|
35
43
|
title={notification.title}
|
|
36
44
|
type={notification.type}
|
|
37
45
|
/>
|
|
@@ -42,9 +50,9 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
42
50
|
|
|
43
51
|
onPushNotification = (event) => {
|
|
44
52
|
const detail = digg(event, "detail")
|
|
45
|
-
const count = this.
|
|
53
|
+
const count = this.s.count + 1
|
|
46
54
|
|
|
47
|
-
setTimeout(() => this.removeNotification(count), 4000)
|
|
55
|
+
// setTimeout(() => this.removeNotification(count), 4000)
|
|
48
56
|
|
|
49
57
|
const notification = {
|
|
50
58
|
count,
|
|
@@ -53,14 +61,14 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
53
61
|
type: digg(detail, "type")
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
this.setState({count, notifications: this.
|
|
64
|
+
this.setState({count, notifications: this.s.notifications.concat([notification])})
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"))
|
|
60
68
|
|
|
61
69
|
removeNotification = (count) => {
|
|
62
70
|
this.setState({
|
|
63
|
-
notifications: this.
|
|
71
|
+
notifications: this.s.notifications.filter((notification) => notification.count != count)
|
|
64
72
|
})
|
|
65
73
|
}
|
|
66
74
|
}))
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
import {Pressable, Text, View} from "react-native"
|
|
2
|
-
import {
|
|
1
|
+
import {Pressable, StyleSheet, Text, View} from "react-native"
|
|
2
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
3
|
+
import React, {memo, useMemo} from "react"
|
|
4
|
+
import classNames from "classnames"
|
|
3
5
|
import PropTypes from "prop-types"
|
|
4
6
|
import PropTypesExact from "prop-types-exact"
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
const styles = StyleSheet.create({
|
|
9
|
+
view: {
|
|
10
|
+
width: 300,
|
|
11
|
+
maxWidth: "100%",
|
|
12
|
+
marginBottom: 15,
|
|
13
|
+
padding: 15,
|
|
14
|
+
borderRadius: 11,
|
|
15
|
+
cursor: "pointer"
|
|
16
|
+
},
|
|
17
|
+
viewError: {
|
|
18
|
+
border: "1px solid rgba(161, 34, 32, 0.95)",
|
|
19
|
+
backgroundColor: "rgba(161, 34, 32, 0.87)"
|
|
20
|
+
},
|
|
21
|
+
viewSuccess: {
|
|
22
|
+
border: "1px solid rgba(0, 0, 0, 0.95)",
|
|
23
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)"
|
|
24
|
+
},
|
|
25
|
+
viewAlert: {
|
|
26
|
+
border: "1px solid rgba(204, 51, 0, 0.95)",
|
|
27
|
+
backgroundColor: "rgba(204, 51, 0, 0.87)"
|
|
28
|
+
},
|
|
29
|
+
titleview: {
|
|
30
|
+
marginBottom: 5
|
|
31
|
+
},
|
|
32
|
+
titleText: {
|
|
33
|
+
color: "#fff",
|
|
34
|
+
fontWeight: "bold"
|
|
35
|
+
},
|
|
36
|
+
messageText: {
|
|
37
|
+
color: "#fff"
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const titleViewDataSet = {class: "notification-title"}
|
|
42
|
+
const messageViewDataSet = {class: "notification-message"}
|
|
6
43
|
|
|
7
44
|
export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
|
|
8
45
|
static propTypes = PropTypesExact({
|
|
@@ -17,41 +54,37 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
17
54
|
render() {
|
|
18
55
|
const {className, message, title, type} = this.props
|
|
19
56
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
marginBottom: 15,
|
|
24
|
-
padding: 15,
|
|
25
|
-
borderRadius: 11,
|
|
26
|
-
cursor: "pointer"
|
|
27
|
-
}
|
|
57
|
+
const viewStyles = useMemo(
|
|
58
|
+
() => {
|
|
59
|
+
const viewStyles = [styles.view]
|
|
28
60
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (type == "success") {
|
|
35
|
-
style.border = "1px solid rgba(0 0 0 / 95%)"
|
|
36
|
-
style.background = "rgba(0 0 0 / 87%)"
|
|
37
|
-
}
|
|
61
|
+
if (type == "error") viewStyles.push(styles.viewError)
|
|
62
|
+
if (type == "success") viewStyles.push(styles.viewSuccess)
|
|
63
|
+
if (type == "alert") viewStyles.push(styles.viewAlert)
|
|
38
64
|
|
|
65
|
+
return viewStyles
|
|
66
|
+
},
|
|
67
|
+
[type]
|
|
68
|
+
)
|
|
39
69
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
70
|
+
const pressableDataSet = useMemo(
|
|
71
|
+
() => ({
|
|
72
|
+
class: classNames("flash-notifications-notification", className),
|
|
73
|
+
type
|
|
74
|
+
}),
|
|
75
|
+
[className, type]
|
|
76
|
+
)
|
|
44
77
|
|
|
45
78
|
return (
|
|
46
|
-
<Pressable dataSet={
|
|
47
|
-
<View style={
|
|
48
|
-
<View dataSet={
|
|
49
|
-
<Text style={
|
|
79
|
+
<Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>
|
|
80
|
+
<View style={viewStyles}>
|
|
81
|
+
<View dataSet={titleViewDataSet} style={styles.titleview}>
|
|
82
|
+
<Text style={styles.titleText}>
|
|
50
83
|
{title}
|
|
51
84
|
</Text>
|
|
52
85
|
</View>
|
|
53
|
-
<View dataSet={
|
|
54
|
-
<Text style={
|
|
86
|
+
<View dataSet={messageViewDataSet}>
|
|
87
|
+
<Text style={styles.messageText}>
|
|
55
88
|
{message}
|
|
56
89
|
</Text>
|
|
57
90
|
</View>
|
|
@@ -60,7 +93,5 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
|
|
|
60
93
|
)
|
|
61
94
|
}
|
|
62
95
|
|
|
63
|
-
onRemovedClicked = () =>
|
|
64
|
-
this.props.onRemovedClicked(this.props.notification)
|
|
65
|
-
}
|
|
96
|
+
onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)
|
|
66
97
|
}))
|