@@ -14,6 +14,7 @@ import Screen from '../common/Screen';
14
14
import ZulipButton from '../common/ZulipButton' ;
15
15
import { getAuth , getOwnUserId } from '../selectors' ;
16
16
import { getUserStatus } from './userStatusesModel' ;
17
+ import type { UserStatus } from '../api/modelTypes' ;
17
18
import { IconCancel , IconDone } from '../common/Icons' ;
18
19
import statusSuggestions from './userStatusTextSuggestions' ;
19
20
import * as api from '../api' ;
@@ -36,14 +37,20 @@ type Props = $ReadOnly<{|
36
37
route : RouteProp < 'user-status' , void> ,
37
38
| } > ;
38
39
40
+ const statusTextFromInputValue = ( v : string ) : $PropertyType < UserStatus , 'status_text' > => v || null ;
41
+
42
+ const inputValueFromStatusText = ( t : $PropertyType < UserStatus , 'status_text' > ) : string => t ?? '' ;
43
+
39
44
export default function UserStatusScreen ( props : Props ) : Node {
40
45
const { navigation } = props ;
41
46
42
47
const auth = useSelector ( getAuth ) ;
43
48
const ownUserId = useSelector ( getOwnUserId ) ;
44
49
const userStatusText = useSelector ( state => getUserStatus ( state , ownUserId ) . status_text ) ;
45
50
46
- const [ textInputValue , setTextInputValue ] = useState < string > ( userStatusText ?? '' ) ;
51
+ const [ textInputValue , setTextInputValue ] = useState < string > (
52
+ inputValueFromStatusText ( userStatusText ) ,
53
+ ) ;
47
54
const _ = useContext ( TranslationContext ) ;
48
55
49
56
const sendToServer = useCallback (
@@ -55,11 +62,11 @@ export default function UserStatusScreen(props: Props): Node {
55
62
) ;
56
63
57
64
const handlePressUpdate = useCallback ( ( ) => {
58
- sendToServer ( { status_text : textInputValue } ) ;
65
+ sendToServer ( { status_text : statusTextFromInputValue ( textInputValue ) } ) ;
59
66
} , [ textInputValue , sendToServer ] ) ;
60
67
61
68
const handlePressClear = useCallback ( ( ) => {
62
- setTextInputValue ( '' ) ;
69
+ setTextInputValue ( inputValueFromStatusText ( null ) ) ;
63
70
sendToServer ( { status_text : null } ) ;
64
71
} , [ sendToServer ] ) ;
65
72
@@ -82,7 +89,7 @@ export default function UserStatusScreen(props: Props): Node {
82
89
key = { item }
83
90
itemKey = { item }
84
91
title = { item }
85
- selected = { item === textInputValue }
92
+ selected = { item === statusTextFromInputValue ( textInputValue ) }
86
93
onRequestSelectionChange = { itemKey => {
87
94
setTextInputValue ( _ ( itemKey ) ) ;
88
95
} }
0 commit comments