Skip to content

Commit bd2bc8b

Browse files
authored
hook up remove from channel (keybase#24029)
* hook up remove from channel * hook up error
1 parent 683ef29 commit bd2bc8b

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

‎protocol/bin/enabled-calls.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"chat.1.local.profileChatSearch": {"promise": true},
6868
"chat.1.local.refreshParticipants": {"promise": true},
6969
"chat.1.local.removeBotMember": {"promise": true},
70+
"chat.1.local.removeFromConversationLocal": {"promise": true},
7071
"chat.1.local.requestInboxLayout": {"promise": true},
7172
"chat.1.local.requestInboxSmallIncrease": {"promise": true},
7273
"chat.1.local.requestInboxSmallReset": {"promise": true},

‎shared/common-adapters/confirm-modal/index.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type Props = {
2323
onConfirmDeactivated?: boolean
2424
prompt: React.ReactNode
2525
waitingKey?: string | string[]
26+
waiting?: boolean
2627
}
2728

2829
const ConfirmModal = (props: Props) => (
@@ -53,7 +54,7 @@ const ConfirmModal = (props: Props) => (
5354
{!Styles.isMobile && (
5455
<WaitingButton
5556
key="cancel"
56-
disabled={!props.onCancel}
57+
disabled={!props.onCancel || props.waiting}
5758
type="Dim"
5859
label="Cancel"
5960
onClick={props.onCancel}
@@ -69,6 +70,7 @@ const ConfirmModal = (props: Props) => (
6970
onClick={props.onConfirm}
7071
style={styles.button}
7172
waitingKey={props.waitingKey || null}
73+
waiting={props.waiting}
7274
/>
7375
</ButtonBar>
7476
),

‎shared/constants/teams.tsx‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export const addInviteWaitingKey = (teamname: Types.Teamname, value: string) =>
4343
export const removeMemberWaitingKey = (teamID: Types.TeamID, id: string) => `teamRemove:${teamID};${id}`
4444
export const addToTeamSearchKey = 'addToTeamSearch'
4545
export const teamProfileAddListWaitingKey = 'teamProfileAddList'
46-
export const removeFromChannelWaitingKey = (
47-
conversationIDKey: ChatTypes.ConversationIDKey,
48-
usernameOrAssertion: string
49-
) => `teamChannelRemove:${conversationIDKey};${usernameOrAssertion}`
5046
export const deleteChannelWaitingKey = (teamID: Types.TeamID) => `channelDelete:${teamID}`
5147
export const deleteTeamWaitingKey = (teamID: Types.TeamID) => `teamDelete:${teamID}`
5248
export const leaveTeamWaitingKey = (teamname: Types.Teamname) => `teamLeave:${teamname}`

‎shared/constants/types/rpc-chat-gen.tsx‎

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/teams/confirm-modals/confirm-remove-from-channel.tsx‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Styles from '../../styles'
77
import * as Constants from '../../constants/teams'
88
import * as ChatConstants from '../../constants/chat2'
99
import * as TeamsGen from '../../actions/teams-gen'
10+
import * as RPCChatGen from '../../constants/types/rpc-chat-gen'
1011

1112
type Props = Container.RouteProps<{
1213
members: string[]
@@ -23,8 +24,8 @@ const ConfirmRemoveFromChannel = (props: Props) => {
2324
ChatConstants.noConversationIDKey
2425
)
2526

26-
const waitingKeys = members.map(member => Constants.removeFromChannelWaitingKey(conversationIDKey, member))
27-
const waiting = Container.useAnyWaiting(...waitingKeys)
27+
const [waiting, setWaiting] = React.useState(false)
28+
const [error, setError] = React.useState('')
2829
const channelInfo = Container.useSelector(state =>
2930
Constants.getTeamChannelInfo(state, teamID, conversationIDKey)
3031
)
@@ -34,28 +35,33 @@ const ConfirmRemoveFromChannel = (props: Props) => {
3435
const nav = Container.useSafeNavigation()
3536
const onCancel = React.useCallback(() => dispatch(nav.safeNavigateUpPayload()), [dispatch, nav])
3637

37-
// TODO(Y2K-1592): do this in one RPC
38+
const removeFromChannel = Container.useRPC(RPCChatGen.localRemoveFromConversationLocalRpcPromise)
39+
3840
const onRemove = () => {
39-
dispatch(
40-
TeamsGen.createChannelSetMemberSelected({
41-
clearAll: true,
42-
conversationIDKey,
43-
selected: false,
44-
username: '',
45-
})
41+
setWaiting(true)
42+
setTimeout(() => setWaiting(false), 1000)
43+
removeFromChannel(
44+
[{convID: ChatTypes.keyToConversationID(conversationIDKey), usernames: members}],
45+
_ => {
46+
setWaiting(false)
47+
dispatch(
48+
TeamsGen.createChannelSetMemberSelected({
49+
clearAll: true,
50+
conversationIDKey,
51+
selected: false,
52+
username: '',
53+
})
54+
)
55+
dispatch(nav.safeNavigateUpPayload())
56+
dispatch(TeamsGen.createLoadTeamChannelList({teamID}))
57+
},
58+
err => {
59+
setWaiting(false)
60+
setError(err.message)
61+
}
4662
)
47-
48-
members.forEach(member => console.log(`TODO: ${member} wants to leave channel, not implemented yet`))
4963
}
5064

51-
const wasWaiting = Container.usePrevious(waiting)
52-
React.useEffect(() => {
53-
// TODO: refactor to `useRPC`
54-
if (wasWaiting && !waiting) {
55-
onCancel()
56-
}
57-
}, [waiting, wasWaiting, onCancel])
58-
5965
const prompt = `Remove ${Constants.stringifyPeople(members)} from #${channelname}?`
6066
const header = (
6167
<Kb.Box style={styles.positionRelative}>
@@ -75,7 +81,8 @@ const ConfirmRemoveFromChannel = (props: Props) => {
7581
onCancel={onCancel}
7682
onConfirm={onRemove}
7783
confirmText="Remove from channel"
78-
waitingKey={waitingKeys}
84+
waiting={waiting}
85+
error={error}
7986
/>
8087
)
8188
}

0 commit comments

Comments
 (0)