Fix mercure info loading in shlink-web-component

This commit is contained in:
Alejandro Celaya
2023-07-27 09:22:03 +02:00
parent d49da185d3
commit 0169060de7
7 changed files with 22 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
import { createSlice } from '@reduxjs/toolkit';
import type { ShlinkApiClient, ShlinkMercureInfo } from '../../api-contract';
import { createAsyncThunk } from '../../utils/redux';
import type { Settings } from '../../utils/settings';
const REDUCER_PREFIX = 'shlink/mercure';
@@ -18,15 +19,13 @@ const initialState: MercureInfo = {
export const mercureInfoReducerCreator = (apiClientFactory: () => ShlinkApiClient) => {
const loadMercureInfo = createAsyncThunk(
`${REDUCER_PREFIX}/loadMercureInfo`,
(): Promise<ShlinkMercureInfo> =>
// FIXME Get settings here somehow, as they are only available via hook
// const { settings } = getState();
// if (!settings.realTimeUpdates.enabled) {
// throw new Error('Real time updates not enabled');
// }
({ realTimeUpdates }: Settings): Promise<ShlinkMercureInfo> => {
if (realTimeUpdates && !realTimeUpdates.enabled) {
throw new Error('Real time updates not enabled');
}
apiClientFactory().mercureInfo()
,
return apiClientFactory().mercureInfo();
},
);
const { reducer } = createSlice({