Skip to content

Commit 07a59a6

Browse files
container removal (#28616)
1 parent 5970b58 commit 07a59a6

File tree

145 files changed

+1326
-1458
lines changed

Some content is hidden

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

145 files changed

+1326
-1458
lines changed

shared/chat/blocking/block-modal/index.tsx renamed to shared/chat/blocking/block-modal.tsx

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react'
22
import * as Kb from '@/common-adapters'
33
import * as Styles from '@/styles'
4+
import * as C from '@/constants'
5+
import * as Constants from '@/constants/users'
46

57
// Type for extra RouteProp passed to block modal sometimes when launching the
68
// modal from specific places from the app.
@@ -35,6 +37,18 @@ export type Props = {
3537
teamname?: string
3638
}
3739

40+
type OwnProps = {
41+
blockUserByDefault?: boolean
42+
filterUserByDefault?: boolean
43+
flagUserByDefault?: boolean
44+
reportsUserByDefault?: boolean
45+
context?: BlockModalContext
46+
conversationIDKey?: string
47+
others?: Array<string>
48+
team?: string
49+
username?: string
50+
}
51+
3852
type CheckboxRowProps = {
3953
checked: boolean
4054
disabled?: boolean
@@ -407,7 +421,118 @@ const BlockModal = React.memo(function BlockModal(p: Props) {
407421
)
408422
})
409423

410-
export default BlockModal
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+
535+
export default Container
411536

412537
const getListHeightStyle = (numOthers: number, expanded: boolean) => ({
413538
height:

shared/chat/blocking/block-modal/container.tsx

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

shared/chat/blocking/invitation-to-block.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as C from '@/constants'
22
import * as Kb from '@/common-adapters'
33
import * as Styles from '@/styles'
4-
import * as Container from '@/util/container'
4+
import {useSafeNavigation} from '@/util/safe-navigation'
55

66
const BlockButtons = () => {
7-
const nav = Container.useSafeNavigation()
7+
const nav = useSafeNavigation()
88
const conversationIDKey = C.useChatContext(s => s.id)
99

1010
const team = C.useChatContext(s => s.meta.teamname)

shared/chat/conversation/info-panel/add-to-channel.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 React from 'react'
33
import * as Kb from '@/common-adapters'
44
import * as Styles from '@/styles'
5-
import * as Container from '@/util/container'
5+
import {useSafeNavigation} from '@/util/safe-navigation'
66
import * as T from '@/constants/types'
77
import {useTeamDetailsSubscribe} from '@/teams/subscriber'
88
import {pluralize} from '@/util/string'
@@ -12,7 +12,7 @@ type Props = {teamID: T.Teams.TeamID}
1212

1313
const AddToChannel = (props: Props) => {
1414
const {teamID} = props
15-
const nav = Container.useSafeNavigation()
15+
const nav = useSafeNavigation()
1616
const conversationIDKey = C.useChatContext(s => s.id)
1717

1818
const [toAdd, setToAdd] = React.useState<Set<string>>(new Set())

shared/chat/conversation/info-panel/settings/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as T from '@/constants/types'
44
import * as React from 'react'
55
import MinWriterRole from './min-writer-role'
66
import Notifications from './notifications'
7-
import RetentionPicker from '@/teams/team/settings-tab/retention/container'
7+
import RetentionPicker from '@/teams/team/settings-tab/retention'
88

99
type EntityType = 'adhoc' | 'small team' | 'channel'
1010
type SettingsPanelProps = {isPreview: boolean}

shared/chat/delete-history-warning/index.tsx renamed to shared/chat/delete-history-warning.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Kb from '@/common-adapters'
2+
import * as C from '@/constants'
23

34
type Props = {
45
onCancel: () => void
@@ -85,4 +86,22 @@ const styles = Kb.Styles.styleSheetCreate(
8586
}) as const
8687
)
8788

88-
export default DeleteHistoryWarning
89+
const Container = () => {
90+
const navigateUp = C.useRouterState(s => s.dispatch.navigateUp)
91+
const onCancel = () => {
92+
navigateUp()
93+
}
94+
const clearModals = C.useRouterState(s => s.dispatch.clearModals)
95+
const messageDeleteHistory = C.useChatContext(s => s.dispatch.messageDeleteHistory)
96+
const onDeleteHistory = () => {
97+
clearModals()
98+
messageDeleteHistory()
99+
}
100+
const props = {
101+
onCancel,
102+
onDeleteHistory,
103+
}
104+
return <DeleteHistoryWarning {...props} />
105+
}
106+
107+
export default Container

shared/chat/delete-history-warning/container.tsx

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

shared/chat/inbox/row/build-team.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as C from '@/constants'
22
import * as React from 'react'
33
import * as Kb from '@/common-adapters'
4-
import * as Container from '@/util/container'
4+
import {useSafeNavigation} from '@/util/safe-navigation'
55

66
const BuildTeam = React.memo(function BuildTeam() {
7-
const nav = Container.useSafeNavigation()
7+
const nav = useSafeNavigation()
88
const launchNewTeamWizardOrModal = C.useTeamsState(s => s.dispatch.launchNewTeamWizardOrModal)
99
const switchTab = C.useRouterState(s => s.dispatch.switchTab)
1010
const onCreateTeam = () => {

shared/chat/new-team-dialog-container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as C from '@/constants'
2-
import NewTeamDialog from '../teams/new-team'
2+
import {CreateNewTeam} from '../teams/new-team'
33
import upperFirst from 'lodash/upperFirst'
44

55
const Container = () => {
@@ -23,7 +23,7 @@ const Container = () => {
2323
onClearError,
2424
onSubmit,
2525
}
26-
return <NewTeamDialog {...props} />
26+
return <CreateNewTeam {...props} />
2727
}
2828

2929
export default Container

0 commit comments

Comments
 (0)