1
1
import React , { useRef , useEffect } from 'react'
2
2
import { createRoot } from 'react-dom/client'
3
- import { createStore } from 'redux'
4
3
import { Provider , connect } from 'react-redux'
5
- import { v4 as uuidv4 } from 'uuid'
6
- import ReconnectingWebSocket from 'reconnectingwebsocket'
7
- import { Base64 } from 'js-base64'
8
- import { library , dom } from '@fortawesome/fontawesome-svg-core'
4
+ import { createStore } from 'redux'
5
+
6
+ import { dom , library } from '@fortawesome/fontawesome-svg-core'
9
7
import { faPencilAlt } from '@fortawesome/free-solid-svg-icons/faPencilAlt'
10
8
import { faTrash } from '@fortawesome/free-solid-svg-icons/faTrash'
9
+ import { Base64 } from 'js-base64'
10
+ import ReconnectingWebSocket from 'reconnectingwebsocket'
11
+ import { v4 as uuidv4 } from 'uuid'
11
12
12
13
import nicks from './nicks'
13
14
@@ -57,7 +58,8 @@ const init: State = ((_) => {
57
58
58
59
let init = getBase64Hash ( )
59
60
if ( ! init ) {
60
- setBase64Hash ( ( init = 'general' ) )
61
+ init = 'general'
62
+ setBase64Hash ( init )
61
63
} // Default channel
62
64
if ( ! ( init in channels ) ) {
63
65
channels [ init ] = new_channel ( )
@@ -83,6 +85,7 @@ type Action = {
83
85
}
84
86
type Dispatch = ( action : Action ) => Action
85
87
88
+ // biome-ignore lint/style/useDefaultParameterLast: This is normal in Redux
86
89
const reducer = ( state : State = init , action : Action ) : State => {
87
90
const { channel : ch , msg, msg_id, msg_txt } = action
88
91
switch ( action . type ) {
@@ -108,17 +111,19 @@ const reducer = (state: State = init, action: Action): State => {
108
111
return state
109
112
}
110
113
114
+ const next = Object . assign ( { } , state )
115
+
111
116
// 내가 모르는 채널의 메세지 수정일경우, 무시
112
- if ( ! ( ch in state . channels ) ) {
117
+ if ( ! ( ch in next . channels ) ) {
113
118
return state
114
119
}
115
120
// 내가 받은적 없는 메세지의 수정일경우, 무시
116
- if ( state . channels [ ch ] . get ( msg_id ) == null ) {
121
+ const msg = next . channels [ ch ] . get ( msg_id )
122
+ if ( msg == null ) {
117
123
return state
118
124
}
119
125
120
- const next = Object . assign ( { } , state )
121
- next . channels [ ch ] . get ( msg_id ) ! . txt = msg_txt
126
+ msg . txt = msg_txt
122
127
return next
123
128
}
124
129
case 'DeleteMsg' : {
@@ -223,16 +228,21 @@ const ChannelView = (props: Props) => {
223
228
value = { txt }
224
229
ref = { elemEdit }
225
230
onBlur = { stopEdit }
226
- onChange = { ( ) => updateMsg ( ch , elemEdit . current ! . value , id ) }
231
+ onChange = { ( ) =>
232
+ elemEdit . current != null &&
233
+ updateMsg ( ch , elemEdit . current . value , id )
234
+ }
227
235
/>
228
236
</ form >
229
237
) }
230
238
{ is_editable && (
231
239
< span className = "control" >
240
+ { /* biome-ignore lint/a11y/useKeyWithClickEvents: TODO: Ensure accessibility by making it usable without a mouse. */ }
232
241
< span onClick = { ( ) => startEdit ( id ) } >
233
242
< i className = "fas fa-pencil-alt" />
234
243
</ span >
235
244
245
+ { /* biome-ignore lint/a11y/useKeyWithClickEvents: TODO: Ensure accessibility by making it usable without a mouse. */ }
236
246
< span onClick = { ( ) => deleteMsg ( ch , id ) } >
237
247
< i className = "fas fa-trash" />
238
248
</ span >
@@ -248,8 +258,8 @@ const ChannelView = (props: Props) => {
248
258
const View = ( props : Props ) => {
249
259
const { state, createMsg, createChannel, changeChannel } = props
250
260
251
- let field = React . createRef < HTMLInputElement > ( )
252
- let field_channel = React . createRef < HTMLInputElement > ( )
261
+ const field = React . createRef < HTMLInputElement > ( )
262
+ const field_channel = React . createRef < HTMLInputElement > ( )
253
263
254
264
const onSubmit = ( e : React . FormEvent ) => {
255
265
e . preventDefault ( )
@@ -267,7 +277,7 @@ const View = (props: Props) => {
267
277
return
268
278
}
269
279
270
- let ch = field_channel . current . value
280
+ const ch = field_channel . current . value
271
281
field_channel . current . value = ''
272
282
createChannel ( ch )
273
283
changeChannel ( ch )
@@ -281,6 +291,7 @@ const View = (props: Props) => {
281
291
</ form >
282
292
< ul >
283
293
{ Object . keys ( state . channels ) . map ( ( ch ) => (
294
+ // biome-ignore lint/a11y/useKeyWithClickEvents: TODO: Ensure accessibility by making it usable without a mouse.
284
295
< li
285
296
id = { ch === state . current_channel ? 'current' : undefined }
286
297
key = { ch }
0 commit comments