mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-05-30 17:16:17 +00:00
Implemented loading of short URLs
This commit is contained in:
33
src/short-urls/ShortUrlsList.js
Normal file
33
src/short-urls/ShortUrlsList.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { listShortUrls } from './reducers/shortUrlsList';
|
||||
|
||||
export class ShortUrlsList extends React.Component {
|
||||
componentDidMount() {
|
||||
const { match } = this.props;
|
||||
this.props.listShortUrls(match.params.serverId);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ul>
|
||||
{this.renderShortUrls()}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
renderShortUrls() {
|
||||
const { shortUrlsList } = this.props;
|
||||
if (! shortUrlsList) {
|
||||
return '<li><i>Loading...</i></li>';
|
||||
}
|
||||
|
||||
return shortUrlsList.map(shortUrl => (
|
||||
<li key={shortUrl.shortCode}>{`${shortUrl.shortCode}`}</li>
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(state => ({
|
||||
shortUrlsList: state.shortUrlsList
|
||||
}), { listShortUrls })(ShortUrlsList);
|
||||
21
src/short-urls/reducers/shortUrlsList.js
Normal file
21
src/short-urls/reducers/shortUrlsList.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { LIST_SHORT_URLS } from '../../reducers/types';
|
||||
import ServersService from '../../servers/services';
|
||||
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
||||
|
||||
export default function shortUrlsListReducer(state = [], action) {
|
||||
switch (action.type) {
|
||||
case LIST_SHORT_URLS:
|
||||
return action.shortUrls;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const listShortUrls = (serverId) => {
|
||||
return async dispatch => {
|
||||
const selectedServer = ServersService.findServerById(serverId);
|
||||
|
||||
ShlinkApiClient.setConfig(selectedServer);
|
||||
dispatch({ type: LIST_SHORT_URLS, shortUrls: await ShlinkApiClient.listShortUrls() });
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user