mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 04:53:49 +00:00
Replace usage of injected selectedServer with useSelectedServer
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user