@plusscommunities/pluss-core-app 6.1.12-beta.0 → 6.1.13
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.
|
@@ -4,7 +4,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
4
4
|
import React, { Component } from 'react';
|
|
5
5
|
import { View, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
6
6
|
import { Icon } from 'react-native-elements';
|
|
7
|
-
import * as DocumentPicker from 'expo-document-picker';
|
|
7
|
+
// import * as DocumentPicker from 'expo-document-picker';
|
|
8
8
|
import { connect } from 'react-redux';
|
|
9
9
|
import Config from '../config';
|
|
10
10
|
import { fileActions } from '../apis';
|
|
@@ -23,21 +23,22 @@ class DocumentUploader extends Component {
|
|
|
23
23
|
allowedTypes,
|
|
24
24
|
multiple
|
|
25
25
|
} = this.props;
|
|
26
|
-
try {
|
|
27
|
-
const result = await DocumentPicker.getDocumentAsync({
|
|
28
|
-
type: allowedTypes,
|
|
29
|
-
copyToCacheDirectory: true,
|
|
30
|
-
multiple: multiple || false
|
|
31
|
-
});
|
|
32
|
-
// console.log('pickDocument', JSON.stringify(result, null, 2));
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
// try {
|
|
28
|
+
// const result = await DocumentPicker.getDocumentAsync({
|
|
29
|
+
// type: allowedTypes,
|
|
30
|
+
// copyToCacheDirectory: true,
|
|
31
|
+
// multiple: multiple || false,
|
|
32
|
+
// });
|
|
33
|
+
// // console.log('pickDocument', JSON.stringify(result, null, 2));
|
|
34
|
+
|
|
35
|
+
// if (!result.canceled) {
|
|
36
|
+
// await this.handleDocumentPicked(result);
|
|
37
|
+
// }
|
|
38
|
+
// } catch (error) {
|
|
39
|
+
// console.log('Document picker error:', error);
|
|
40
|
+
// this.props.onUploadFailed(null, error.message);
|
|
41
|
+
// }
|
|
41
42
|
});
|
|
42
43
|
_defineProperty(this, "handleDocumentPicked", async documentResult => {
|
|
43
44
|
const {
|
|
@@ -56,14 +57,30 @@ class DocumentUploader extends Component {
|
|
|
56
57
|
const uploadPromises = assets.map(async asset => {
|
|
57
58
|
const {
|
|
58
59
|
name,
|
|
59
|
-
uri
|
|
60
|
+
uri,
|
|
61
|
+
mimeType
|
|
60
62
|
} = asset;
|
|
63
|
+
let file, fileExt;
|
|
64
|
+
if (name && name.includes('.')) {
|
|
65
|
+
const lastDotIndex = name.lastIndexOf('.');
|
|
66
|
+
file = name.substring(0, lastDotIndex);
|
|
67
|
+
fileExt = name.substring(lastDotIndex + 1);
|
|
68
|
+
} else {
|
|
69
|
+
// Fallback: extract extension from mimeType
|
|
70
|
+
file = name || 'document';
|
|
71
|
+
if (mimeType) {
|
|
72
|
+
const mimeTypeParts = mimeType.split('/');
|
|
73
|
+
// Handle specific MIME type mappings
|
|
74
|
+
if (mimeType === 'application/pdf') fileExt = 'pdf';else if (mimeType.startsWith('image/')) fileExt = mimeTypeParts[1];else if (mimeType.startsWith('text/')) fileExt = 'txt';else fileExt = mimeTypeParts[1] || 'pdf';
|
|
75
|
+
} else {
|
|
76
|
+
fileExt = 'pdf';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
61
79
|
|
|
62
80
|
// Generate a unique filename if not provided
|
|
63
|
-
const
|
|
64
|
-
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}_${Date.now()}.${fileExt}`;
|
|
81
|
+
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}.${fileExt}`;
|
|
65
82
|
const uploadUri = fileActions.getUploadUrl(userId, fileName);
|
|
66
|
-
// console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName }, null, 2));
|
|
83
|
+
// console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName, mimeType, file, fileExt }, null, 2));
|
|
67
84
|
|
|
68
85
|
try {
|
|
69
86
|
// Notify parent component that upload has started for this file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Component","View","TouchableOpacity","Text","StyleSheet","ActivityIndicator","Icon","DocumentPicker","connect","Config","fileActions","getValueOrDefault","TEXT_DARK","getMainBrandingColourFromState","DEFAULT_DOCUMENT_NAME","DocumentUploader","constructor","args","_defineProperty","isUploading","uploadProgress","allowedTypes","multiple","props","result","getDocumentAsync","type","copyToCacheDirectory","canceled","handleDocumentPicked","error","console","log","onUploadFailed","message","documentResult","assets","userId","setState","uploadPromises","map","asset","name","uri","file","fileExt","split","fileName","Date","now","uploadUri","getUploadUrl","onUploadStarted","toUpperCase","res","uploadUserMediaWithProgress","progress","onUploadProgress","fileUrl","env","baseUploadsUrl","key","onUploadSuccess","success","url","results","Promise","all","buttonTitle","buttonStyle","buttonTextStyle","disabled","state","mainColor","createElement","style","styles","uploadButton","borderColor","onPress","pickDocument","activeOpacity","buttonContent","color","size","icon","buttonText","progressContainer","progressBar","progressFill","width","progressText","Math","round","render","container","renderUploadButton","renderProgress","create","marginVertical","flexDirection","alignItems","justifyContent","paddingVertical","paddingHorizontal","borderRadius","backgroundColor","borderWidth","fontSize","fontWeight","marginLeft","marginRight","marginTop","height","overflow","mapStateToProps","user","colourBrandingMain"],"sources":["DocumentUploader.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { View, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\nimport { Icon } from 'react-native-elements';\nimport * as DocumentPicker from 'expo-document-picker';\nimport { connect } from 'react-redux';\nimport Config from '../config';\nimport { fileActions } from '../apis';\nimport { getValueOrDefault } from '../helper';\nimport { TEXT_DARK, getMainBrandingColourFromState } from '../colours';\n\nconst DEFAULT_DOCUMENT_NAME = 'document';\n\nclass DocumentUploader extends Component {\n static defaultProps = {\n allowedTypes: ['application/pdf'],\n buttonTitle: 'Upload Document',\n buttonStyle: {},\n buttonTextStyle: {},\n onUploadStarted: () => {},\n onUploadSuccess: () => {},\n onUploadFailed: () => {},\n onUploadProgress: null,\n userId: null,\n fileName: null,\n disabled: false,\n };\n\n state = {\n isUploading: false,\n uploadProgress: 0,\n };\n\n pickDocument = async () => {\n const { allowedTypes, multiple } = this.props;\n\n try {\n const result = await DocumentPicker.getDocumentAsync({\n type: allowedTypes,\n copyToCacheDirectory: true,\n multiple: multiple || false,\n });\n // console.log('pickDocument', JSON.stringify(result, null, 2));\n\n if (!result.canceled) {\n await this.handleDocumentPicked(result);\n }\n } catch (error) {\n console.log('Document picker error:', error);\n this.props.onUploadFailed(null, error.message);\n }\n };\n\n handleDocumentPicked = async documentResult => {\n const { assets } = documentResult;\n const { userId } = this.props;\n\n try {\n this.setState({ isUploading: true, uploadProgress: 0 });\n\n // Process each asset in parallel\n const uploadPromises = assets.map(async asset => {\n const { name, uri } = asset;\n\n // Generate a unique filename if not provided\n const [file, fileExt] = name.split('.');\n const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}_${Date.now()}.${fileExt}`;\n const uploadUri = fileActions.getUploadUrl(userId, fileName);\n // console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName }, null, 2));\n\n try {\n // Notify parent component that upload has started for this file\n this.props.onUploadStarted(uploadUri, uri, file, fileExt.toUpperCase());\n\n const res = await fileActions.uploadUserMediaWithProgress(uri, uploadUri, progress => {\n if (this.props.onUploadProgress) this.props.onUploadProgress(progress);\n });\n\n const fileUrl = Config.env.baseUploadsUrl + res.key;\n this.props.onUploadSuccess(fileUrl, uploadUri);\n console.log('Upload success', fileUrl);\n return { success: true, url: fileUrl, uploadUri };\n } catch (error) {\n console.error(`Upload failed for ${name}:`, error);\n this.props.onUploadFailed(uploadUri, error.message);\n return { success: false, error, uploadUri };\n }\n });\n\n // Wait for all uploads to complete\n const results = await Promise.all(uploadPromises);\n return results;\n } catch (error) {\n console.error('Document upload error:', error);\n return [];\n } finally {\n this.setState({ isUploading: false, uploadProgress: 0 });\n }\n };\n\n renderUploadButton = () => {\n const { buttonTitle, buttonStyle, buttonTextStyle, disabled } = this.props;\n const { isUploading } = this.state;\n const mainColor = getMainBrandingColourFromState(this.props);\n\n return (\n <TouchableOpacity\n style={[styles.uploadButton, { borderColor: mainColor }, buttonStyle]}\n onPress={this.pickDocument}\n disabled={isUploading || disabled}\n activeOpacity={0.7}\n >\n <View style={styles.buttonContent}>\n {isUploading ? (\n <ActivityIndicator color={mainColor} />\n ) : (\n <Icon name=\"attachment\" type=\"entypo\" color={mainColor} size={18} style={styles.icon} />\n )}\n <Text style={[styles.buttonText, { color: mainColor }, buttonTextStyle]}>{buttonTitle}</Text>\n </View>\n </TouchableOpacity>\n );\n };\n\n renderProgress = () => {\n const { uploadProgress } = this.state;\n if (uploadProgress <= 0 || uploadProgress >= 1) return null;\n\n return (\n <View style={styles.progressContainer}>\n <View style={styles.progressBar}>\n <View style={[styles.progressFill, { width: `${uploadProgress * 100}%` }]} />\n </View>\n <Text style={styles.progressText}>{Math.round(uploadProgress * 100)}%</Text>\n </View>\n );\n };\n\n render() {\n return (\n <View style={styles.container}>\n {this.renderUploadButton()}\n {this.renderProgress()}\n </View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n container: {\n marginVertical: 10,\n },\n uploadButton: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n paddingVertical: 8,\n paddingHorizontal: 16,\n borderRadius: 6,\n backgroundColor: '#fff',\n borderWidth: 1,\n borderColor: '#007AFF',\n },\n buttonContent: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n buttonText: {\n color: '#fff',\n fontSize: 16,\n fontWeight: '500',\n marginLeft: 8,\n },\n icon: {\n marginRight: 8,\n },\n progressContainer: {\n marginTop: 8,\n alignItems: 'center',\n },\n progressBar: {\n height: 4,\n width: '100%',\n backgroundColor: '#E0E0E0',\n borderRadius: 2,\n overflow: 'hidden',\n },\n progressFill: {\n height: '100%',\n backgroundColor: '#4CAF50',\n },\n progressText: {\n marginTop: 4,\n fontSize: 12,\n color: TEXT_DARK,\n },\n});\n\nconst mapStateToProps = state => {\n const { user } = state;\n return {\n user,\n colourBrandingMain: getMainBrandingColourFromState(state),\n };\n};\n\nexport default connect(mapStateToProps)(DocumentUploader);\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,IAAI,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,UAAU,EAAEC,iBAAiB,QAAQ,cAAc;AAC1F,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,OAAO,KAAKC,cAAc,MAAM,sBAAsB;AACtD,SAASC,OAAO,QAAQ,aAAa;AACrC,OAAOC,MAAM,MAAM,WAAW;AAC9B,SAASC,WAAW,QAAQ,SAAS;AACrC,SAASC,iBAAiB,QAAQ,WAAW;AAC7C,SAASC,SAAS,EAAEC,8BAA8B,QAAQ,YAAY;AAEtE,MAAMC,qBAAqB,GAAG,UAAU;AAExC,MAAMC,gBAAgB,SAASf,SAAS,CAAC;EAAAgB,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAAC,eAAA,gBAe/B;MACNC,WAAW,EAAE,KAAK;MAClBC,cAAc,EAAE;IAClB,CAAC;IAAAF,eAAA,uBAEc,YAAY;MACzB,MAAM;QAAEG,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAI,CAACC,KAAK;MAE7C,IAAI;QACF,MAAMC,MAAM,GAAG,MAAMjB,cAAc,CAACkB,gBAAgB,CAAC;UACnDC,IAAI,EAAEL,YAAY;UAClBM,oBAAoB,EAAE,IAAI;UAC1BL,QAAQ,EAAEA,QAAQ,IAAI;QACxB,CAAC,CAAC;QACF;;QAEA,IAAI,CAACE,MAAM,CAACI,QAAQ,EAAE;UACpB,MAAM,IAAI,CAACC,oBAAoB,CAACL,MAAM,CAAC;QACzC;MACF,CAAC,CAAC,OAAOM,KAAK,EAAE;QACdC,OAAO,CAACC,GAAG,CAAC,wBAAwB,EAAEF,KAAK,CAA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pBC,UAAU,EAAE;EACd,CAAC;EACDf,UAAU,EAAE;IACVH,KAAK,EAAE,MAAM;IACbyB,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,KAAK;IACjBC,UAAU,EAAE;EACd,CAAC;EACDzB,IAAI,EAAE;IACJ0B,WAAW,EAAE;EACf,CAAC;EACDxB,iBAAiB,EAAE;IACjByB,SAAS,EAAE,CAAC;IACZX,UAAU,EAAE;EACd,CAAC;EACDb,WAAW,EAAE;IACXyB,MAAM,EAAE,CAAC;IACTvB,KAAK,EAAE,MAAM;IACbgB,eAAe,EAAE,SAAS;IAC1BD,YAAY,EAAE,CAAC;IACfS,QAAQ,EAAE;EACZ,CAAC;EACDzB,YAAY,EAAE;IACZwB,MAAM,EAAE,MAAM;IACdP,eAAe,EAAE;EACnB,CAAC;EACDf,YAAY,EAAE;IACZqB,SAAS,EAAE,CAAC;IACZJ,QAAQ,EAAE,EAAE;IACZzB,KAAK,EAAEvE;EACT;AACF,CAAC,CAAC;AAEF,MAAMuG,eAAe,GAAG3C,KAAK,IAAI;EAC/B,MAAM;IAAE4C;EAAK,CAAC,GAAG5C,KAAK;EACtB,OAAO;IACL4C,IAAI;IACJC,kBAAkB,EAAExG,8BAA8B,CAAC2D,KAAK;EAC1D,CAAC;AACH,CAAC;AAED,eAAehE,OAAO,CAAC2G,eAAe,CAAC,CAACpG,gBAAgB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","Component","View","TouchableOpacity","Text","StyleSheet","ActivityIndicator","Icon","connect","Config","fileActions","getValueOrDefault","TEXT_DARK","getMainBrandingColourFromState","DEFAULT_DOCUMENT_NAME","DocumentUploader","constructor","args","_defineProperty","isUploading","uploadProgress","allowedTypes","multiple","props","documentResult","assets","userId","setState","uploadPromises","map","asset","name","uri","mimeType","file","fileExt","includes","lastDotIndex","lastIndexOf","substring","mimeTypeParts","split","startsWith","fileName","uploadUri","getUploadUrl","onUploadStarted","toUpperCase","res","uploadUserMediaWithProgress","progress","onUploadProgress","fileUrl","env","baseUploadsUrl","key","onUploadSuccess","console","log","success","url","error","onUploadFailed","message","results","Promise","all","buttonTitle","buttonStyle","buttonTextStyle","disabled","state","mainColor","createElement","style","styles","uploadButton","borderColor","onPress","pickDocument","activeOpacity","buttonContent","color","type","size","icon","buttonText","progressContainer","progressBar","progressFill","width","progressText","Math","round","render","container","renderUploadButton","renderProgress","create","marginVertical","flexDirection","alignItems","justifyContent","paddingVertical","paddingHorizontal","borderRadius","backgroundColor","borderWidth","fontSize","fontWeight","marginLeft","marginRight","marginTop","height","overflow","mapStateToProps","user","colourBrandingMain"],"sources":["DocumentUploader.js"],"sourcesContent":["import React, { Component } from 'react';\nimport { View, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\nimport { Icon } from 'react-native-elements';\n// import * as DocumentPicker from 'expo-document-picker';\nimport { connect } from 'react-redux';\nimport Config from '../config';\nimport { fileActions } from '../apis';\nimport { getValueOrDefault } from '../helper';\nimport { TEXT_DARK, getMainBrandingColourFromState } from '../colours';\n\nconst DEFAULT_DOCUMENT_NAME = 'document';\n\nclass DocumentUploader extends Component {\n static defaultProps = {\n allowedTypes: ['application/pdf'],\n buttonTitle: 'Upload Document',\n buttonStyle: {},\n buttonTextStyle: {},\n onUploadStarted: () => {},\n onUploadSuccess: () => {},\n onUploadFailed: () => {},\n onUploadProgress: null,\n userId: null,\n fileName: null,\n disabled: false,\n };\n\n state = {\n isUploading: false,\n uploadProgress: 0,\n };\n\n pickDocument = async () => {\n const { allowedTypes, multiple } = this.props;\n\n // try {\n // const result = await DocumentPicker.getDocumentAsync({\n // type: allowedTypes,\n // copyToCacheDirectory: true,\n // multiple: multiple || false,\n // });\n // // console.log('pickDocument', JSON.stringify(result, null, 2));\n\n // if (!result.canceled) {\n // await this.handleDocumentPicked(result);\n // }\n // } catch (error) {\n // console.log('Document picker error:', error);\n // this.props.onUploadFailed(null, error.message);\n // }\n };\n\n handleDocumentPicked = async documentResult => {\n const { assets } = documentResult;\n const { userId } = this.props;\n\n try {\n this.setState({ isUploading: true, uploadProgress: 0 });\n\n // Process each asset in parallel\n const uploadPromises = assets.map(async asset => {\n const { name, uri, mimeType } = asset;\n\n let file, fileExt;\n if (name && name.includes('.')) {\n const lastDotIndex = name.lastIndexOf('.');\n file = name.substring(0, lastDotIndex);\n fileExt = name.substring(lastDotIndex + 1);\n } else {\n // Fallback: extract extension from mimeType\n file = name || 'document';\n if (mimeType) {\n const mimeTypeParts = mimeType.split('/');\n // Handle specific MIME type mappings\n if (mimeType === 'application/pdf') fileExt = 'pdf';\n else if (mimeType.startsWith('image/')) fileExt = mimeTypeParts[1];\n else if (mimeType.startsWith('text/')) fileExt = 'txt';\n else fileExt = mimeTypeParts[1] || 'pdf';\n } else {\n fileExt = 'pdf';\n }\n }\n\n // Generate a unique filename if not provided\n const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}.${fileExt}`;\n const uploadUri = fileActions.getUploadUrl(userId, fileName);\n // console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName, mimeType, file, fileExt }, null, 2));\n\n try {\n // Notify parent component that upload has started for this file\n this.props.onUploadStarted(uploadUri, uri, file, fileExt.toUpperCase());\n\n const res = await fileActions.uploadUserMediaWithProgress(uri, uploadUri, progress => {\n if (this.props.onUploadProgress) this.props.onUploadProgress(progress);\n });\n\n const fileUrl = Config.env.baseUploadsUrl + res.key;\n this.props.onUploadSuccess(fileUrl, uploadUri);\n console.log('Upload success', fileUrl);\n return { success: true, url: fileUrl, uploadUri };\n } catch (error) {\n console.error(`Upload failed for ${name}:`, error);\n this.props.onUploadFailed(uploadUri, error.message);\n return { success: false, error, uploadUri };\n }\n });\n\n // Wait for all uploads to complete\n const results = await Promise.all(uploadPromises);\n return results;\n } catch (error) {\n console.error('Document upload error:', error);\n return [];\n } finally {\n this.setState({ isUploading: false, uploadProgress: 0 });\n }\n };\n\n renderUploadButton = () => {\n const { buttonTitle, buttonStyle, buttonTextStyle, disabled } = this.props;\n const { isUploading } = this.state;\n const mainColor = getMainBrandingColourFromState(this.props);\n\n return (\n <TouchableOpacity\n style={[styles.uploadButton, { borderColor: mainColor }, buttonStyle]}\n onPress={this.pickDocument}\n disabled={isUploading || disabled}\n activeOpacity={0.7}\n >\n <View style={styles.buttonContent}>\n {isUploading ? (\n <ActivityIndicator color={mainColor} />\n ) : (\n <Icon name=\"attachment\" type=\"entypo\" color={mainColor} size={18} style={styles.icon} />\n )}\n <Text style={[styles.buttonText, { color: mainColor }, buttonTextStyle]}>{buttonTitle}</Text>\n </View>\n </TouchableOpacity>\n );\n };\n\n renderProgress = () => {\n const { uploadProgress } = this.state;\n if (uploadProgress <= 0 || uploadProgress >= 1) return null;\n\n return (\n <View style={styles.progressContainer}>\n <View style={styles.progressBar}>\n <View style={[styles.progressFill, { width: `${uploadProgress * 100}%` }]} />\n </View>\n <Text style={styles.progressText}>{Math.round(uploadProgress * 100)}%</Text>\n </View>\n );\n };\n\n render() {\n return (\n <View style={styles.container}>\n {this.renderUploadButton()}\n {this.renderProgress()}\n </View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n container: {\n marginVertical: 10,\n },\n uploadButton: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n paddingVertical: 8,\n paddingHorizontal: 16,\n borderRadius: 6,\n backgroundColor: '#fff',\n borderWidth: 1,\n borderColor: '#007AFF',\n },\n buttonContent: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n buttonText: {\n color: '#fff',\n fontSize: 16,\n fontWeight: '500',\n marginLeft: 8,\n },\n icon: {\n marginRight: 8,\n },\n progressContainer: {\n marginTop: 8,\n alignItems: 'center',\n },\n progressBar: {\n height: 4,\n width: '100%',\n backgroundColor: '#E0E0E0',\n borderRadius: 2,\n overflow: 'hidden',\n },\n progressFill: {\n height: '100%',\n backgroundColor: '#4CAF50',\n },\n progressText: {\n marginTop: 4,\n fontSize: 12,\n color: TEXT_DARK,\n },\n});\n\nconst mapStateToProps = state => {\n const { user } = state;\n return {\n user,\n colourBrandingMain: getMainBrandingColourFromState(state),\n };\n};\n\nexport default connect(mapStateToProps)(DocumentUploader);\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,IAAI,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,UAAU,EAAEC,iBAAiB,QAAQ,cAAc;AAC1F,SAASC,IAAI,QAAQ,uBAAuB;AAC5C;AACA,SAASC,OAAO,QAAQ,aAAa;AACrC,OAAOC,MAAM,MAAM,WAAW;AAC9B,SAASC,WAAW,QAAQ,SAAS;AACrC,SAASC,iBAAiB,QAAQ,WAAW;AAC7C,SAASC,SAAS,EAAEC,8BAA8B,QAAQ,YAAY;AAEtE,MAAMC,qBAAqB,GAAG,UAAU;AAExC,MAAMC,gBAAgB,SAASd,SAAS,CAAC;EAAAe,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAAC,eAAA,gBAe/B;MACNC,WAAW,EAAE,KAAK;MAClBC,cAAc,EAAE;IAClB,CAAC;IAAAF,eAAA,uBAEc,YAAY;MACzB,MAAM;QAAEG,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAI,CAACC,KAAK;;MAE7C;MACA;MACA;MACA;MACA;MACA;MACA;;MAEA;MACA;MACA;MACA;MACA;MACA;MACA;IACF,CAAC;IAAAL,eAAA,+BAEsB,MAAMM,cAAc,IAAI;MAC7C,MAAM;QAAEC;MAAO,CAAC,GAAGD,cAAc;MACjC,MAAM;QAAEE;MAAO,CAAC,GAAG,IAAI,CAACH,KAAK;MAE7B,IAAI;QACF,IAAI,CAACI,QAAQ,CAAC;UAAER,WAAW,EAAE,IAAI;UAAEC,cAAc,EAAE;QAAE,CAAC,CAAC;;QAEvD;QACA,MAAMQ,cAAc,GAAGH,MAAM,CAACI,GAAG,CAAC,MAAMC,KAAK,IAAI;UAC/C,MAAM;YAAEC,IAAI;YAAEC,GAAG;YAAEC;UAAS,CAAC,GAAGH,KAA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AAc,EAAE,QAAQ;IACxBC,eAAe,EAAE,CAAC;IAClBC,iBAAiB,EAAE,EAAE;IACrBC,YAAY,EAAE,CAAC;IACfC,eAAe,EAAE,MAAM;IACvBC,WAAW,EAAE,CAAC;IACd9B,WAAW,EAAE;EACf,CAAC;EACDI,aAAa,EAAE;IACbmB,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE;EACd,CAAC;EACDf,UAAU,EAAE;IACVJ,KAAK,EAAE,MAAM;IACb0B,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,KAAK;IACjBC,UAAU,EAAE;EACd,CAAC;EACDzB,IAAI,EAAE;IACJ0B,WAAW,EAAE;EACf,CAAC;EACDxB,iBAAiB,EAAE;IACjByB,SAAS,EAAE,CAAC;IACZX,UAAU,EAAE;EACd,CAAC;EACDb,WAAW,EAAE;IACXyB,MAAM,EAAE,CAAC;IACTvB,KAAK,EAAE,MAAM;IACbgB,eAAe,EAAE,SAAS;IAC1BD,YAAY,EAAE,CAAC;IACfS,QAAQ,EAAE;EACZ,CAAC;EACDzB,YAAY,EAAE;IACZwB,MAAM,EAAE,MAAM;IACdP,eAAe,EAAE;EACnB,CAAC;EACDf,YAAY,EAAE;IACZqB,SAAS,EAAE,CAAC;IACZJ,QAAQ,EAAE,EAAE;IACZ1B,KAAK,EAAEtE;EACT;AACF,CAAC,CAAC;AAEF,MAAMuG,eAAe,GAAG5C,KAAK,IAAI;EAC/B,MAAM;IAAE6C;EAAK,CAAC,GAAG7C,KAAK;EACtB,OAAO;IACL6C,IAAI;IACJC,kBAAkB,EAAExG,8BAA8B,CAAC0D,KAAK;EAC1D,CAAC;AACH,CAAC;AAED,eAAe/D,OAAO,CAAC2G,eAAe,CAAC,CAACpG,gBAAgB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-core-app",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.13",
|
|
4
4
|
"description": "Core extension package for Pluss Communities platform",
|
|
5
5
|
"main": "dist/module/index.js",
|
|
6
6
|
"module": "dist/module/index.js",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"expo-av": "~13.10.6",
|
|
32
32
|
"expo-calendar": "~12.2.1",
|
|
33
33
|
"expo-constants": "~15.4.6",
|
|
34
|
-
"expo-document-picker": "~11.10.1",
|
|
35
34
|
"expo-file-system": "~16.0.9",
|
|
36
35
|
"expo-image-manipulator": "~11.8.0",
|
|
37
36
|
"expo-image-picker": "~14.7.1",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
import { View, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
3
3
|
import { Icon } from 'react-native-elements';
|
|
4
|
-
import * as DocumentPicker from 'expo-document-picker';
|
|
4
|
+
// import * as DocumentPicker from 'expo-document-picker';
|
|
5
5
|
import { connect } from 'react-redux';
|
|
6
6
|
import Config from '../config';
|
|
7
7
|
import { fileActions } from '../apis';
|
|
@@ -33,21 +33,21 @@ class DocumentUploader extends Component {
|
|
|
33
33
|
pickDocument = async () => {
|
|
34
34
|
const { allowedTypes, multiple } = this.props;
|
|
35
35
|
|
|
36
|
-
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} catch (error) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
36
|
+
// try {
|
|
37
|
+
// const result = await DocumentPicker.getDocumentAsync({
|
|
38
|
+
// type: allowedTypes,
|
|
39
|
+
// copyToCacheDirectory: true,
|
|
40
|
+
// multiple: multiple || false,
|
|
41
|
+
// });
|
|
42
|
+
// // console.log('pickDocument', JSON.stringify(result, null, 2));
|
|
43
|
+
|
|
44
|
+
// if (!result.canceled) {
|
|
45
|
+
// await this.handleDocumentPicked(result);
|
|
46
|
+
// }
|
|
47
|
+
// } catch (error) {
|
|
48
|
+
// console.log('Document picker error:', error);
|
|
49
|
+
// this.props.onUploadFailed(null, error.message);
|
|
50
|
+
// }
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
handleDocumentPicked = async documentResult => {
|
|
@@ -59,13 +59,32 @@ class DocumentUploader extends Component {
|
|
|
59
59
|
|
|
60
60
|
// Process each asset in parallel
|
|
61
61
|
const uploadPromises = assets.map(async asset => {
|
|
62
|
-
const { name, uri } = asset;
|
|
62
|
+
const { name, uri, mimeType } = asset;
|
|
63
|
+
|
|
64
|
+
let file, fileExt;
|
|
65
|
+
if (name && name.includes('.')) {
|
|
66
|
+
const lastDotIndex = name.lastIndexOf('.');
|
|
67
|
+
file = name.substring(0, lastDotIndex);
|
|
68
|
+
fileExt = name.substring(lastDotIndex + 1);
|
|
69
|
+
} else {
|
|
70
|
+
// Fallback: extract extension from mimeType
|
|
71
|
+
file = name || 'document';
|
|
72
|
+
if (mimeType) {
|
|
73
|
+
const mimeTypeParts = mimeType.split('/');
|
|
74
|
+
// Handle specific MIME type mappings
|
|
75
|
+
if (mimeType === 'application/pdf') fileExt = 'pdf';
|
|
76
|
+
else if (mimeType.startsWith('image/')) fileExt = mimeTypeParts[1];
|
|
77
|
+
else if (mimeType.startsWith('text/')) fileExt = 'txt';
|
|
78
|
+
else fileExt = mimeTypeParts[1] || 'pdf';
|
|
79
|
+
} else {
|
|
80
|
+
fileExt = 'pdf';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
63
83
|
|
|
64
84
|
// Generate a unique filename if not provided
|
|
65
|
-
const
|
|
66
|
-
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}_${Date.now()}.${fileExt}`;
|
|
85
|
+
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_DOCUMENT_NAME)}.${fileExt}`;
|
|
67
86
|
const uploadUri = fileActions.getUploadUrl(userId, fileName);
|
|
68
|
-
// console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName }, null, 2));
|
|
87
|
+
// console.log('handleDocumentPicked', JSON.stringify({ uploadUri, uri, name, fileName, mimeType, file, fileExt }, null, 2));
|
|
69
88
|
|
|
70
89
|
try {
|
|
71
90
|
// Notify parent component that upload has started for this file
|