Replace usage of injected selectedServer with useSelectedServer

This commit is contained in:
Alejandro Celaya
2025-11-14 10:27:49 +01:00
parent 7890d0084a
commit 9c1052c10b
15 changed files with 71 additions and 86 deletions

View File

@@ -4,22 +4,23 @@ import { Link } from 'react-router';
import { NoMenuLayout } from '../../common/NoMenuLayout';
import type { FCWithDeps } from '../../container/utils';
import { componentFactory, useDependencies } from '../../container/utils';
import type { SelectedServer, ServersMap } from '../data';
import type { ServersMap } from '../data';
import { isServerWithId } from '../data';
import type { DeleteServerButtonProps } from '../DeleteServerButton';
import { useSelectedServer } from '../reducers/selectedServer';
import { ServersListGroup } from '../ServersListGroup';
type ServerErrorProps = {
servers: ServersMap;
selectedServer: SelectedServer;
};
type ServerErrorDeps = {
DeleteServerButton: FC<DeleteServerButtonProps>;
};
const ServerError: FCWithDeps<ServerErrorProps, ServerErrorDeps> = ({ servers, selectedServer }) => {
const ServerError: FCWithDeps<ServerErrorProps, ServerErrorDeps> = ({ servers }) => {
const { DeleteServerButton } = useDependencies(ServerError);
const { selectedServer } = useSelectedServer();
return (
<NoMenuLayout>

View File

@@ -6,14 +6,8 @@ import type { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientB
import { NoMenuLayout } from '../../common/NoMenuLayout';
import type { FCWithDeps } from '../../container/utils';
import { useDependencies } from '../../container/utils';
import type { SelectedServer } from '../data';
import { isNotFoundServer } from '../data';
import type { SelectServerOptions } from '../reducers/selectedServer';
export type WithSelectedServerProps = {
selectServer: (options: SelectServerOptions) => void;
selectedServer: SelectedServer;
};
import { useSelectedServer } from '../reducers/selectedServer';
export type WithSelectedServerPropsDeps = {
ServerError: FC;
@@ -21,12 +15,12 @@ export type WithSelectedServerPropsDeps = {
};
export function withSelectedServer<T extends object>(
WrappedComponent: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps>,
WrappedComponent: FCWithDeps<T, WithSelectedServerPropsDeps>,
) {
const ComponentWrapper: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps> = (props) => {
const ComponentWrapper: FCWithDeps<T, WithSelectedServerPropsDeps> = (props) => {
const { ServerError, buildShlinkApiClient } = useDependencies(ComponentWrapper);
const params = useParams<{ serverId: string }>();
const { selectServer, selectedServer } = props;
const { selectServer, selectedServer } = useSelectedServer();
useEffect(() => {
if (params.serverId) {