Skip to content

Commit be7ed10

Browse files
cleanup containers 1 (#28617)
1 parent 07a59a6 commit be7ed10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+400
-677
lines changed

shared/chat/blocking/block-modal.tsx

Lines changed: 103 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ export type ReportSettings = {
1919
export type NewBlocksMap = Map<string, BlocksForUser>
2020
type BlocksForUser = {chatBlocked?: boolean; followBlocked?: boolean; report?: ReportSettings}
2121

22-
export type Props = {
23-
adderUsername?: string
24-
blockUserByDefault?: boolean
25-
context?: BlockModalContext
26-
conversationIDKey?: string
27-
filterUserByDefault?: boolean
28-
finishWaiting: boolean
29-
flagUserByDefault?: boolean
30-
isBlocked: (username: string, which: BlockType) => boolean
31-
loadingWaiting: boolean
32-
onClose: () => void
33-
onFinish: (newBlocks: NewBlocksMap, blockTeam: boolean, report?: ReportSettings) => void
34-
otherUsernames?: Array<string>
35-
refreshBlocks: () => void
36-
reportsUserByDefault?: boolean
37-
teamname?: string
38-
}
39-
4022
type OwnProps = {
4123
blockUserByDefault?: boolean
4224
filterUserByDefault?: boolean
@@ -141,9 +123,102 @@ const ReportOptions = (props: ReportOptionsProps) => {
141123
// In order to have this play nicely with scrolling and keyboards, put all the stuff in a List.
142124
type Item = 'topStuff' | {username: string}
143125

144-
const BlockModal = React.memo(function BlockModal(p: Props) {
145-
const {finishWaiting, onClose, refreshBlocks, context, blockUserByDefault, otherUsernames} = p
146-
const {reportsUserByDefault, flagUserByDefault, conversationIDKey, adderUsername} = p
126+
const Container = React.memo(function BlockModal(ownProps: OwnProps) {
127+
const {context, conversationIDKey, blockUserByDefault = false, filterUserByDefault = false} = ownProps
128+
const {flagUserByDefault = false, reportsUserByDefault = false, team: teamname} = ownProps
129+
let {username: adderUsername, others} = ownProps
130+
const waitingForLeave = C.Waiting.useAnyWaiting(
131+
teamname ? C.Teams.leaveTeamWaitingKey(teamname) : undefined
132+
)
133+
const waitingForBlocking = C.Waiting.useAnyWaiting(Constants.setUserBlocksWaitingKey)
134+
const waitingForReport = C.Waiting.useAnyWaiting(Constants.reportUserWaitingKey)
135+
if (others?.length === 1 && !adderUsername) {
136+
adderUsername = others[0]
137+
others = undefined
138+
}
139+
140+
const _allKnownBlocks = C.useUsersState(s => s.blockMap)
141+
const loadingWaiting = C.Waiting.useAnyWaiting(Constants.getUserBlocksWaitingKey)
142+
143+
const onClose = C.useRouterState(s => s.dispatch.navigateUp)
144+
const leaveTeam = C.useTeamsState(s => s.dispatch.leaveTeam)
145+
const leaveTeamAndBlock = React.useCallback(
146+
(teamname: string) => {
147+
leaveTeam(teamname, true, 'chat')
148+
},
149+
[leaveTeam]
150+
)
151+
const getBlockState = C.useUsersState(s => s.dispatch.getBlockState)
152+
const _reportUser = C.useUsersState(s => s.dispatch.reportUser)
153+
const refreshBlocksFor = getBlockState
154+
const reportUser = React.useCallback(
155+
(username: string, conversationIDKey: string | undefined, report: ReportSettings) => {
156+
_reportUser({
157+
comment: report.extraNotes,
158+
conversationIDKey,
159+
includeTranscript: report.includeTranscript && !!conversationIDKey,
160+
reason: report.reason,
161+
username,
162+
})
163+
},
164+
[_reportUser]
165+
)
166+
const setConversationStatus = C.useChatContext(s => s.dispatch.blockConversation)
167+
const _setUserBlocks = C.useUsersState(s => s.dispatch.setUserBlocks)
168+
const setUserBlocks = React.useCallback(
169+
(newBlocks: NewBlocksMap) => {
170+
// Convert our state block array to action payload.
171+
const blocks = [...newBlocks.entries()]
172+
.filter(
173+
([_, userBlocks]) => userBlocks.chatBlocked !== undefined || userBlocks.followBlocked !== undefined
174+
)
175+
.map(([username, userBlocks]) => ({
176+
setChatBlock: userBlocks.chatBlocked,
177+
setFollowBlock: userBlocks.followBlocked,
178+
username,
179+
}))
180+
if (blocks.length) {
181+
_setUserBlocks(blocks)
182+
}
183+
},
184+
[_setUserBlocks]
185+
)
186+
187+
const otherUsernames = others && others.length > 0 ? others : undefined
188+
const finishWaiting = waitingForLeave || waitingForBlocking || waitingForReport
189+
const isBlocked = (username: string, which: BlockType) => {
190+
const blockObj = _allKnownBlocks.get(username)
191+
return blockObj ? blockObj[which] : false
192+
}
193+
194+
const onFinish = (newBlocks: NewBlocksMap, blockTeam: boolean) => {
195+
let takingAction = false
196+
if (blockTeam) {
197+
if (teamname) {
198+
takingAction = true
199+
leaveTeamAndBlock(teamname)
200+
} else if (conversationIDKey) {
201+
takingAction = true
202+
const anyReported = [...newBlocks.values()].some(v => v.report !== undefined)
203+
setConversationStatus(anyReported)
204+
}
205+
}
206+
if (newBlocks.size) {
207+
takingAction = true
208+
setUserBlocks(newBlocks)
209+
}
210+
newBlocks.forEach(({report}, username) => report && reportUser(username, conversationIDKey, report))
211+
if (!takingAction) {
212+
onClose()
213+
}
214+
}
215+
const refreshBlocks = React.useCallback(() => {
216+
const usernames = [...(adderUsername ? [adderUsername] : []), ...(otherUsernames || [])]
217+
if (usernames.length) {
218+
refreshBlocksFor(usernames)
219+
}
220+
}, [adderUsername, otherUsernames, refreshBlocksFor])
221+
147222
const [blockTeam, setBlockTeam] = React.useState(true)
148223
const [finishClicked, setFinishClicked] = React.useState(false)
149224
// newBlocks holds a Map of blocks that will be applied when user clicks
@@ -205,7 +280,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
205280
return current[which] || false
206281
}
207282
// If we don't have a checkbox, check the store for current block value.
208-
return p.isBlocked(username, which)
283+
return isBlocked(username, which)
209284
}
210285

211286
const setReportForUsername = (username: string, shouldReport: boolean) => {
@@ -263,9 +338,9 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
263338
}
264339
}
265340

266-
const onFinish = () => {
341+
const onClickFinish = () => {
267342
setFinishClicked(true)
268-
p.onFinish(newBlocks, blockTeam)
343+
onFinish(newBlocks, blockTeam)
269344
}
270345

271346
const shouldShowReport = (username: string): boolean => {
@@ -290,8 +365,8 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
290365
<CheckboxRow
291366
text={
292367
!teamLabel
293-
? `${p.filterUserByDefault ? 'Filter' : 'Block'} ${username}`
294-
: `${p.filterUserByDefault ? 'Filter' : 'Block'} ${username} from messaging me directly`
368+
? `${filterUserByDefault ? 'Filter' : 'Block'} ${username}`
369+
: `${filterUserByDefault ? 'Filter' : 'Block'} ${username} from messaging me directly`
295370
}
296371
onCheck={checked => setBlockFor(username, 'chatBlocked', checked)}
297372
checked={getBlockFor(username, 'chatBlocked')}
@@ -335,8 +410,6 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
335410
</>
336411
)
337412

338-
const {teamname} = p
339-
340413
const header = {
341414
leftButton: Styles.isMobile ? (
342415
<Kb.Text onClick={onClose} type="BodyPrimaryLink">
@@ -346,7 +419,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
346419
title: <Kb.Icon type="iconfont-user-block" sizeType="Big" color={Styles.globalColors.red} />,
347420
}
348421

349-
if (p.loadingWaiting) {
422+
if (loadingWaiting) {
350423
return (
351424
<Kb.Modal mode="Default" header={header}>
352425
<Kb.Box style={styles.loadingAnimationBox}>
@@ -393,7 +466,7 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
393466
content: (
394467
<Kb.ButtonBar fullWidth={true} style={styles.buttonBar}>
395468
{!Styles.isMobile && <Kb.Button fullWidth={true} label="Cancel" onClick={onClose} type="Dim" />}
396-
<Kb.WaitingButton label="Finish" onClick={onFinish} fullWidth={true} type="Danger" />
469+
<Kb.WaitingButton label="Finish" onClick={onClickFinish} fullWidth={true} type="Danger" />
397470
</Kb.ButtonBar>
398471
),
399472
}}
@@ -421,117 +494,6 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
421494
)
422495
})
423496

424-
const Container = (ownProps: OwnProps) => {
425-
const {context, conversationIDKey, blockUserByDefault = false, filterUserByDefault = false} = ownProps
426-
const {flagUserByDefault = false, reportsUserByDefault = false, team: teamname} = ownProps
427-
let {username: adderUsername, others} = ownProps
428-
const waitingForLeave = C.Waiting.useAnyWaiting(
429-
teamname ? C.Teams.leaveTeamWaitingKey(teamname) : undefined
430-
)
431-
const waitingForBlocking = C.Waiting.useAnyWaiting(Constants.setUserBlocksWaitingKey)
432-
const waitingForReport = C.Waiting.useAnyWaiting(Constants.reportUserWaitingKey)
433-
if (others?.length === 1 && !adderUsername) {
434-
adderUsername = others[0]
435-
others = undefined
436-
}
437-
438-
const _allKnownBlocks = C.useUsersState(s => s.blockMap)
439-
const loadingWaiting = C.Waiting.useAnyWaiting(Constants.getUserBlocksWaitingKey)
440-
441-
const onClose = C.useRouterState(s => s.dispatch.navigateUp)
442-
const leaveTeam = C.useTeamsState(s => s.dispatch.leaveTeam)
443-
const leaveTeamAndBlock = React.useCallback(
444-
(teamname: string) => {
445-
leaveTeam(teamname, true, 'chat')
446-
},
447-
[leaveTeam]
448-
)
449-
const getBlockState = C.useUsersState(s => s.dispatch.getBlockState)
450-
const _reportUser = C.useUsersState(s => s.dispatch.reportUser)
451-
const refreshBlocksFor = getBlockState
452-
const reportUser = React.useCallback(
453-
(username: string, conversationIDKey: string | undefined, report: ReportSettings) => {
454-
_reportUser({
455-
comment: report.extraNotes,
456-
conversationIDKey,
457-
includeTranscript: report.includeTranscript && !!conversationIDKey,
458-
reason: report.reason,
459-
username,
460-
})
461-
},
462-
[_reportUser]
463-
)
464-
const setConversationStatus = C.useChatContext(s => s.dispatch.blockConversation)
465-
const _setUserBlocks = C.useUsersState(s => s.dispatch.setUserBlocks)
466-
const setUserBlocks = React.useCallback(
467-
(newBlocks: NewBlocksMap) => {
468-
// Convert our state block array to action payload.
469-
const blocks = [...newBlocks.entries()]
470-
.filter(
471-
([_, userBlocks]) => userBlocks.chatBlocked !== undefined || userBlocks.followBlocked !== undefined
472-
)
473-
.map(([username, userBlocks]) => ({
474-
setChatBlock: userBlocks.chatBlocked,
475-
setFollowBlock: userBlocks.followBlocked,
476-
username,
477-
}))
478-
if (blocks.length) {
479-
_setUserBlocks(blocks)
480-
}
481-
},
482-
[_setUserBlocks]
483-
)
484-
485-
const otherUsernames = others && others.length > 0 ? others : undefined
486-
const props = {
487-
adderUsername,
488-
blockUserByDefault,
489-
context,
490-
conversationIDKey,
491-
filterUserByDefault,
492-
finishWaiting: waitingForLeave || waitingForBlocking || waitingForReport,
493-
flagUserByDefault,
494-
isBlocked: (username: string, which: BlockType) => {
495-
const blockObj = _allKnownBlocks.get(username)
496-
return blockObj ? blockObj[which] : false
497-
},
498-
loadingWaiting,
499-
onClose,
500-
onFinish: (newBlocks: NewBlocksMap, blockTeam: boolean) => {
501-
let takingAction = false
502-
if (blockTeam) {
503-
if (teamname) {
504-
takingAction = true
505-
leaveTeamAndBlock(teamname)
506-
} else if (conversationIDKey) {
507-
takingAction = true
508-
const anyReported = [...newBlocks.values()].some(v => v.report !== undefined)
509-
setConversationStatus(anyReported)
510-
}
511-
}
512-
if (newBlocks.size) {
513-
takingAction = true
514-
setUserBlocks(newBlocks)
515-
}
516-
newBlocks.forEach(({report}, username) => report && reportUser(username, conversationIDKey, report))
517-
if (!takingAction) {
518-
onClose()
519-
}
520-
},
521-
otherUsernames,
522-
refreshBlocks: () => {
523-
const usernames = [...(adderUsername ? [adderUsername] : []), ...(otherUsernames || [])]
524-
if (usernames.length) {
525-
refreshBlocksFor(usernames)
526-
}
527-
},
528-
reportsUserByDefault,
529-
teamname,
530-
}
531-
532-
return <BlockModal {...props} />
533-
}
534-
535497
export default Container
536498

537499
const getListHeightStyle = (numOthers: number, expanded: boolean) => ({

shared/chat/conversation/command-markdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as C from '@/constants'
22
import * as Kb from '@/common-adapters'
33
import * as Styles from '@/styles'
44

5-
const Container = () => {
5+
const CommandMarkdown = () => {
66
const md = C.useChatContext(s => s.commandMarkdown)
77
const body = md?.body ?? ''
88
const title = md?.title ?? undefined
@@ -63,4 +63,4 @@ const styles = Styles.styleSheetCreate(
6363
}) as const
6464
)
6565

66-
export default Container
66+
export default CommandMarkdown
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import * as React from 'react'
2-
32
export const ForceListRedrawContext = React.createContext(() => {})

shared/chat/conversation/giphy/container.tsx

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)