mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-03-14 02:08:41 +03:00
Changed format on action types and reducer names for those already migrated to RTK
This commit is contained in:
parent
89423737e8
commit
fe85291772
15 changed files with 48 additions and 49 deletions
|
@ -1,7 +1,7 @@
|
|||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
const { actions, reducer } = createSlice({
|
||||
name: 'appUpdatesReducer',
|
||||
name: 'shlink/appUpdates',
|
||||
initialState: false,
|
||||
reducers: {
|
||||
appUpdateAvailable: () => true,
|
||||
|
|
|
@ -9,7 +9,7 @@ const initialState: Sidebar = {
|
|||
};
|
||||
|
||||
const { actions, reducer } = createSlice({
|
||||
name: 'sidebarReducer',
|
||||
name: 'shlink/sidebar',
|
||||
initialState,
|
||||
reducers: {
|
||||
sidebarPresent: () => ({ sidebarPresent: true }),
|
||||
|
|
|
@ -9,9 +9,7 @@ import { ProblemDetailsError } from '../../api/types/errors';
|
|||
import { parseApiError } from '../../api/utils';
|
||||
import { EditDomainRedirects } from './domainRedirects';
|
||||
|
||||
const LIST_DOMAINS = 'shlink/domainsList/LIST_DOMAINS';
|
||||
const FILTER_DOMAINS = 'shlink/domainsList/FILTER_DOMAINS';
|
||||
const VALIDATE_DOMAIN = 'shlink/domainsList/VALIDATE_DOMAIN';
|
||||
const REDUCER_PREFIX = 'shlink/domainsList';
|
||||
|
||||
export interface DomainsList {
|
||||
domains: Domain[];
|
||||
|
@ -49,7 +47,7 @@ export const domainsListReducerCreator = (
|
|||
buildShlinkApiClient: ShlinkApiClientBuilder,
|
||||
editDomainRedirects: AsyncThunk<EditDomainRedirects, any, any>,
|
||||
) => {
|
||||
const listDomains = createAsyncThunk(LIST_DOMAINS, async (_: void, { getState }): Promise<ListDomains> => {
|
||||
const listDomains = createAsyncThunk(`${REDUCER_PREFIX}/listDomains`, async (_: void, { getState }): Promise<ListDomains> => {
|
||||
const { listDomains: shlinkListDomains } = buildShlinkApiClient(getState);
|
||||
const { data, defaultRedirects } = await shlinkListDomains();
|
||||
|
||||
|
@ -60,7 +58,7 @@ export const domainsListReducerCreator = (
|
|||
});
|
||||
|
||||
const checkDomainHealth = createAsyncThunk(
|
||||
VALIDATE_DOMAIN,
|
||||
`${REDUCER_PREFIX}/checkDomainHealth`,
|
||||
async (domain: string, { getState }): Promise<ValidateDomain> => {
|
||||
const { selectedServer } = getState();
|
||||
|
||||
|
@ -84,10 +82,10 @@ export const domainsListReducerCreator = (
|
|||
},
|
||||
);
|
||||
|
||||
const filterDomains = createAction<string>(FILTER_DOMAINS);
|
||||
const filterDomains = createAction<string>(`${REDUCER_PREFIX}/filterDomains`);
|
||||
|
||||
const { reducer } = createSlice<DomainsList, SliceCaseReducers<DomainsList>>({
|
||||
name: 'domainsList',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
@import './utils/base';
|
||||
@import 'node_modules/bootstrap/scss/bootstrap.scss';
|
||||
@import './common/react-tag-autocomplete.scss';
|
||||
@import './theme/theme';
|
||||
@import 'utils/theme/theme';
|
||||
@import './utils/table/ResponsiveTable';
|
||||
@import './utils/StickyCardPaginator';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { createAsyncThunk } from '../../utils/helpers/redux';
|
|||
import { ShlinkMercureInfo } from '../../api/types';
|
||||
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
||||
|
||||
const GET_MERCURE_INFO = 'shlink/mercure/GET_MERCURE_INFO';
|
||||
const REDUCER_PREFIX = 'shlink/mercure';
|
||||
|
||||
export interface MercureInfo extends Partial<ShlinkMercureInfo> {
|
||||
interval?: number;
|
||||
|
@ -17,17 +17,20 @@ const initialState: MercureInfo = {
|
|||
};
|
||||
|
||||
export const mercureInfoReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder) => {
|
||||
const loadMercureInfo = createAsyncThunk(GET_MERCURE_INFO, (_: void, { getState }): Promise<ShlinkMercureInfo> => {
|
||||
const { settings } = getState();
|
||||
if (!settings.realTimeUpdates.enabled) {
|
||||
throw new Error('Real time updates not enabled');
|
||||
}
|
||||
const loadMercureInfo = createAsyncThunk(
|
||||
`${REDUCER_PREFIX}/loadMercureInfo`,
|
||||
(_: void, { getState }): Promise<ShlinkMercureInfo> => {
|
||||
const { settings } = getState();
|
||||
if (!settings.realTimeUpdates.enabled) {
|
||||
throw new Error('Real time updates not enabled');
|
||||
}
|
||||
|
||||
return buildShlinkApiClient(getState).mercureInfo();
|
||||
});
|
||||
return buildShlinkApiClient(getState).mercureInfo();
|
||||
},
|
||||
);
|
||||
|
||||
const { reducer } = createSlice({
|
||||
name: 'mercureInfoReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -26,7 +26,7 @@ const serverWithId = (server: ServerWithId | ServerData): ServerWithId => {
|
|||
const serversListToMap = reduce<ServerWithId, ServersMap>((acc, server) => assoc(server.id, server, acc), {});
|
||||
|
||||
export const { actions, reducer } = createSlice({
|
||||
name: 'serversReducer',
|
||||
name: 'shlink/servers',
|
||||
initialState,
|
||||
reducers: {
|
||||
editServer: {
|
||||
|
|
|
@ -82,7 +82,7 @@ const toReducer = (prepare: SettingsPrepareAction) => ({ reducer: commonReducer,
|
|||
const toPreparedAction: SettingsPrepareAction = (payload: Settings) => ({ payload });
|
||||
|
||||
const { reducer, actions } = createSlice({
|
||||
name: 'settingsReducer',
|
||||
name: 'shlink/settings',
|
||||
initialState,
|
||||
reducers: {
|
||||
toggleRealTimeUpdates: toReducer((enabled: boolean) => toPreparedAction({ realTimeUpdates: { enabled } })),
|
||||
|
|
|
@ -5,7 +5,8 @@ import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilde
|
|||
import { parseApiError } from '../../api/utils';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
export const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL';
|
||||
const REDUCER_PREFIX = 'shlink/shortUrlCreation';
|
||||
export const CREATE_SHORT_URL = `${REDUCER_PREFIX}/createShortUrl`;
|
||||
|
||||
export type ShortUrlCreation = {
|
||||
saving: false;
|
||||
|
@ -45,7 +46,7 @@ export const createShortUrl = (buildShlinkApiClient: ShlinkApiClientBuilder) =>
|
|||
|
||||
export const shortUrlCreationReducerCreator = (createShortUrlThunk: ReturnType<typeof createShortUrl>) => {
|
||||
const { reducer, actions } = createSlice({
|
||||
name: 'shortUrlCreationReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState: initialState as ShortUrlCreation, // Without this casting it infers type ShortUrlCreationWaiting
|
||||
reducers: {
|
||||
resetCreateShortUrl: () => initialState,
|
||||
|
|
|
@ -5,7 +5,8 @@ import { parseApiError } from '../../api/utils';
|
|||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
import { ShortUrlIdentifier } from '../data';
|
||||
|
||||
export const SHORT_URL_DELETED = 'shlink/deleteShortUrl/SHORT_URL_DELETED';
|
||||
const REDUCER_PREFIX = 'shlink/shortUrlDeletion';
|
||||
export const SHORT_URL_DELETED = `${REDUCER_PREFIX}/deleteShortUrl`;
|
||||
|
||||
export interface ShortUrlDeletion {
|
||||
shortCode: string;
|
||||
|
@ -35,7 +36,7 @@ export const shortUrlDeletionReducerCreator = (buildShlinkApiClient: ShlinkApiCl
|
|||
);
|
||||
|
||||
const { actions, reducer } = createSlice({
|
||||
name: 'shortUrlDeletion',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {
|
||||
resetDeleteShortUrl: () => initialState,
|
||||
|
|
|
@ -6,7 +6,7 @@ import { shortUrlMatches } from '../helpers';
|
|||
import { parseApiError } from '../../api/utils';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
const GET_SHORT_URL_DETAIL = 'shlink/shortUrlDetail/GET_SHORT_URL_DETAIL';
|
||||
const REDUCER_PREFIX = 'shlink/shortUrlDetail';
|
||||
|
||||
export interface ShortUrlDetail {
|
||||
shortUrl?: ShortUrl;
|
||||
|
@ -24,7 +24,7 @@ const initialState: ShortUrlDetail = {
|
|||
|
||||
export const shortUrlDetailReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder) => {
|
||||
const getShortUrlDetail = createAsyncThunk(
|
||||
GET_SHORT_URL_DETAIL,
|
||||
`${REDUCER_PREFIX}/getShortUrlDetail`,
|
||||
async ({ shortCode, domain }: ShortUrlIdentifier, { getState }): Promise<ShortUrl> => {
|
||||
const { shortUrlsList } = getState();
|
||||
const alreadyLoaded = shortUrlsList?.shortUrls?.data.find((url) => shortUrlMatches(url, shortCode, domain));
|
||||
|
@ -34,7 +34,7 @@ export const shortUrlDetailReducerCreator = (buildShlinkApiClient: ShlinkApiClie
|
|||
);
|
||||
|
||||
const { reducer } = createSlice({
|
||||
name: 'shortUrlDetailReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -5,7 +5,8 @@ import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilde
|
|||
import { parseApiError } from '../../api/utils';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
export const SHORT_URL_EDITED = 'shlink/shortUrlEdition/SHORT_URL_EDITED';
|
||||
const REDUCER_PREFIX = 'shlink/shortUrlEdition';
|
||||
export const SHORT_URL_EDITED = `${REDUCER_PREFIX}/editShortUrl`;
|
||||
|
||||
export interface ShortUrlEdition {
|
||||
shortUrl?: ShortUrl;
|
||||
|
@ -37,7 +38,7 @@ export const shortUrlEditionReducerCreator = (buildShlinkApiClient: ShlinkApiCli
|
|||
);
|
||||
|
||||
const { reducer } = createSlice({
|
||||
name: 'shortUrlEditionReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { createAction, createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { createAction, createSlice } from '@reduxjs/toolkit';
|
||||
import { createAsyncThunk } from '../../utils/helpers/redux';
|
||||
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
||||
import { parseApiError } from '../../api/utils';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
const DELETE_TAG = 'shlink/deleteTag/DELETE_TAG';
|
||||
const TAG_DELETED = 'shlink/deleteTag/TAG_DELETED';
|
||||
const REDUCER_PREFIX = 'shlink/tagDelete';
|
||||
|
||||
export interface TagDeletion {
|
||||
deleting: boolean;
|
||||
|
@ -14,24 +13,22 @@ export interface TagDeletion {
|
|||
errorData?: ProblemDetailsError;
|
||||
}
|
||||
|
||||
export type DeleteTagAction = PayloadAction<string>;
|
||||
|
||||
const initialState: TagDeletion = {
|
||||
deleting: false,
|
||||
deleted: false,
|
||||
error: false,
|
||||
};
|
||||
|
||||
export const tagDeleted = createAction<string>(TAG_DELETED);
|
||||
export const tagDeleted = createAction<string>(`${REDUCER_PREFIX}/tagDeleted`);
|
||||
|
||||
export const tagDeleteReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder) => {
|
||||
const deleteTag = createAsyncThunk(DELETE_TAG, async (tag: string, { getState }): Promise<void> => {
|
||||
const deleteTag = createAsyncThunk(`${REDUCER_PREFIX}/deleteTag`, async (tag: string, { getState }): Promise<void> => {
|
||||
const { deleteTags } = buildShlinkApiClient(getState);
|
||||
await deleteTags([tag]);
|
||||
});
|
||||
|
||||
const { reducer } = createSlice({
|
||||
name: 'tagDeleteReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -6,8 +6,7 @@ import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilde
|
|||
import { parseApiError } from '../../api/utils';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
const EDIT_TAG = 'shlink/editTag/EDIT_TAG';
|
||||
const TAG_EDITED = 'shlink/editTag/TAG_EDITED';
|
||||
const REDUCER_PREFIX = 'shlink/tagEdit';
|
||||
|
||||
export interface TagEdition {
|
||||
oldName?: string;
|
||||
|
@ -32,11 +31,11 @@ const initialState: TagEdition = {
|
|||
error: false,
|
||||
};
|
||||
|
||||
export const tagEdited = createAction<EditTag>(TAG_EDITED);
|
||||
export const tagEdited = createAction<EditTag>(`${REDUCER_PREFIX}/tagEdited`);
|
||||
|
||||
export const tagEditReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder, colorGenerator: ColorGenerator) => {
|
||||
const editTag = createAsyncThunk(
|
||||
EDIT_TAG,
|
||||
`${REDUCER_PREFIX}/editTag`,
|
||||
async ({ oldName, newName, color }: EditTag, { getState }): Promise<EditTag> => {
|
||||
await buildShlinkApiClient(getState).editTag(oldName, newName);
|
||||
colorGenerator.setColorForKey(newName, color);
|
||||
|
@ -46,7 +45,7 @@ export const tagEditReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuild
|
|||
);
|
||||
|
||||
const { reducer } = createSlice({
|
||||
name: 'tagEditReducer',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -12,8 +12,7 @@ import { tagDeleted } from './tagDelete';
|
|||
import { tagEdited } from './tagEdit';
|
||||
import { ProblemDetailsError } from '../../api/types/errors';
|
||||
|
||||
const LIST_TAGS = 'shlink/tagsList/LIST_TAGS';
|
||||
const FILTER_TAGS = 'shlink/tagsList/FILTER_TAGS';
|
||||
const REDUCER_PREFIX = 'shlink/tagsList';
|
||||
|
||||
type TagsStatsMap = Record<string, TagStats>;
|
||||
|
||||
|
@ -66,7 +65,7 @@ const calculateVisitsPerTag = (createdVisits: CreateVisit[]): TagIncrease[] => O
|
|||
);
|
||||
|
||||
export const listTags = (buildShlinkApiClient: ShlinkApiClientBuilder, force = true) => createAsyncThunk(
|
||||
LIST_TAGS,
|
||||
`${REDUCER_PREFIX}/listTags`,
|
||||
async (_: void, { getState }): Promise<ListTags> => {
|
||||
const { tagsList } = getState();
|
||||
|
||||
|
@ -86,13 +85,13 @@ export const listTags = (buildShlinkApiClient: ShlinkApiClientBuilder, force = t
|
|||
},
|
||||
);
|
||||
|
||||
export const filterTags = createAction<string>(FILTER_TAGS);
|
||||
export const filterTags = createAction<string>(`${REDUCER_PREFIX}/filterTags`);
|
||||
|
||||
export const reducer = (
|
||||
listTagsThunk: ReturnType<typeof listTags>,
|
||||
createShortUrlThunk: ReturnType<typeof createShortUrl>,
|
||||
) => createSlice({
|
||||
name: 'shlink/tagsList',
|
||||
name: REDUCER_PREFIX,
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@import '../utils/base';
|
||||
@import '../base';
|
||||
|
||||
// Light theme colors
|
||||
$lightPrimaryColor: #ffffff;
|
Loading…
Add table
Reference in a new issue