-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/switch-server-v2' into 'master'
switch server v2 See merge request kchat/webapp!665
- Loading branch information
Showing
43 changed files
with
1,241 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
/* eslint-disable max-lines */ | ||
|
||
import store from 'stores/redux_store'; | ||
|
||
import {SocketEvents} from 'utils/constants'; | ||
|
||
import {changeStatus, setBadges} from './views/servers'; | ||
|
||
const dispatch = store.dispatch; | ||
|
||
type ServerMessage<T> = { | ||
event: string; | ||
serverId: string; | ||
data: T; | ||
} | ||
|
||
export function handleServerEvent(msg: ServerMessage<any>) { | ||
switch (msg.event) { | ||
case SocketEvents.BADGE_UPDATED: | ||
handleBadgeUpdated(msg); | ||
break; | ||
case SocketEvents.TEAM_STATUS_CHANGED: | ||
handleChangeStatus(msg); | ||
break; | ||
} | ||
} | ||
|
||
export const handleBadgeUpdated = (msgProps: ServerMessage<{ badge: number }>) => { | ||
dispatch(setBadges(msgProps.serverId, msgProps.data.badge)); | ||
}; | ||
|
||
export const handleChangeStatus = (msgProps: ServerMessage<{ status: string }>) => { | ||
dispatch(changeStatus(msgProps.serverId, msgProps.data.status)); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {Servers} from 'utils/constants'; | ||
|
||
export function setBadges(serverId: string, badges: number) { | ||
return { | ||
type: Servers.BADGE_UPDATED, | ||
data: { | ||
serverId, | ||
badges, | ||
}, | ||
}; | ||
} | ||
|
||
export function changeStatus(serverId: string, status: string) { | ||
return { | ||
type: Servers.STATUS_UPDATED, | ||
data: { | ||
serverId, | ||
status, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import type {ConnectedProps} from 'react-redux'; | ||
import {connect} from 'react-redux'; | ||
import {withRouter} from 'react-router-dom'; | ||
|
||
import {getTeamsOrderCookie} from 'mattermost-redux/utils/team_utils'; | ||
|
||
import {getCurrentServer, getOtherServers, getServersUnreadStatus, isMultiServer} from 'selectors/views/servers'; | ||
|
||
import type {GlobalState} from 'types/store'; | ||
|
||
import SwitchServer from './switch_server'; | ||
|
||
function mapStateToProps(state: GlobalState) { | ||
const currentServer = getCurrentServer(state); | ||
const servers = getOtherServers(state); | ||
|
||
return { | ||
servers, | ||
currentServer, | ||
unreadStatus: getServersUnreadStatus(state), | ||
userTeamsOrderPreference: getTeamsOrderCookie(), | ||
isMultiServer: isMultiServer(state), | ||
}; | ||
} | ||
|
||
const connector = connect(mapStateToProps, {}); | ||
|
||
export type PropsFromRedux = ConnectedProps<typeof connector>; | ||
|
||
export default withRouter(connector(SwitchServer)); |
19 changes: 19 additions & 0 deletions
19
webapp/channels/src/components/switch_server/switch_item/counter/counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
import type {FC} from 'react'; | ||
|
||
type Props = { | ||
total: number; | ||
} | ||
|
||
const Counter: FC<Props> = ({total}) => { | ||
return ( | ||
<span className='switch-counter'> | ||
{total} | ||
</span> | ||
); | ||
}; | ||
|
||
export default Counter; |
3 changes: 3 additions & 0 deletions
3
webapp/channels/src/components/switch_server/switch_item/counter/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Counter from './counter'; | ||
export default Counter; | ||
|
49 changes: 49 additions & 0 deletions
49
webapp/channels/src/components/switch_server/switch_item/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import type {ConnectedProps} from 'react-redux'; | ||
import {connect} from 'react-redux'; | ||
import type {ActionCreatorsMapObject, Dispatch} from 'redux'; | ||
import {bindActionCreators} from 'redux'; | ||
|
||
import type {Team} from '@mattermost/types/teams'; | ||
|
||
import type {GenericAction, GetStateFunc} from 'mattermost-redux/types/actions'; | ||
|
||
import {switchTeam} from 'actions/team_actions'; | ||
import {makeGetBadgeCountForServerId} from 'selectors/views/servers'; | ||
|
||
import type {GlobalState} from 'types/store'; | ||
import type {Server} from 'types/store/servers'; | ||
|
||
import SwitchItem from './switch_item'; | ||
|
||
type OwnProps = { | ||
server: Server; | ||
} | ||
|
||
function mapStateToProps(state: GlobalState, ownProps: OwnProps) { | ||
return { | ||
unreadCounts: makeGetBadgeCountForServerId(state, ownProps.server.id), | ||
disabled: ownProps.server.status !== 'ok', | ||
}; | ||
} | ||
|
||
type Actions = { | ||
switchTeam: (url: string, team?: Team) => (dispatch: Dispatch<GenericAction>, getState: GetStateFunc) => void; | ||
} | ||
|
||
function mapDispatchToProps(dispatch: Dispatch<GenericAction>) { | ||
return { | ||
actions: bindActionCreators<ActionCreatorsMapObject, Actions>({ | ||
switchTeam, | ||
}, dispatch), | ||
}; | ||
} | ||
|
||
const connector = connect(mapStateToProps, mapDispatchToProps); | ||
|
||
export type PropsFromRedux = ConnectedProps<typeof connector>; | ||
|
||
export default connector(SwitchItem); |
3 changes: 3 additions & 0 deletions
3
webapp/channels/src/components/switch_server/switch_item/label/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Label from './label'; | ||
export default Label; | ||
|
Oops, something went wrong.