mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-12 02:23:49 +00:00
Implemented loading of short URLs
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { isEmpty } from 'ramda';
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
|
||||
import { isEmpty } from 'ramda';
|
||||
|
||||
import { listServers } from './reducers/server';
|
||||
import { loadServer } from './reducers/selectedServer';
|
||||
|
||||
export class ServersDropdown extends React.Component {
|
||||
renderServers = () => {
|
||||
@@ -16,17 +16,13 @@ export class ServersDropdown extends React.Component {
|
||||
|
||||
return Object.values(servers).map(({ name, id }) => (
|
||||
<span key={id}>
|
||||
<DropdownItem onClick={() => this.selectServer(id)}>
|
||||
<DropdownItem tag={Link} to={`/server/${id}/list-short-urls/1`}>
|
||||
{name}
|
||||
</DropdownItem>
|
||||
</span>
|
||||
));
|
||||
};
|
||||
|
||||
selectServer = serverId => {
|
||||
this.props.loadServer(serverId);
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.props.listServers();
|
||||
}
|
||||
@@ -45,4 +41,4 @@ const mapStateToProps = state => ({
|
||||
servers: state.servers
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, { listServers, loadServer })(ServersDropdown);
|
||||
export default connect(mapStateToProps, { listServers })(ServersDropdown);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import ServersService from '../services';
|
||||
|
||||
const LOAD_SERVER = 'shlink/LOAD_SERVER';
|
||||
import { LOAD_SERVER } from '../../reducers/types';
|
||||
|
||||
export default function selectedServerReducer(state = null, action) {
|
||||
switch (action.type) {
|
||||
case LOAD_SERVER:
|
||||
return action.selectedServer;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export const loadServer = serverId => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import ServersService from '../services';
|
||||
|
||||
const FETCH_SERVERS = 'shlink/FETCH_SERVERS';
|
||||
const CREATE_SERVER = 'shlink/CREATE_SERVER';
|
||||
import { FETCH_SERVERS, CREATE_SERVER } from '../../reducers/types';
|
||||
|
||||
export default function serversReducer(state = {}, action) {
|
||||
switch (action.type) {
|
||||
@@ -9,9 +7,9 @@ export default function serversReducer(state = {}, action) {
|
||||
return action.servers;
|
||||
case CREATE_SERVER:
|
||||
return [ ...state, action.server ];
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export const listServers = () => {
|
||||
|
||||
Reference in New Issue
Block a user