Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load general channel when loading add to channel modal #22003

Merged
merged 5 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions shared/chat/conversation/info-panel/add-to-channel/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,31 @@ const mapStateToProps = (state: Container.TypedState, ownProps: OwnProps) => {
const meta = Constants.getMeta(state, conversationIDKey)
const participantInfo = Constants.getParticipantInfo(state, conversationIDKey)
const teamname = meta.teamname
const generalChannel = Constants.getChannelForTeam(state, teamname, 'general')
const generalParts = Constants.getParticipantInfo(state, generalChannel.conversationIDKey)
const generalChannel = Constants.getGeneralChannelForBigTeam(state, teamname)
const generalParts = Constants.getParticipantInfo(state, generalChannel)
const _fullnames = state.users.infoMap
const title = `Add to #${meta.channelname}`
return {
_allMembers: generalChannel ? generalParts.all : [],
_alreadyAdded: participantInfo.all,
_conversationIDKey: conversationIDKey,
_fullnames,
_generalChannel: generalChannel,
error: anyErrors(state, Constants.waitingKeyAddUsersToChannel),
title,
}
}

const mapDispatchToProps = (dispatch: Container.TypedDispatch) => ({
_onLoad: (generalChannel: Types.ConversationIDKey) => {
dispatch(
Chat2Gen.createMetaRequestTrusted({
conversationIDKeys: [generalChannel],
force: true,
reason: 'requestTeamsUnboxing',
})
)
},
_onSubmit: (conversationIDKey: Types.ConversationIDKey, usernames: Array<string>) =>
dispatch(Chat2Gen.createAddUsersToChannel({conversationIDKey, usernames})),
onCancel: () => {
Expand Down Expand Up @@ -66,6 +76,10 @@ export default Container.namedConnect(
error,
onBack: null,
onCancel: dispatchProps.onCancel,
onLoad:
stateProps._allMembers.length === 0
? () => dispatchProps._onLoad(stateProps._generalChannel)
: undefined,
onSubmit: (usernames: Array<string>) =>
dispatchProps._onSubmit(stateProps._conversationIDKey, usernames),
title: stateProps.title,
Expand Down
77 changes: 43 additions & 34 deletions shared/chat/conversation/info-panel/add-to-channel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type User = {
type Props = {
error: string | null
onCancel: () => void
onLoad?: () => void
onSubmit: (usernames: Array<string>) => void
title: string
users: Array<User>
Expand Down Expand Up @@ -84,6 +85,10 @@ class AddToChannel extends React.Component<Props, State> {
/>
)

componentDidMount() {
this.props.onLoad?.()
}

render() {
const items = this.props.users.map(u => ({...u, selected: this.state.selected.has(u.username)}))
return (
Expand All @@ -96,45 +101,49 @@ class AddToChannel extends React.Component<Props, State> {
gap="small"
>
{!Styles.isMobile && <Kb.Text type="Header">{this.props.title}</Kb.Text>}
<Kb.Box2 direction="vertical" fullWidth={true} gap="tiny" style={styles.flexOne}>
<Kb.BoxGrow style={styles.listContainer}>
<Kb.List2
style={styles.list}
items={items}
keyProperty="username"
renderItem={this._renderItem}
itemHeight={this._itemHeight}
/>
</Kb.BoxGrow>
<Kb.Box2 direction="vertical" alignItems="center" fullWidth={true}>
<Kb.ButtonBar direction="row">
{!Styles.isMobile && (
{this.props.users.length === 0 ? (
<Kb.ProgressIndicator type="Large" />
) : (
<Kb.Box2 direction="vertical" fullWidth={true} gap="tiny" style={styles.flexOne}>
<Kb.BoxGrow style={styles.listContainer}>
<Kb.List2
style={styles.list}
items={items}
keyProperty="username"
renderItem={this._renderItem}
itemHeight={this._itemHeight}
/>
</Kb.BoxGrow>
<Kb.Box2 direction="vertical" alignItems="center" fullWidth={true}>
<Kb.ButtonBar direction="row">
{!Styles.isMobile && (
<Kb.WaitingButton
onlyDisable={true}
waitingKey={this.props.waitingKey || null}
type="Dim"
label="Cancel"
onClick={this.props.onCancel}
/>
)}
<Kb.WaitingButton
onlyDisable={true}
disabled={!this.state.selected.size}
waitingKey={this.props.waitingKey || null}
type="Dim"
label="Cancel"
onClick={this.props.onCancel}
label={
this.state.selected.size
? `Add ${this.state.selected.size} ${pluralize('user', this.state.selected.size)}`
: 'Add'
}
onClick={() => this.props.onSubmit([...this.state.selected])}
/>
</Kb.ButtonBar>
{!!this.props.error && (
<Kb.Text type="BodySmallError" center={true}>
{this.props.error}
</Kb.Text>
)}
<Kb.WaitingButton
disabled={!this.state.selected.size}
waitingKey={this.props.waitingKey || null}
label={
this.state.selected.size
? `Add ${this.state.selected.size} ${pluralize('user', this.state.selected.size)}`
: 'Add'
}
onClick={() => this.props.onSubmit([...this.state.selected])}
/>
</Kb.ButtonBar>
{!!this.props.error && (
<Kb.Text type="BodySmallError" center={true}>
{this.props.error}
</Kb.Text>
)}
</Kb.Box2>
</Kb.Box2>
</Kb.Box2>
)}
</Kb.Box2>
)
}
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/chat2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ export const getParticipantSuggestions = (state: TypedState, id: Types.Conversat

export {
getBotCommands,
getChannelForTeam,
getCommands,
getConversationIDKeyMetasToLoad,
getEffectiveRetentionPolicy,
getGeneralChannelForBigTeam,
getMeta,
getRowParticipants,
getRowStyles,
Expand Down
12 changes: 9 additions & 3 deletions shared/constants/chat2/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,15 @@ const emptyMeta = makeConversationMeta()
export const getMeta = (state: TypedState, id: Types.ConversationIDKey) =>
state.chat2.metaMap.get(id) || emptyMeta

export const getChannelForTeam = (state: TypedState, teamname: string, channelname: string) =>
[...state.chat2.metaMap.values()].find(m => m.teamname === teamname && m.channelname === channelname) ||
emptyMeta
export const getGeneralChannelForBigTeam = (state: TypedState, teamname: string) => {
const t = state.chat2.inboxLayout?.bigTeams?.find(
m =>
m.state === RPCChatTypes.UIInboxBigTeamRowTyp.channel &&
m.channel.teamname === teamname &&
m.channel.channelname === 'general'
)
return t?.state === RPCChatTypes.UIInboxBigTeamRowTyp.channel ? t.channel.convID : noConversationIDKey
}

const blankCommands: Array<RPCChatTypes.ConversationCommand> = []

Expand Down