mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Fixed changing selected server
This commit is contained in:
parent
daf67e1d43
commit
5517fcdde5
3 changed files with 23 additions and 8 deletions
|
@ -5,10 +5,11 @@ import { Link } from 'react-router-dom';
|
|||
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
||||
|
||||
import { listServers } from './reducers/server';
|
||||
import { selectServer } from '../servers/reducers/selectedServer';
|
||||
|
||||
export class ServersDropdown extends React.Component {
|
||||
renderServers = () => {
|
||||
const { servers, selectedServer } = this.props;
|
||||
const { servers, selectedServer, selectServer } = this.props;
|
||||
|
||||
if (isEmpty(servers)) {
|
||||
return <DropdownItem disabled><i>Add a server first...</i></DropdownItem>
|
||||
|
@ -20,6 +21,7 @@ export class ServersDropdown extends React.Component {
|
|||
tag={Link}
|
||||
to={`/server/${id}/list-short-urls/1`}
|
||||
active={selectedServer && selectedServer.id === id}
|
||||
onClick={() => selectServer(id)} // FIXME This should be implicit
|
||||
>
|
||||
{name}
|
||||
</DropdownItem>
|
||||
|
@ -41,4 +43,4 @@ export class ServersDropdown extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default connect(pick(['servers', 'selectedServer']), { listServers })(ServersDropdown);
|
||||
export default connect(pick(['servers', 'selectedServer']), { listServers, selectServer })(ServersDropdown);
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
||||
import ServersService from '../../servers/services/ServersService';
|
||||
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams'
|
||||
|
||||
const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
|
||||
const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
|
||||
|
||||
export default function reducer(state = null, action) {
|
||||
const defaultState = null;
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case SELECT_SERVER:
|
||||
return action.selectedServer;
|
||||
case RESET_SELECTED_SERVER:
|
||||
return null;
|
||||
return defaultState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -17,12 +20,14 @@ export default function reducer(state = null, action) {
|
|||
|
||||
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
|
||||
|
||||
export const selectServer = serverId => {
|
||||
export const selectServer = serverId => dispatch => {
|
||||
dispatch(resetShortUrlParams());
|
||||
|
||||
const selectedServer = ServersService.findServerById(serverId);
|
||||
ShlinkApiClient.setConfig(selectedServer);
|
||||
|
||||
return {
|
||||
dispatch({
|
||||
type: SELECT_SERVER,
|
||||
selectedServer
|
||||
}
|
||||
})
|
||||
};
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
import { LIST_SHORT_URLS } from './shortUrlsList';
|
||||
|
||||
export default function reducer(state = { page: 1 }, action) {
|
||||
const RESET_SHORT_URL_PARAMS = 'shlink/shortUrlsListParams/RESET_SHORT_URL_PARAMS';
|
||||
|
||||
const defaultState = { page: 1 };
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case LIST_SHORT_URLS:
|
||||
return { ...state, ...action.params };
|
||||
case RESET_SHORT_URL_PARAMS:
|
||||
return defaultState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const resetShortUrlParams = () => ({ type: RESET_SHORT_URL_PARAMS });
|
||||
|
|
Loading…
Reference in a new issue