@@ -3,6 +3,7 @@ import * as Kb from '@/common-adapters'
33import * as Styles from '@/styles'
44import * as C from '@/constants'
55import type * as T from '@/constants/types'
6+ import { isPathHEIC } from '@/constants/chat2'
67
78export type Info = {
89 type : 'image' | 'file' | 'video'
@@ -24,140 +25,126 @@ type Props = {
2425 onSubmit : ( titles : Array < string > , spoiler : boolean ) => void
2526}
2627
27- type State = {
28- index : number
29- titles : Array < string >
30- spoiler : boolean
31- }
32-
33- class GetTitles extends React . Component < Props , State > {
34- state : State
35-
36- constructor ( props : Props ) {
37- super ( props )
38- this . state = {
39- index : 0 ,
40- spoiler : false ,
41- titles : props . pathAndInfos . map ( ( _ , idx ) => props . titles ?. [ idx ] ?? '' ) ,
42- }
43- }
28+ const GetTitles = ( p : Props ) => {
29+ const { pathAndInfos, titles : _titles , onSubmit : _onSubmit , onCancel} = p
30+ const [ index , setIndex ] = React . useState ( 0 )
31+ const [ titles , setTitles ] = React . useState ( pathAndInfos . map ( ( _ , idx ) => _titles ?. [ idx ] ?? '' ) )
32+ const [ spoiler , setSpoiler ] = React . useState ( false )
33+ setSpoiler // TODO commented out
4434
45- _onNext = ( e ?: React . BaseSyntheticEvent ) => {
46- e ?. preventDefault ( )
35+ const onNext = React . useCallback (
36+ ( e ?: React . BaseSyntheticEvent ) => {
37+ e ?. preventDefault ( )
4738
48- const { info} = this . props . pathAndInfos [ this . state . index ] ?? { }
49- if ( ! info ) return
39+ const { info} = pathAndInfos [ index ] ?? { }
40+ if ( ! info ) return
5041
51- const nextIndex = this . state . index + 1
42+ const nextIndex = index + 1
5243
53- // done
54- if ( nextIndex === this . props . pathAndInfos . length ) {
55- this . props . onSubmit ( this . state . titles , this . state . spoiler )
56- } else {
57- // go to next
58- this . setState ( { index : nextIndex } )
44+ // done
45+ if ( nextIndex === pathAndInfos . length ) {
46+ _onSubmit ( titles , spoiler )
47+ } else {
48+ // go to next
49+ setIndex ( s => s + 1 )
50+ }
51+ } ,
52+ [ index , pathAndInfos , titles , spoiler , setIndex , _onSubmit ]
53+ )
54+
55+ const onSubmit = React . useCallback (
56+ ( e ?: React . BaseSyntheticEvent ) => {
57+ e ?. preventDefault ( )
58+ _onSubmit ( titles , spoiler )
59+ } ,
60+ [ _onSubmit , titles , spoiler ]
61+ )
62+
63+ const updateTitle = React . useCallback (
64+ ( title : string ) => {
65+ setTitles ( [ ...titles . slice ( 0 , index ) , title , ...titles . slice ( index + 1 ) ] )
66+ } ,
67+ [ index , titles ]
68+ )
69+
70+ const { info, path} = pathAndInfos [ index ] ?? { }
71+ const titleHint = 'Add a caption...'
72+ if ( ! info ) return null
73+
74+ let preview : React . ReactNode = null
75+ switch ( info . type ) {
76+ case 'image' :
77+ preview = path ? < Kb . ZoomableImage src = { info . url ?? path } style = { styles . image } /> : null
78+ break
79+ case 'video' :
80+ preview = path ? < Kb . Video autoPlay = { false } allowFile = { true } muted = { true } url = { path } /> : null
81+ break
82+ default : {
83+ if ( C . isIOS && path && isPathHEIC ( path ) ) {
84+ preview = < Kb . ZoomableImage src = { path } style = { styles . image } />
85+ } else {
86+ preview = (
87+ < Kb . Box2 direction = "vertical" fullWidth = { true } fullHeight = { true } centerChildren = { true } >
88+ < Kb . Icon type = "icon-file-uploading-48" />
89+ </ Kb . Box2 >
90+ )
91+ }
5992 }
6093 }
6194
62- _onSubmit = ( e ?: React . BaseSyntheticEvent ) => {
63- e ?. preventDefault ( )
64- this . props . onSubmit ( this . state . titles , this . state . spoiler )
65- }
66-
67- _isLast = ( ) => {
68- const numPaths = this . props . pathAndInfos . length
69- return this . state . index + 1 === numPaths
70- }
71-
95+ const isLast = index + 1 === pathAndInfos . length
7296 // Are we trying to upload multiple?
73- _multiUpload = ( ) => {
74- return this . props . pathAndInfos . length > 1
75- }
76-
77- _updateTitle = ( title : string ) => {
78- this . setState ( state => ( {
79- titles : [ ...state . titles . slice ( 0 , state . index ) , title , ...state . titles . slice ( state . index + 1 ) ] ,
80- } ) )
81- }
82-
83- render ( ) {
84- const { info, path} = this . props . pathAndInfos [ this . state . index ] ?? { }
85- const titleHint = 'Add a caption...'
86- if ( ! info ) return null
87-
88- let preview : React . ReactNode = null
89- switch ( info . type ) {
90- case 'image' :
91- preview = path ? < Kb . ZoomableImage src = { info . url ?? path } style = { styles . image } /> : null
92- break
93- case 'video' :
94- preview = path ? < Kb . Video autoPlay = { false } allowFile = { true } muted = { true } url = { path } /> : null
95- break
96- default : {
97- if ( C . isMobile && path ?. toLowerCase ( ) . endsWith ( '.heic' ) ) {
98- preview = < Kb . ZoomableImage src = { path } style = { styles . image } />
99- } else {
100- preview = (
101- < Kb . Box2 direction = "vertical" fullWidth = { true } fullHeight = { true } centerChildren = { true } >
102- < Kb . Icon type = "icon-file-uploading-48" />
97+ const multiUpload = pathAndInfos . length > 1
98+
99+ return (
100+ < Kb . PopupWrapper onCancel = { onCancel } >
101+ < Kb . Box2 direction = "vertical" style = { styles . containerOuter } fullWidth = { true } >
102+ < Kb . Box2 alignItems = "center" direction = "vertical" fullWidth = { true } style = { styles . container } >
103+ < Kb . BoxGrow style = { styles . boxGrow } > { preview } </ Kb . BoxGrow >
104+ { pathAndInfos . length > 0 && ! Styles . isMobile && (
105+ < Kb . Box2 direction = "vertical" style = { styles . filename } >
106+ < Kb . Text type = "BodySmallSemibold" > Filename</ Kb . Text >
107+ < Kb . Text type = "BodySmall" center = { true } >
108+ { info . filename } ({ index + 1 } of { pathAndInfos . length } )
109+ </ Kb . Text >
103110 </ Kb . Box2 >
104- )
105- }
106- }
107- }
108-
109- return (
110- < Kb . PopupWrapper onCancel = { this . props . onCancel } >
111- < Kb . Box2 direction = "vertical" style = { styles . containerOuter } fullWidth = { true } >
112- < Kb . Box2 alignItems = "center" direction = "vertical" fullWidth = { true } style = { styles . container } >
113- < Kb . BoxGrow style = { styles . boxGrow } > { preview } </ Kb . BoxGrow >
114- { this . props . pathAndInfos . length > 0 && ! Styles . isMobile && (
115- < Kb . Box2 direction = "vertical" style = { styles . filename } >
116- < Kb . Text type = "BodySmallSemibold" > Filename</ Kb . Text >
117- < Kb . Text type = "BodySmall" center = { true } >
118- { info . filename } ({ this . state . index + 1 } of { this . props . pathAndInfos . length } )
119- </ Kb . Text >
120- </ Kb . Box2 >
121- ) }
122- < Kb . Box2 direction = "vertical" fullWidth = { true } style = { styles . inputContainer } >
123- < Kb . PlainInput
124- style = { styles . input }
125- autoFocus = { ! Styles . isMobile }
126- autoCorrect = { true }
127- placeholder = { titleHint }
128- multiline = { true }
129- rowsMin = { 2 }
130- padding = "tiny"
131- value = { this . state . titles [ this . state . index ] }
132- onEnterKeyDown = { this . _onNext }
133- onChangeText = { this . _updateTitle }
134- selectTextOnFocus = { true }
135- />
136- { /* (
111+ ) }
112+ < Kb . Box2 direction = "vertical" fullWidth = { true } style = { styles . inputContainer } >
113+ < Kb . PlainInput
114+ style = { styles . input }
115+ autoFocus = { ! Styles . isMobile }
116+ autoCorrect = { true }
117+ placeholder = { titleHint }
118+ multiline = { true }
119+ rowsMin = { 2 }
120+ padding = "tiny"
121+ value = { titles [ index ] }
122+ onEnterKeyDown = { onNext }
123+ onChangeText = { updateTitle }
124+ selectTextOnFocus = { true }
125+ />
126+ { /* (
137127 <Kb.Checkbox
138128 style={{alignSelf: 'flex-end'}}
139129 label="Spoiler?"
140- checked={this.state. spoiler}
141- onCheck={c => this.setState({spoiler: c}) }
130+ checked={spoiler}
131+ onCheck={setSpoiler }
142132 />
143133 )*/ }
144- </ Kb . Box2 >
145134 </ Kb . Box2 >
146- < Kb . ButtonBar fullWidth = { true } small = { true } style = { styles . buttonContainer } >
147- { ! Styles . isMobile && (
148- < Kb . Button fullWidth = { true } type = "Dim" onClick = { this . props . onCancel } label = "Cancel" />
149- ) }
150- { this . _isLast ( ) ? (
151- < Kb . WaitingButton fullWidth = { ! this . _multiUpload ( ) } onClick = { this . _onSubmit } label = "Send" />
152- ) : (
153- < Kb . Button fullWidth = { ! this . _multiUpload ( ) } onClick = { this . _onNext } label = "Next" />
154- ) }
155- { this . _multiUpload ( ) ? < Kb . WaitingButton onClick = { this . _onSubmit } label = "Send All" /> : null }
156- </ Kb . ButtonBar >
157135 </ Kb . Box2 >
158- </ Kb . PopupWrapper >
159- )
160- }
136+ < Kb . ButtonBar fullWidth = { true } small = { true } style = { styles . buttonContainer } >
137+ { ! Styles . isMobile && < Kb . Button fullWidth = { true } type = "Dim" onClick = { onCancel } label = "Cancel" /> }
138+ { isLast ? (
139+ < Kb . WaitingButton fullWidth = { ! multiUpload } onClick = { onSubmit } label = "Send" />
140+ ) : (
141+ < Kb . Button fullWidth = { ! multiUpload } onClick = { onNext } label = "Next" />
142+ ) }
143+ { multiUpload ? < Kb . WaitingButton onClick = { onSubmit } label = "Send All" /> : null }
144+ </ Kb . ButtonBar >
145+ </ Kb . Box2 >
146+ </ Kb . PopupWrapper >
147+ )
161148}
162149
163150const styles = Styles . styleSheetCreate (
0 commit comments