mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-11 09:06:20 +00:00
Infer redux types when possible
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
import type { ShlinkState } from '../../container/types';
|
||||
|
||||
export const migrateDeprecatedSettings = (state: Partial<ShlinkState>): Partial<ShlinkState> => {
|
||||
if (!state.settings) {
|
||||
return state;
|
||||
}
|
||||
|
||||
export const migrateDeprecatedSettings = (state: any): any => {
|
||||
// The "last180Days" interval had a typo, with a lowercase d
|
||||
if (state.settings.visits && (state.settings.visits.defaultInterval as any) === 'last180days') {
|
||||
if (state.settings?.visits?.defaultInterval === 'last180days') {
|
||||
state.settings.visits.defaultInterval = 'last180Days';
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import { mergeDeepRight } from '@shlinkio/data-manipulation';
|
||||
import { getSystemPreferredTheme } from '@shlinkio/shlink-frontend-kit';
|
||||
import type { Settings, ShortUrlsListSettings } from '@shlinkio/shlink-web-component/settings';
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import type { ShlinkState } from '../../container/types';
|
||||
import { useAppDispatch, useAppSelector } from '../../store';
|
||||
import type { Defined } from '../../utils/types';
|
||||
|
||||
type ShortUrlsOrder = Defined<ShortUrlsListSettings['defaultOrdering']>;
|
||||
@@ -46,9 +45,9 @@ export const { setSettings } = actions;
|
||||
export const settingsReducer = reducer;
|
||||
|
||||
export const useSettings = () => {
|
||||
const dispatch = useDispatch();
|
||||
const dispatch = useAppDispatch();
|
||||
const setSettings = useCallback((settings: Settings) => dispatch(actions.setSettings(settings)), [dispatch]);
|
||||
const settings = useSelector((state: ShlinkState) => state.settings);
|
||||
const settings = useAppSelector((state) => state.settings);
|
||||
|
||||
return { settings, setSettings };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user