react-native-srschat 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/commonjs/assets/heritage.png +0 -0
  2. package/lib/commonjs/components/header.js +105 -0
  3. package/lib/commonjs/components/header.js.map +1 -0
  4. package/lib/commonjs/components/testing.js +58 -0
  5. package/lib/commonjs/components/testing.js.map +1 -0
  6. package/lib/commonjs/contexts/AppContext.js +99 -0
  7. package/lib/commonjs/contexts/AppContext.js.map +1 -0
  8. package/lib/commonjs/hooks/Stream.js +202 -0
  9. package/lib/commonjs/hooks/Stream.js.map +1 -0
  10. package/lib/commonjs/index.js +14 -154
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/layout/chatIcon.js +53 -0
  13. package/lib/commonjs/layout/chatIcon.js.map +1 -0
  14. package/lib/commonjs/layout/chatWindow.js +208 -0
  15. package/lib/commonjs/layout/chatWindow.js.map +1 -0
  16. package/lib/commonjs/layout/layout.js +35 -0
  17. package/lib/commonjs/layout/layout.js.map +1 -0
  18. package/lib/module/assets/heritage.png +0 -0
  19. package/lib/module/components/header.js +96 -0
  20. package/lib/module/components/header.js.map +1 -0
  21. package/lib/module/components/testing.js +50 -0
  22. package/lib/module/components/testing.js.map +1 -0
  23. package/lib/module/contexts/AppContext.js +90 -0
  24. package/lib/module/contexts/AppContext.js.map +1 -0
  25. package/lib/module/hooks/Stream.js +194 -0
  26. package/lib/module/hooks/Stream.js.map +1 -0
  27. package/lib/module/index.js +13 -154
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/layout/chatIcon.js +44 -0
  30. package/lib/module/layout/chatIcon.js.map +1 -0
  31. package/lib/module/layout/chatWindow.js +199 -0
  32. package/lib/module/layout/chatWindow.js.map +1 -0
  33. package/lib/module/layout/layout.js +26 -0
  34. package/lib/module/layout/layout.js.map +1 -0
  35. package/lib/typescript/components/header.d.ts +3 -0
  36. package/lib/typescript/components/header.d.ts.map +1 -0
  37. package/lib/typescript/components/testing.d.ts +6 -0
  38. package/lib/typescript/components/testing.d.ts.map +1 -0
  39. package/lib/typescript/contexts/AppContext.d.ts +6 -0
  40. package/lib/typescript/contexts/AppContext.d.ts.map +1 -0
  41. package/lib/typescript/hooks/Stream.d.ts +2 -0
  42. package/lib/typescript/hooks/Stream.d.ts.map +1 -0
  43. package/lib/typescript/index.d.ts +5 -11
  44. package/lib/typescript/index.d.ts.map +1 -1
  45. package/lib/typescript/layout/chatIcon.d.ts +3 -0
  46. package/lib/typescript/layout/chatIcon.d.ts.map +1 -0
  47. package/lib/typescript/layout/chatWindow.d.ts +6 -0
  48. package/lib/typescript/layout/chatWindow.d.ts.map +1 -0
  49. package/lib/typescript/layout/layout.d.ts +6 -0
  50. package/lib/typescript/layout/layout.d.ts.map +1 -0
  51. package/package.json +5 -3
  52. package/src/assets/heritage.png +0 -0
  53. package/src/components/header.js +89 -0
  54. package/src/components/testing.js +47 -0
  55. package/src/contexts/AppContext.js +83 -0
  56. package/src/hooks/Stream.js +198 -0
  57. package/src/index.js +18 -0
  58. package/src/layout/chatIcon.js +38 -0
  59. package/src/layout/chatWindow.js +200 -0
  60. package/src/layout/layout.js +23 -0
  61. package/src/index.tsx +0 -194
@@ -0,0 +1,199 @@
1
+ import React, { useState, useCallback, useContext } from 'react';
2
+ import { SafeAreaView, Text, StyleSheet, View, TextInput, ScrollView, KeyboardAvoidingView, Platform, TouchableOpacity, RefreshControl } from 'react-native';
3
+ import { Ionicons as Icon } from '@expo/vector-icons';
4
+ import { Header } from '../components/header';
5
+ import { AppContext } from '../contexts/AppContext';
6
+ import { Testing } from '../components/testing';
7
+ const theme = {
8
+ primaryColor: '#003764',
9
+ backgroundColor: '#f6f6f6',
10
+ textColor: '#000000',
11
+ inputBackgroundColor: '#f6f6f6'
12
+ };
13
+ export const ChatWindow = ({
14
+ onProductCardClick,
15
+ onAddToCartClick
16
+ }) => {
17
+ const {
18
+ handleSend,
19
+ messages,
20
+ setMessages,
21
+ onSendMessage,
22
+ input,
23
+ setInput
24
+ } = useContext(AppContext);
25
+ const [refreshing, setRefreshing] = useState(false);
26
+ const onRefresh = useCallback(async () => {
27
+ setRefreshing(true);
28
+ try {
29
+ const response = await onSendMessage("Hi, I'm refreshing the chat!");
30
+ setMessages(prev => [...prev, {
31
+ text: response,
32
+ isUser: false
33
+ }]);
34
+ } catch (error) {
35
+ console.error('Error refreshing chat:', error);
36
+ } finally {
37
+ setRefreshing(false);
38
+ }
39
+ }, []);
40
+ const getMessageStyle = type => [styles.messageBubble, type === "user" ? styles.userMessage : styles.aiMessage, {
41
+ backgroundColor: type === "user" ? theme.primaryColor : '#E8E8E8'
42
+ }];
43
+ const getTextStyle = type => [styles.messageText, {
44
+ color: type === "user" ? '#fff' : theme.textColor
45
+ }];
46
+ return /*#__PURE__*/React.createElement(SafeAreaView, {
47
+ style: [styles.container, {
48
+ backgroundColor: theme.backgroundColor
49
+ }]
50
+ }, /*#__PURE__*/React.createElement(View, {
51
+ style: styles.chatWindow
52
+ }, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(KeyboardAvoidingView, {
53
+ behavior: Platform.OS === 'ios' ? 'padding' : 'height',
54
+ style: styles.content,
55
+ keyboardVerticalOffset: Platform.OS === 'ios' ? 60 : 0
56
+ }, /*#__PURE__*/React.createElement(ScrollView, {
57
+ style: styles.messagesContainer,
58
+ contentContainerStyle: styles.messagesContent,
59
+ refreshControl: /*#__PURE__*/React.createElement(RefreshControl, {
60
+ refreshing: refreshing,
61
+ onRefresh: onRefresh,
62
+ tintColor: theme.primaryColor,
63
+ colors: [theme.primaryColor],
64
+ progressBackgroundColor: "#ffffff"
65
+ })
66
+ }, messages.map((msg, i) => /*#__PURE__*/React.createElement(View, {
67
+ key: i,
68
+ style: styles.messageWrapper
69
+ }, /*#__PURE__*/React.createElement(View, {
70
+ style: [getMessageStyle(msg.type), styles.messageShadow]
71
+ }, /*#__PURE__*/React.createElement(Text, {
72
+ style: getTextStyle(msg.type)
73
+ }, msg.text))))), /*#__PURE__*/React.createElement(Testing, {
74
+ onProductCardClick: onProductCardClick,
75
+ onAddToCartClick: onAddToCartClick
76
+ }), /*#__PURE__*/React.createElement(View, {
77
+ style: styles.inputWrapper
78
+ }, /*#__PURE__*/React.createElement(View, {
79
+ style: styles.inputContainer
80
+ }, /*#__PURE__*/React.createElement(TextInput, {
81
+ style: styles.input,
82
+ value: input,
83
+ onChangeText: setInput,
84
+ placeholder: "Ask a question...",
85
+ placeholderTextColor: "#999",
86
+ multiline: true
87
+ }), /*#__PURE__*/React.createElement(TouchableOpacity, {
88
+ style: styles.inputButton
89
+ }, /*#__PURE__*/React.createElement(Icon, {
90
+ name: "mic-outline",
91
+ size: 24,
92
+ color: "#8E8E93"
93
+ })), /*#__PURE__*/React.createElement(TouchableOpacity, {
94
+ style: [styles.sendButton, !input.trim() && styles.disabledButton],
95
+ onPress: handleSend,
96
+ disabled: !input.trim()
97
+ }, /*#__PURE__*/React.createElement(Icon, {
98
+ name: "paper-plane-outline",
99
+ size: 24,
100
+ color: input.trim() ? theme.primaryColor : '#8E8E93'
101
+ })))))));
102
+ };
103
+ const styles = StyleSheet.create({
104
+ container: {
105
+ flex: 1,
106
+ backgroundColor: '#FFFFFF'
107
+ },
108
+ chatWindow: {
109
+ zIndex: 1,
110
+ flex: 1,
111
+ marginTop: 40,
112
+ borderTopWidth: 1,
113
+ borderTopColor: '#DDD',
114
+ borderTopLeftRadius: 16,
115
+ borderTopRightRadius: 16,
116
+ overflow: 'hidden',
117
+ backgroundColor: theme.backgroundColor
118
+ },
119
+ content: {
120
+ flex: 1
121
+ },
122
+ messagesContainer: {
123
+ flex: 1
124
+ },
125
+ messagesContent: {
126
+ padding: 16,
127
+ paddingBottom: 32
128
+ },
129
+ messageWrapper: {
130
+ marginBottom: 16
131
+ },
132
+ messageBubble: {
133
+ maxWidth: '90%',
134
+ padding: 12,
135
+ paddingHorizontal: 16,
136
+ borderRadius: 20
137
+ },
138
+ messageShadow: {
139
+ shadowColor: '#000',
140
+ shadowOffset: {
141
+ width: 0,
142
+ height: 1
143
+ },
144
+ shadowOpacity: 0.08,
145
+ shadowRadius: 2,
146
+ elevation: 2
147
+ },
148
+ userMessage: {
149
+ alignSelf: 'flex-end',
150
+ backgroundColor: theme.primaryColor
151
+ },
152
+ aiMessage: {
153
+ alignSelf: 'flex-start',
154
+ backgroundColor: '#F2F2F7'
155
+ },
156
+ messageText: {
157
+ fontSize: 16,
158
+ lineHeight: 22
159
+ },
160
+ inputWrapper: {
161
+ backgroundColor: '#f6f6f6',
162
+ paddingHorizontal: 8,
163
+ paddingVertical: 8,
164
+ borderTopWidth: 1,
165
+ borderTopColor: 'rgba(0, 0, 0, 0.1)'
166
+ },
167
+ inputContainer: {
168
+ flexDirection: 'row',
169
+ alignItems: 'center',
170
+ paddingHorizontal: 8,
171
+ paddingVertical: 8,
172
+ backgroundColor: '#FFFFFF',
173
+ borderRadius: 16,
174
+ margin: 8,
175
+ shadowColor: '#000',
176
+ shadowOffset: {
177
+ width: 0,
178
+ height: 2
179
+ },
180
+ shadowOpacity: 0.1,
181
+ shadowRadius: 4,
182
+ elevation: 3
183
+ },
184
+ input: {
185
+ flex: 1,
186
+ fontSize: 16,
187
+ paddingVertical: 8,
188
+ paddingHorizontal: 12,
189
+ color: '#000000'
190
+ },
191
+ sendButton: {
192
+ padding: 6,
193
+ marginLeft: 'auto'
194
+ },
195
+ disabledButton: {
196
+ opacity: 0.7
197
+ }
198
+ });
199
+ //# sourceMappingURL=chatWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useState","useCallback","useContext","SafeAreaView","Text","StyleSheet","View","TextInput","ScrollView","KeyboardAvoidingView","Platform","TouchableOpacity","RefreshControl","Ionicons","Icon","Header","AppContext","Testing","theme","primaryColor","backgroundColor","textColor","inputBackgroundColor","ChatWindow","onProductCardClick","onAddToCartClick","handleSend","messages","setMessages","onSendMessage","input","setInput","refreshing","setRefreshing","onRefresh","response","prev","text","isUser","error","console","getMessageStyle","type","styles","messageBubble","userMessage","aiMessage","getTextStyle","messageText","color","createElement","style","container","chatWindow","behavior","OS","content","keyboardVerticalOffset","messagesContainer","contentContainerStyle","messagesContent","refreshControl","tintColor","colors","progressBackgroundColor","map","msg","i","key","messageWrapper","messageShadow","inputWrapper","inputContainer","value","onChangeText","placeholder","placeholderTextColor","multiline","inputButton","name","size","sendButton","trim","disabledButton","onPress","disabled","create","flex","zIndex","marginTop","borderTopWidth","borderTopColor","borderTopLeftRadius","borderTopRightRadius","overflow","padding","paddingBottom","marginBottom","maxWidth","paddingHorizontal","borderRadius","shadowColor","shadowOffset","width","height","shadowOpacity","shadowRadius","elevation","alignSelf","fontSize","lineHeight","paddingVertical","flexDirection","alignItems","margin","marginLeft","opacity"],"sourceRoot":"../../../src","sources":["layout/chatWindow.js"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,QAAQ,OAAO;AAChE,SAASC,YAAY,EAAEC,IAAI,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,UAAU,EAAEC,oBAAoB,EACtFC,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,QAAS,cAAc;AACrE,SAASC,QAAQ,IAAIC,IAAI,QAAQ,oBAAoB;AACrD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,OAAO,QAAQ,uBAAuB;AAE/C,MAAMC,KAAK,GAAG;EACZC,YAAY,EAAE,SAAS;EACvBC,eAAe,EAAE,SAAS;EAC1BC,SAAS,EAAE,SAAS;EACpBC,oBAAoB,EAAE;AACxB,CAAC;AAED,OAAO,MAAMC,UAAU,GAAGA,CAAC;EAAEC,kBAAkB;EAAEC;AAAiB,CAAC,KAAK;EACtE,MAAM;IAAEC,UAAU;IAAEC,QAAQ;IAAEC,WAAW;IAAEC,aAAa;IAAEC,KAAK;IAAEC;EAAS,CAAC,GA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AClB,CAAC;EACDnB,cAAc,EAAE;IACdwC,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBd,iBAAiB,EAAE,CAAC;IACpBY,eAAe,EAAE,CAAC;IAClB3F,eAAe,EAAE,SAAS;IAC1BgF,YAAY,EAAE,EAAE;IAChBc,MAAM,EAAE,CAAC;IACTb,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MACZC,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE;IACV,CAAC;IACDC,aAAa,EAAE,GAAG;IAClBC,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE;EACb,CAAC;EACD7E,KAAK,EAAE;IACLyD,IAAI,EAAE,CAAC;IACPsB,QAAQ,EAAE,EAAE;IACZE,eAAe,EAAE,CAAC;IAClBZ,iBAAiB,EAAE,EAAE;IACrBlD,KAAK,EAAE;EACT,CAAC;EACDgC,UAAU,EAAE;IACVc,OAAO,EAAE,CAAC;IACVoB,UAAU,EAAE;EACd,CAAC;EACDhC,cAAc,EAAE;IACdiC,OAAO,EAAE;EACX;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import React, { useState, useCallback, useContext } from 'react';
2
+ import { SafeAreaView, Text, StyleSheet, View, TextInput, ScrollView, KeyboardAvoidingView, Platform, TouchableOpacity, RefreshControl } from 'react-native';
3
+ import { Ionicons as Icon } from '@expo/vector-icons';
4
+ import { ChatWindow } from './chatWindow';
5
+ import { AppContext } from '../contexts/AppContext';
6
+ import { ChatIcon } from './chatIcon';
7
+ export const Layout = ({
8
+ onProductCardClick,
9
+ onAddToCartClick
10
+ }) => {
11
+ const {
12
+ showModal
13
+ } = useContext(AppContext);
14
+ return /*#__PURE__*/React.createElement(View, {
15
+ style: styles.container
16
+ }, showModal === "Icon" ? /*#__PURE__*/React.createElement(ChatIcon, null) : /*#__PURE__*/React.createElement(ChatWindow, {
17
+ onProductCardClick: onProductCardClick,
18
+ onAddToCartClick: onAddToCartClick
19
+ }));
20
+ };
21
+ const styles = StyleSheet.create({
22
+ container: {
23
+ flex: 1
24
+ }
25
+ });
26
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useState","useCallback","useContext","SafeAreaView","Text","StyleSheet","View","TextInput","ScrollView","KeyboardAvoidingView","Platform","TouchableOpacity","RefreshControl","Ionicons","Icon","ChatWindow","AppContext","ChatIcon","Layout","onProductCardClick","onAddToCartClick","showModal","createElement","style","styles","container","create","flex"],"sourceRoot":"../../../src","sources":["layout/layout.js"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,QAAQ,OAAO;AAChE,SAASC,YAAY,EAAEC,IAAI,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,UAAU,EAAEC,oBAAoB,EACxFC,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,QAAS,cAAc;AACnE,SAASC,QAAQ,IAAIC,IAAI,QAAQ,oBAAoB;AACrD,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,QAAQ,YAAY;AAErC,OAAO,MAAMC,MAAM,GAAGA,CAAC;EAAEC,kBAAkB;EAAEC;AAAiB,CAAC,KAAK;EAChE,MAAM;IAAEC;EAAU,CAAC,GAAGnB,UAAU,CAACc,UAAU,CAAC;EAE5C,oBACEjB,KAAA,CAAAuB,aAAA,CAAChB,IAAI;IAACiB,KAAK,EAAEC,MAAM,CAACC;EAAU,GAC3BJ,SAAS,KAAK,MAAM,gBAAGtB,KAAA,CAAAuB,aAAA,CAACL,QAAQ,MAAE,CAAC,gBAAGlB,KAAA,CAAAuB,aAAA,CAACP,UAAU;IAACI,kBAAkB,EAAEA,kBAAmB;IAACC,gBAAgB,EAAEA;EAAiB,CAAC,CAC3H,CAAC;AAEb,CAAC;AAED,MAAMI,MAAM,GAAGnB,UAAU,CAACqB,MAAM,CAAC;EAC7BD,SAAS,EAAE;IACTE,IAAI,EAAE;EACR;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export function Header(): React.JSX.Element;
2
+ import React from 'react';
3
+ //# sourceMappingURL=header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../src/components/header.js"],"names":[],"mappings":"AAKO,4CA+BN;kBApCiC,OAAO"}
@@ -0,0 +1,6 @@
1
+ export function Testing({ onProductCardClick, onAddToCartClick }: {
2
+ onProductCardClick: any;
3
+ onAddToCartClick: any;
4
+ }): React.JSX.Element;
5
+ import React from 'react';
6
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/components/testing.js"],"names":[],"mappings":"AAGO;;;sBAgCN;kBAnCiB,OAAO"}
@@ -0,0 +1,6 @@
1
+ export const AppContext: React.Context<any>;
2
+ export function AppProvider({ children }: {
3
+ children: any;
4
+ }): React.JSX.Element;
5
+ import React from "react";
6
+ //# sourceMappingURL=AppContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/AppContext.js"],"names":[],"mappings":"AAEA,4CAA0C;AAEnC;;sBA8EN;kBAlFoE,OAAO"}
@@ -0,0 +1,2 @@
1
+ export function useWebSocketMessage(): void;
2
+ //# sourceMappingURL=Stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stream.d.ts","sourceRoot":"","sources":["../../../src/hooks/Stream.js"],"names":[],"mappings":"AAGA,4CAkMC"}
@@ -1,13 +1,7 @@
1
+ export function Chat({ data, onProductCardClick, onAddToCartClick }: {
2
+ data: any;
3
+ onProductCardClick: any;
4
+ onAddToCartClick: any;
5
+ }): React.JSX.Element;
1
6
  import React from 'react';
2
- interface ChatProps {
3
- onSendMessage: (message: string) => Promise<string>;
4
- placeholder?: string;
5
- theme?: {
6
- primaryColor?: string;
7
- backgroundColor?: string;
8
- textColor?: string;
9
- };
10
- }
11
- export declare const Chat: React.FC<ChatProps>;
12
- export {};
13
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,UAAU,SAAS;IACjB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAQD,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA2EpC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":"AAOO;;;;sBAON;kBAd4C,OAAO"}
@@ -0,0 +1,3 @@
1
+ export function ChatIcon(): React.JSX.Element;
2
+ import React from 'react';
3
+ //# sourceMappingURL=chatIcon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatIcon.d.ts","sourceRoot":"","sources":["../../../src/layout/chatIcon.js"],"names":[],"mappings":"AAKO,8CAUN;kBAfiC,OAAO"}
@@ -0,0 +1,6 @@
1
+ export function ChatWindow({ onProductCardClick, onAddToCartClick }: {
2
+ onProductCardClick: any;
3
+ onAddToCartClick: any;
4
+ }): React.JSX.Element;
5
+ import React from 'react';
6
+ //# sourceMappingURL=chatWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatWindow.d.ts","sourceRoot":"","sources":["../../../src/layout/chatWindow.js"],"names":[],"mappings":"AAeO;;;sBA0FN;kBAzGwD,OAAO"}
@@ -0,0 +1,6 @@
1
+ export function Layout({ onProductCardClick, onAddToCartClick }: {
2
+ onProductCardClick: any;
3
+ onAddToCartClick: any;
4
+ }): React.JSX.Element;
5
+ import React from 'react';
6
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/layout/layout.js"],"names":[],"mappings":"AAQO;;;sBAQN;kBAhBwD,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-srschat",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "description": "A modern, sophisticated chat interface for React Native",
6
6
  "main": "lib/commonjs/index",
@@ -33,11 +33,12 @@
33
33
  "@babel/preset-env": "^7.20.0",
34
34
  "@babel/preset-react": "^7.20.0",
35
35
  "@babel/preset-typescript": "^7.20.0",
36
- "@react-native/eslint-config": "^0.72.2",
37
36
  "@react-native/babel-preset": "^0.73.18",
38
37
  "@react-native/codegen": "^0.73.3",
38
+ "@react-native/eslint-config": "^0.72.2",
39
39
  "@types/react": "^18.2.0",
40
40
  "@types/react-native": "~0.72.8",
41
+ "@types/react-native-vector-icons": "^6.4.18",
41
42
  "@typescript-eslint/eslint-plugin": "^5.0.0",
42
43
  "@typescript-eslint/parser": "^5.0.0",
43
44
  "eslint": "^8.0.0",
@@ -58,7 +59,8 @@
58
59
  },
59
60
  "homepage": "https://github.com/alxkai/react-native-srschat#readme",
60
61
  "dependencies": {
61
- "@babel/runtime": "^7.20.0"
62
+ "@babel/runtime": "^7.20.0",
63
+ "@expo/vector-icons": "^14.0.4"
62
64
  },
63
65
  "react-native-builder-bob": {
64
66
  "source": "src",
Binary file
@@ -0,0 +1,89 @@
1
+ import React, { useContext } from 'react';
2
+ import { View, Text, TouchableOpacity, StyleSheet, Image } from 'react-native';
3
+ import { Ionicons as Icon } from '@expo/vector-icons';
4
+ import { AppContext } from '../contexts/AppContext';
5
+
6
+ export const Header = () => {
7
+ const { setShowModal } = useContext(AppContext);
8
+
9
+ return (
10
+ <View style={styles.header}>
11
+ {/* Logo on the left */}
12
+ <View style={styles.section}>
13
+ <Image source={require('../assets/heritage.png')} style={styles.logo} />
14
+ </View>
15
+
16
+ {/* Title in the center */}
17
+ <View style={[styles.section, styles.titleContainer]}>
18
+ <View style={styles.titleWrapper}>
19
+ <Text style={styles.title}>
20
+ Poseidon
21
+ </Text>
22
+ <Text style={styles.betaText}><Icon style={styles.icon} name="sparkles-outline" size={10} color="#007AFF" />beta</Text>
23
+ </View>
24
+ </View>
25
+
26
+ {/* Close button on the right */}
27
+ <View style={styles.iconsSection}>
28
+ <TouchableOpacity onPress={() => setShowModal("Icon")}>
29
+ <Icon name="trash" size={24} color="gray" />
30
+ </TouchableOpacity>
31
+ <TouchableOpacity onPress={() => setShowModal("Icon")}>
32
+ <Icon name="chevron-down" size={24} color="gray" />
33
+ </TouchableOpacity>
34
+ </View>
35
+ </View>
36
+ );
37
+ };
38
+
39
+ const styles = StyleSheet.create({
40
+ header: {
41
+ flexDirection: 'row',
42
+ alignItems: 'center',
43
+ backgroundColor: '#f6f6f6',
44
+ padding: 16,
45
+ borderBottomWidth: 1,
46
+ borderBottomColor: '#ddd',
47
+ },
48
+ section: {
49
+ flex: 1,
50
+ alignItems: 'center',
51
+ },
52
+ iconsSection: {
53
+ flex: 1,
54
+ display: 'flex',
55
+ flexDirection: 'row',
56
+ alignItems: 'center',
57
+ justifyContent: 'flex-end'
58
+ },
59
+ logo: {
60
+ width: 100,
61
+ height: 40,
62
+ resizeMode: 'contain',
63
+ },
64
+ icon: {
65
+ paddingLeft: 2,
66
+ paddingRight: 2
67
+ },
68
+ titleContainer: {
69
+ flex: 2, // Slightly larger space for the title
70
+ },
71
+ titleWrapper: {
72
+ alignItems: 'center',
73
+ justifyContent: 'center',
74
+ },
75
+ title: {
76
+ fontSize: 20,
77
+ fontWeight: 'medium',
78
+ color: '#000',
79
+ textAlign: 'center',
80
+ flexDirection: 'row',
81
+ },
82
+ betaText: {
83
+ fontSize: 12,
84
+ color: 'gray',
85
+ position: 'absolute',
86
+ top: -10,
87
+ right: -35,
88
+ },
89
+ });
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { View, Button, StyleSheet } from 'react-native';
3
+
4
+ export const Testing = ({ onProductCardClick, onAddToCartClick }) => {
5
+
6
+ const product = {
7
+ "part_number": "AEQO177",
8
+ "inventory_info": {
9
+ "default_uom": "EA",
10
+ "is_valid": true,
11
+ "info_by_uom": {
12
+ "EA": {
13
+ "gross_price": 7.83,
14
+ "net_price": 7.83,
15
+ "is_on_sale": false,
16
+ "quantity_available": 0,
17
+ "discounts": null
18
+ }
19
+ }
20
+ },
21
+ "product_details": {
22
+ "product_name": "Aladdin Hayward SPX1600S SuperPump Lid Gasket | O-177-2",
23
+ "part_number": "AEQO177",
24
+ "manufacturer_id": "O-177-2",
25
+ "heritage_link": "https://www.heritagepoolplus.com/aeqo177-aladdin-o-ring-o-177-o-177-2-o-177-2",
26
+ "image_url": "https://media.heritageplus.com/image/upload/v1668157956/image/AEQO177_0.jpg"
27
+ }
28
+ }
29
+
30
+ return (
31
+ <View style={styles.container}>
32
+ <Button title="Product Card Click" onPress={() => onProductCardClick(product)} />
33
+ <Button title="Add to Cart" onPress={() => onAddToCartClick(product)} />
34
+ </View>
35
+ );
36
+ };
37
+
38
+ const styles = StyleSheet.create({
39
+ container: {
40
+ flexDirection: 'row',
41
+ justifyContent: 'space-evenly',
42
+ marginVertical: 10,
43
+ paddingHorizontal: 16,
44
+ borderTopWidth: 1,
45
+ borderTopColor: '#DDD',
46
+ },
47
+ });
@@ -0,0 +1,83 @@
1
+ import React, {createContext, useContext, useState, useEffect } from "react";
2
+
3
+ export const AppContext = createContext();
4
+
5
+ export const AppProvider = ({ children }) => {
6
+
7
+ const [showModal, setShowModal] = useState("Icon");
8
+
9
+ const [input, setInput] = useState('');
10
+ const [messages, setMessages] = useState([
11
+ {type: "ai", text: "Hi there šŸ‘‹ I’m Poseidon, your Heritage Pool+ AI Agent. I can help you during your online visit with Product and Account information. How can I help you today?"},
12
+ {type: "user", text: "Do you carry Hayward super pumps?"},
13
+ {type: "ai", text: "Could you provide more details on the specific model or horsepower you are interested in for the Hayward Super Pump? We have various models with different features, such as variable speed settings and different horsepower ratings. Alternatively, I can offer you some recommendations right away to help you decide."},
14
+ ]);
15
+
16
+ const handleSend = async () => {
17
+ if (!input.trim()) return;
18
+
19
+ const userMessage = input;
20
+ setInput('');
21
+
22
+ // Add user message to the list
23
+ setMessages((prev) => [...prev, { type: "user", text: userMessage }]);
24
+
25
+ try {
26
+ // Add placeholder for AI message
27
+ setMessages((prev) => [...prev, { type: "ai", text: '' }]);
28
+
29
+ // Simulate response with streaming
30
+ const response = await onSendMessage(userMessage, (chunk) => {
31
+ setMessages((prev) => {
32
+ const newMessages = [...prev];
33
+ const lastMessage = newMessages[newMessages.length - 1];
34
+ if (lastMessage && lastMessage.type === "ai") {
35
+ lastMessage.text += chunk;
36
+ }
37
+ return newMessages;
38
+ });
39
+ });
40
+
41
+ // Finalize AI response
42
+ setMessages((prev) => {
43
+ const newMessages = [...prev];
44
+ const lastMessage = newMessages[newMessages.length - 1];
45
+ if (lastMessage && lastMessage.type === "ai" && lastMessage.text !== response) {
46
+ lastMessage.text = response;
47
+ }
48
+ return newMessages;
49
+ });
50
+ } catch (error) {
51
+ console.error('Error sending message:', error);
52
+ }
53
+ };
54
+
55
+ const onSendMessage = async (message, onStream) => {
56
+ try {
57
+ if (onStream) {
58
+ const words = `You said: ${message}`.split(' ');
59
+ for (const word of words) {
60
+ await new Promise((resolve) => setTimeout(resolve, 100));
61
+ onStream(word + ' ');
62
+ }
63
+ return `You said: ${message}`;
64
+ }
65
+
66
+ await new Promise((resolve) => setTimeout(resolve, 1000));
67
+ return `You said: ${message}`;
68
+ } catch (error) {
69
+ console.error('Error handling message:', error);
70
+ return 'Error processing message';
71
+ }
72
+ };
73
+
74
+
75
+ return (
76
+ <AppContext.Provider
77
+ value={{ showModal, setShowModal, messages, setMessages, handleSend, onSendMessage, input, setInput
78
+ }}
79
+ >
80
+ {children}
81
+ </AppContext.Provider>
82
+ );
83
+ };