mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-13 11:03:50 +00:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
|
|
import { OrderDir } from '../../utils/helpers/ordering';
|
|
import { LIST_SHORT_URLS, ListShortUrlsAction } from './shortUrlsList';
|
|
|
|
export const RESET_SHORT_URL_PARAMS = 'shlink/shortUrlsListParams/RESET_SHORT_URL_PARAMS';
|
|
|
|
export const SORTABLE_FIELDS = {
|
|
dateCreated: 'Created at',
|
|
shortCode: 'Short URL',
|
|
longUrl: 'Long URL',
|
|
title: 'Title',
|
|
visits: 'Visits',
|
|
};
|
|
|
|
export type OrderableFields = keyof typeof SORTABLE_FIELDS;
|
|
|
|
export type OrderBy = Partial<Record<OrderableFields, OrderDir>>;
|
|
|
|
export interface ShortUrlsListParams {
|
|
page?: string;
|
|
itemsPerPage?: number;
|
|
orderBy?: OrderBy;
|
|
}
|
|
|
|
const initialState: ShortUrlsListParams = {
|
|
page: '1',
|
|
orderBy: { dateCreated: 'DESC' },
|
|
};
|
|
|
|
export default buildReducer<ShortUrlsListParams, ListShortUrlsAction>({
|
|
[LIST_SHORT_URLS]: (state, { params }) => ({ ...state, ...params }),
|
|
[RESET_SHORT_URL_PARAMS]: () => initialState,
|
|
}, initialState);
|
|
|
|
export const resetShortUrlParams = buildActionCreator(RESET_SHORT_URL_PARAMS);
|