@supportworks/multi-imagepicker 6.0.0 → 7.0.0
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/TestMIP.js +103 -0
- package/changes.md +5 -0
- package/index.js +15 -9
- package/package.json +2 -2
- package/src/components/ActionBar.js +104 -0
- package/src/components/AddImages.js +473 -304
- package/src/components/ImageDetailsModal.js +134 -0
- package/src/components/ImageIndicators.js +85 -0
- package/src/components/MultiImagePicker.js +284 -264
- package/src/components/SelectedImages.js +130 -67
- package/src/components/SingleImage.js +320 -182
- package/src/components/UploadWarningModal.js +105 -0
- package/src/components/loaderHandler.js +5 -5
- package/src/lib/MIPickerApi.js +78 -39
|
@@ -1,84 +1,147 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useCallback, useMemo, useEffect, useState } from 'react'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
View,
|
|
4
|
+
Modal,
|
|
5
|
+
SafeAreaView
|
|
6
|
+
} from 'react-native'
|
|
7
|
+
import SingleImage from './SingleImage'
|
|
6
8
|
import { Analytics } from '@supportworks/analytics'
|
|
9
|
+
import { MediaPlayer } from '@supportworks/core-controls'
|
|
10
|
+
import { colors } from '@supportworks/app-styler'
|
|
11
|
+
import { Api } from '@supportworks/api-core'
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
const SelectedImages = (
|
|
14
|
+
{
|
|
15
|
+
items = [], // array of image info (required)
|
|
16
|
+
annotationAllowed = false,
|
|
17
|
+
onDeleteItem = null,
|
|
18
|
+
onItemChange = null,
|
|
19
|
+
allowSaveToDevice = null,
|
|
20
|
+
allowShowToCustomer = null
|
|
21
|
+
}) => {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
Analytics.setCurrentScreen('MultiImagePicker/SelectedImages', SelectedImages.name)
|
|
24
|
+
}, [])
|
|
9
25
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
const onChangeImageInfo = useCallback((payload) => {
|
|
27
|
+
switch (payload.name) {
|
|
28
|
+
case 'title': {
|
|
29
|
+
if (typeof onItemChange === 'function') {
|
|
30
|
+
onItemChange(payload.imgIndex, { filename: payload.value, isValid: payload.isValid })
|
|
31
|
+
}
|
|
32
|
+
setVersion(v => v + 1)
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
case 'desc': {
|
|
36
|
+
if (typeof onItemChange === 'function') {
|
|
37
|
+
onItemChange(payload.imgIndex, { desc: payload.value })
|
|
38
|
+
}
|
|
39
|
+
setVersion(v => v + 1)
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
break
|
|
25
44
|
}
|
|
45
|
+
}, [onItemChange])
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let cRef = this;
|
|
31
|
-
//console.log("-----onChangeImageInfo: start");
|
|
32
|
-
//console.log("-----name: " + payload.name);
|
|
33
|
-
//console.log("-----value: " + payload.value);
|
|
34
|
-
//console.log("-----isValid: " + payload.isValid);
|
|
35
|
-
//console.log("-----imgIndex: " + payload.imgIndex);
|
|
47
|
+
const [mediaOpen, setMediaOpen] = useState(false)
|
|
48
|
+
const [mediaIndex, setMediaIndex] = useState(0)
|
|
49
|
+
const [version, setVersion] = useState(0)
|
|
36
50
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
const resourceList = useMemo(() => {
|
|
52
|
+
return items.map((img, idx) => ({
|
|
53
|
+
id: String(idx),
|
|
54
|
+
title: img.filename || img.defaultName || '',
|
|
55
|
+
description: img.desc || '',
|
|
56
|
+
localPath: img.path,
|
|
57
|
+
type: 'Image'
|
|
58
|
+
}))
|
|
59
|
+
}, [items, version])
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//if any are invalid, set allValid to false
|
|
47
|
-
if (!cRef.props.imgValidArr[i]) {
|
|
48
|
-
allValid = false;
|
|
49
|
-
break; //no need to check others
|
|
50
|
-
}
|
|
51
|
-
}
|
|
61
|
+
const openMedia = useCallback((idx) => {
|
|
62
|
+
setMediaIndex(idx)
|
|
63
|
+
setMediaOpen(true)
|
|
64
|
+
}, [])
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
cRef.props.callback(allValid);
|
|
55
|
-
}
|
|
66
|
+
const closeMedia = useCallback(() => setMediaOpen(false), [])
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
68
|
+
// When MediaPlayer saves an annotated image, refresh the list and bust cache
|
|
69
|
+
const handleMediaUpdated = useCallback((newPath) => {
|
|
70
|
+
if (typeof onItemChange === 'function' && newPath) {
|
|
71
|
+
onItemChange(mediaIndex, { path: newPath })
|
|
62
72
|
}
|
|
73
|
+
setVersion(v => v + 1)
|
|
74
|
+
}, [onItemChange, mediaIndex])
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
let cRef = this;
|
|
66
|
-
|
|
67
|
-
//put selected images into array
|
|
68
|
-
console.log("SWSI cRef.imgArr: " + JSON.stringify(cRef.props.imgArr));
|
|
69
|
-
let selImages = cRef.props.imgArr.map(function (o, idx) {
|
|
70
|
-
//let fname = o.filename;
|
|
71
|
-
//let path = o.path;
|
|
72
|
-
return (
|
|
73
|
-
<View key={idx}>
|
|
74
|
-
<SingleImage imgObject={o} imgIndex={idx} callback={cRef.onChangeImageInfo} annotationAllowed={cRef.props.annotationAllowed}/>
|
|
75
|
-
</View>
|
|
76
|
-
);
|
|
77
|
-
});
|
|
76
|
+
// Title/desc update callbacks are handled via onChangeImageInfo -> onItemChange
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
const toggleSaveForItem = useCallback((idx) => {
|
|
79
|
+
if (!items || !items[idx]) return
|
|
80
|
+
const current = !!items[idx].saveToDevice
|
|
81
|
+
if (typeof onItemChange === 'function') {
|
|
82
|
+
onItemChange(idx, { saveToDevice: !current })
|
|
83
|
+
}
|
|
84
|
+
setVersion(v => v + 1)
|
|
85
|
+
}, [items, onItemChange])
|
|
80
86
|
|
|
87
|
+
const toggleShowToCustForItem = useCallback((idx) => {
|
|
88
|
+
if (!items || !items[idx]) return
|
|
89
|
+
const current = !!items[idx].showToCust
|
|
90
|
+
if (typeof onItemChange === 'function') {
|
|
91
|
+
onItemChange(idx, { showToCust: !current })
|
|
81
92
|
}
|
|
93
|
+
setVersion(v => v + 1)
|
|
94
|
+
}, [items, onItemChange])
|
|
95
|
+
|
|
96
|
+
// Deletion is handled by parent (AddImages) to keep refs/state in sync
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
{items.map((o, idx) => (
|
|
101
|
+
<View key={idx}>
|
|
102
|
+
<SingleImage
|
|
103
|
+
imgObject={o}
|
|
104
|
+
imgIndex={idx}
|
|
105
|
+
callback={onChangeImageInfo}
|
|
106
|
+
annotationAllowed={annotationAllowed}
|
|
107
|
+
onOpenMedia={openMedia}
|
|
108
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
109
|
+
saveToDevice={!!o.saveToDevice}
|
|
110
|
+
onToggleSaveToDevice={() => toggleSaveForItem(idx)}
|
|
111
|
+
allowShowToCustomer={allowShowToCustomer}
|
|
112
|
+
showToCust={!!o.showToCust}
|
|
113
|
+
onToggleShowToCust={() => toggleShowToCustForItem(idx)}
|
|
114
|
+
onDelete={() => { if (typeof onDeleteItem === 'function') onDeleteItem(idx) }}
|
|
115
|
+
disableDelete={items.length <= 1}
|
|
116
|
+
initialDesc={o.desc || ''}
|
|
117
|
+
cacheVersion={version}
|
|
118
|
+
/>
|
|
119
|
+
</View>
|
|
120
|
+
))}
|
|
121
|
+
{mediaOpen && (
|
|
122
|
+
<Modal
|
|
123
|
+
presentationStyle='fullScreen'
|
|
124
|
+
animationType='slide'
|
|
125
|
+
onRequestClose={closeMedia}
|
|
126
|
+
visible
|
|
127
|
+
>
|
|
128
|
+
<SafeAreaView style={{ flex: 1, backgroundColor: colors.black }}>
|
|
129
|
+
<MediaPlayer
|
|
130
|
+
mediaId={mediaIndex}
|
|
131
|
+
backgroundColor={colors.black}
|
|
132
|
+
resourceList={resourceList}
|
|
133
|
+
initialResource={mediaIndex}
|
|
134
|
+
annotationAllowed={annotationAllowed}
|
|
135
|
+
onClose={closeMedia}
|
|
136
|
+
onNotifyChange={handleMediaUpdated}
|
|
137
|
+
fullPath={Api.getApi().fullPath}
|
|
138
|
+
fullImagePath={Api.getApi().fullImagePath}
|
|
139
|
+
/>
|
|
140
|
+
</SafeAreaView>
|
|
141
|
+
</Modal>
|
|
142
|
+
)}
|
|
143
|
+
</>
|
|
144
|
+
)
|
|
82
145
|
}
|
|
83
146
|
|
|
84
|
-
export default SelectedImages
|
|
147
|
+
export default SelectedImages
|