mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-08-02 00:51:52 +00:00
Defined visit stats page
This commit is contained in:
46
src/short-urls/reducers/shortUrlVisits.js
Normal file
46
src/short-urls/reducers/shortUrlVisits.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
||||
|
||||
const GET_SHORT_URL_VISITS_START = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_START';
|
||||
const GET_SHORT_URL_VISITS_ERROR = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_ERROR';
|
||||
const GET_SHORT_URL_VISITS = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS';
|
||||
|
||||
const initialState = {
|
||||
visits: [],
|
||||
loading: false,
|
||||
error: false
|
||||
};
|
||||
|
||||
export default function dispatch (state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case GET_SHORT_URL_VISITS_START:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
};
|
||||
case GET_SHORT_URL_VISITS_ERROR:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: true
|
||||
};
|
||||
case GET_SHORT_URL_VISITS:
|
||||
return {
|
||||
visits: action.visits,
|
||||
loading: false,
|
||||
error: false
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const getShortUrlVisits = shortCode => async dispatch => {
|
||||
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
||||
|
||||
try {
|
||||
const visits = await ShlinkApiClient.getShortUrlVisits(shortCode);
|
||||
dispatch({ visits, type: GET_SHORT_URL_VISITS });
|
||||
} catch (e) {
|
||||
dispatch({ type: GET_SHORT_URL_VISITS_ERROR });
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,8 @@
|
||||
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
||||
import ServersService from '../../servers/services/ServersService';
|
||||
|
||||
export const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
|
||||
export const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
|
||||
const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
|
||||
const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
|
||||
export const LIST_SHORT_URLS = 'shlink/shortUrlsList/LIST_SHORT_URLS';
|
||||
export const UPDATE_SHORT_URLS_LIST = LIST_SHORT_URLS;
|
||||
|
||||
const initialState = {
|
||||
shortUrls: [],
|
||||
@@ -32,16 +30,7 @@ export default function reducer(state = initialState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const listShortUrls = (serverId, params = {}) => {
|
||||
// FIXME There should be a way to not need this, however, the active server is set when any route is loaded, in an
|
||||
// FIXME outer component's componentDidMount, which makes it be invoked after this action
|
||||
const selectedServer = ServersService.findServerById(serverId);
|
||||
ShlinkApiClient.setConfig(selectedServer);
|
||||
|
||||
return updateShortUrlsList(params);
|
||||
};
|
||||
|
||||
export const updateShortUrlsList = (params = {}) => async dispatch => {
|
||||
export const listShortUrls = (params = {}) => async dispatch => {
|
||||
dispatch({ type: LIST_SHORT_URLS_START });
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { UPDATE_SHORT_URLS_LIST, LIST_SHORT_URLS } from './shortUrlsList';
|
||||
import { LIST_SHORT_URLS } from './shortUrlsList';
|
||||
|
||||
export default function reducer(state = { page: 1 }, action) {
|
||||
switch (action.type) {
|
||||
case UPDATE_SHORT_URLS_LIST:
|
||||
case LIST_SHORT_URLS:
|
||||
return { ...state, ...action.params };
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user