@@ -31,7 +31,6 @@ import { resolveHostname, protocolMap } from '../minecraft/utils'
3131import initiateConnection from '../minecraft/connection'
3232import {
3333 ChatToJsx ,
34- MinecraftChat ,
3534 lightColorMap ,
3635 mojangColorMap
3736} from '../minecraft/chatToJsx'
@@ -52,7 +51,12 @@ const ServerScreen = () => {
5251 const darkMode = useDarkMode ( )
5352 const { servers, setServers } = useContext ( ServersContext )
5453 const { accounts } = useContext ( AccountsContext )
55- const { connection, setConnection } = useContext ( ConnectionContext )
54+ const {
55+ connection,
56+ setConnection,
57+ disconnectReason,
58+ setDisconnectReason
59+ } = useContext ( ConnectionContext )
5660 const initiatingConnection = useRef ( false )
5761
5862 const [ ipAddr , setIpAddr ] = useState ( '' )
@@ -68,10 +72,6 @@ const ServerScreen = () => {
6872 const [ pingResponses , setPingResponses ] = useState < {
6973 [ ip : string ] : LegacyPing | Ping | null
7074 } > ( { } )
71- const [ disconnectDialog , setDisconnectDialog ] = useState < {
72- server : string
73- reason : MinecraftChat
74- } | null > ( null )
7575
7676 useEffect ( ( ) => {
7777 if ( Object . keys ( pingResponses ) . length > 0 ) {
@@ -139,7 +139,7 @@ const ServerScreen = () => {
139139 const activeAccount = Object . keys ( accounts ) . find ( e => accounts [ e ] . active )
140140 if ( ! activeAccount ) {
141141 initiatingConnection . current = false
142- return setDisconnectDialog ( {
142+ return setDisconnectReason ( {
143143 server,
144144 reason :
145145 'No active account selected! Open the Accounts tab and add an account.'
@@ -156,7 +156,7 @@ const ServerScreen = () => {
156156 }
157157 if ( protocolVersion < 754 ) {
158158 initiatingConnection . current = false
159- return setDisconnectDialog ( {
159+ return setDisconnectReason ( {
160160 server,
161161 reason : 'EnderChat only supports 1.16.4 and newer for now.'
162162 } )
@@ -174,8 +174,7 @@ const ServerScreen = () => {
174174 const onCloseOrError = ( ) => {
175175 setConnection ( undefined )
176176 if ( newConn . disconnectReason ) {
177- // TODO: This doesn't always hit correctly, since screen may be unrendered.
178- setDisconnectDialog ( {
177+ setDisconnectReason ( {
179178 server,
180179 reason : JSON . parse ( newConn . disconnectReason )
181180 } )
@@ -213,21 +212,21 @@ const ServerScreen = () => {
213212 </ Text >
214213 </ Pressable >
215214 </ Dialog >
216- { disconnectDialog && (
217- < Dialog visible onRequestClose = { ( ) => setDisconnectDialog ( null ) } >
215+ { disconnectReason && (
216+ < Dialog visible onRequestClose = { ( ) => setDisconnectReason ( ) } >
218217 < Text style = { dialogStyles . modalTitle } >
219- Disconnected from { disconnectDialog . server }
218+ Disconnected from { disconnectReason . server }
220219 </ Text >
221220 < ChatToJsx
222- chat = { disconnectDialog . reason }
221+ chat = { disconnectReason . reason }
223222 component = { Text }
224223 colorMap = { darkMode ? mojangColorMap : lightColorMap }
225224 componentProps = { { style : styles . serverDescription } }
226225 />
227226 < View style = { dialogStyles . modalButtons } >
228227 < View style = { globalStyle . flexSpacer } />
229228 < Pressable
230- onPress = { ( ) => setDisconnectDialog ( null ) }
229+ onPress = { ( ) => setDisconnectReason ( ) }
231230 android_ripple = { { color : '#aaa' } }
232231 style = { dialogStyles . modalButton }
233232 >
0 commit comments