Skip to content

Commit

Permalink
Remove unused hub client
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Apr 3, 2024
1 parent e716fd5 commit 8361cb9
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/common/AxiosContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { createContext, useContext } from 'react';
import { AxiosClient } from './axiosclient';

export const AxiosContext = createContext<{
hubClient: AxiosClient;
serviceClient: AxiosClient;
}>({ hubClient: new AxiosClient({}), serviceClient: new AxiosClient({}) });
}>({ serviceClient: new AxiosClient({}) });

export const useAxios = () => {
return useContext(AxiosContext);
Expand Down
5 changes: 1 addition & 4 deletions src/common/axiosclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import urlJoin from 'url-join';
import { encodeUriComponents } from './utils';
import axios, { AxiosInstance } from 'axios';

export const API_PREFIX = 'api';
export const SPAWN_PREFIX = 'spawn';
export class AxiosClient {
constructor(options: AxiosClient.IOptions) {
this._baseUrl = options.baseUrl ?? '';
Expand All @@ -15,14 +13,13 @@ export class AxiosClient {

async request<T = any>(args: {
method: 'get' | 'post' | 'put' | 'option' | 'delete';
prefix?: 'api' | 'spawn';
path: string;
query?: string;
data?: { [key: string]: any } | FormData;
params?: { [key: string]: string };
}): Promise<T> {
const { method, path, params } = args;
const prefix = args.prefix ?? '';
const prefix = 'api';
const data = args.data ?? {};
let url = urlJoin(prefix, encodeUriComponents(path));
if (args.query) {
Expand Down
8 changes: 1 addition & 7 deletions src/environments/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export interface IAppProps {
export default function App(props: IAppProps) {
const jhData = useJupyterhub();

const hubClient = useMemo(() => {
const baseUrl = jhData.hubPrefix;
const xsrfToken = jhData.xsrfToken;
return new AxiosClient({ baseUrl, xsrfToken });
}, [jhData]);

const serviceClient = useMemo(() => {
const baseUrl = jhData.servicePrefix;
const xsrfToken = jhData.xsrfToken;
Expand All @@ -34,7 +28,7 @@ export default function App(props: IAppProps) {

return (
<ThemeProvider theme={customTheme}>
<AxiosContext.Provider value={{ hubClient, serviceClient }}>
<AxiosContext.Provider value={{ serviceClient }}>
<ScopedCssBaseline>
<Stack sx={{ padding: 1 }} spacing={1}>
<NewEnvironmentDialog
Expand Down
2 changes: 0 additions & 2 deletions src/environments/NewEnvironmentDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '@mui/material';
import { Fragment, memo, useCallback, useMemo, useState } from 'react';

import { API_PREFIX } from '../common/axiosclient';
import { useAxios } from '../common/AxiosContext';
import { SmallTextField } from '../common/SmallTextField';
import { ENV_PREFIX } from './types';
Expand Down Expand Up @@ -174,7 +173,6 @@ function _NewEnvironmentDialog(props: INewEnvironmentDialogProps) {
data.password = data.password ?? '';
const response = await axios.serviceClient.request({
method: 'post',
prefix: API_PREFIX,
path: ENV_PREFIX,
data
});
Expand Down
2 changes: 0 additions & 2 deletions src/environments/RemoveEnvironmentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { memo, useCallback } from 'react';
import { useAxios } from '../common/AxiosContext';
import { ButtonWithConfirm } from '../common/ButtonWithConfirm';
import { ENV_PREFIX } from './types';
import { API_PREFIX } from '../common/axiosclient';

interface IRemoveEnvironmentButton {
name: string;
Expand All @@ -18,7 +17,6 @@ function _RemoveEnvironmentButton(props: IRemoveEnvironmentButton) {
const removeEnv = useCallback(async () => {
const response = await axios.serviceClient.request({
method: 'delete',
prefix: API_PREFIX,
path: ENV_PREFIX,
data: { name: props.image }
});
Expand Down
8 changes: 1 addition & 7 deletions src/servers/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export interface IAppProps {
export default function App(props: IAppProps) {
const jhData = useJupyterhub();

const hubClient = useMemo(() => {
const baseUrl = jhData.hubPrefix;
const xsrfToken = jhData.xsrfToken;
return new AxiosClient({ baseUrl, xsrfToken });
}, [jhData]);

const serviceClient = useMemo(() => {
const baseUrl = jhData.servicePrefix;
const xsrfToken = jhData.xsrfToken;
Expand All @@ -36,7 +30,7 @@ export default function App(props: IAppProps) {

return (
<ThemeProvider theme={customTheme}>
<AxiosContext.Provider value={{ hubClient, serviceClient }}>
<AxiosContext.Provider value={{ serviceClient }}>
<ScopedCssBaseline>
<Stack sx={{ padding: 1 }} spacing={1}>
<NewServerDialog
Expand Down
1 change: 0 additions & 1 deletion src/servers/NewServerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function _NewServerDialog(props: INewServerDialogProps) {
setLoading(true);
await axios.serviceClient.request({
method: 'post',
prefix: 'api',
path: SERVER_PREFIX,
data
});
Expand Down
1 change: 0 additions & 1 deletion src/servers/OpenServerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function _OpenServerButton(props: IOpenServerButton) {
try {
await axios.serviceClient.request({
method: 'post',
prefix: 'api',
path: SERVER_PREFIX,
data
});
Expand Down
1 change: 0 additions & 1 deletion src/servers/RemoveServerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function _RemoveServerButton(props: IRemoveServerButton) {
await axios.serviceClient.request({
method: 'delete',
path: SERVER_PREFIX,
prefix: 'api',
data: {
userName: jhData.user,
serverName: props.server
Expand Down

0 comments on commit 8361cb9

Please sign in to comment.