Skip to content

Commit eac5d6b

Browse files
committed
Temp
1 parent f03812a commit eac5d6b

10 files changed

Lines changed: 233 additions & 174 deletions

File tree

apps/demo/src/H5GroveApp.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { App, assertEnvVar, H5GroveProvider } from '@h5web/app';
22
import axios from 'axios';
3-
import { useMemo } from 'react';
43
import { useSearchParams } from 'wouter';
54

5+
import { createAxiosFetcher } from '../../../packages/app/src/providers/utils';
66
import { getFeedbackURL } from './utils';
77

88
const URL = import.meta.env.VITE_H5GROVE_URL;
99
const FILEPATH = import.meta.env.VITE_H5GROVE_FALLBACK_FILEPATH;
1010

11+
const fetcher = createAxiosFetcher(axios);
12+
1113
function H5GroveApp() {
1214
assertEnvVar(URL, 'VITE_H5GROVE_URL');
1315
assertEnvVar(FILEPATH, 'VITE_H5GROVE_FALLBACK_FILEPATH');
1416

1517
const [searchParams] = useSearchParams();
1618
const filepath = searchParams.get('file') || FILEPATH;
1719

18-
const client = useMemo(() => {
19-
return axios.create({ adapter: 'fetch', baseURL: URL });
20-
}, []);
21-
2220
return (
23-
<H5GroveProvider filepath={filepath} axiosClient={client}>
21+
<H5GroveProvider baseUrl={URL} filepath={filepath} fetcher={fetcher}>
2422
<App
2523
sidebarOpen={!searchParams.has('wide')}
2624
getFeedbackURL={getFeedbackURL}

packages/app/src/ErrorFallback.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type FallbackProps } from 'react-error-boundary';
22

33
import styles from './App.module.css';
4-
import { CANCELLED_ERROR_MSG } from './providers/utils';
4+
import { AbortError, CANCELLED_BY_USER } from './providers/utils';
55

66
interface Props extends FallbackProps {
77
className?: string;
@@ -11,10 +11,10 @@ interface Props extends FallbackProps {
1111
function ErrorFallback(props: Props) {
1212
const { className = '', error, resetErrorBoundary } = props;
1313

14-
if (error instanceof Error && error.message === CANCELLED_ERROR_MSG) {
14+
if (error instanceof AbortError && error.message === CANCELLED_BY_USER) {
1515
return (
1616
<p className={`${styles.error} ${className}`}>
17-
{CANCELLED_ERROR_MSG}
17+
Request cancelled
1818
<span></span>
1919
<button
2020
className={styles.retryBtn}

packages/app/src/providers/h5grove/H5GroveProvider.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import { type AxiosInstance } from 'axios';
21
import { type PropsWithChildren, useMemo } from 'react';
32

43
import { type DataProviderApi } from '../api';
54
import DataProvider from '../DataProvider';
5+
import { type Fetcher } from '../models';
66
import { H5GroveApi } from './h5grove-api';
77

88
interface Props {
9+
baseUrl: string;
910
filepath: string;
10-
axiosClient: AxiosInstance;
1111
resetKeys?: unknown[];
12+
fetcher?: Fetcher;
1213
getExportURL?: DataProviderApi['getExportURL'];
1314
}
1415

1516
function H5GroveProvider(props: PropsWithChildren<Props>) {
1617
const {
18+
baseUrl,
1719
filepath,
18-
axiosClient,
1920
resetKeys = [],
21+
fetcher,
2022
getExportURL,
2123
children,
2224
} = props;
2325

2426
const api = useMemo(
25-
() => new H5GroveApi(filepath, axiosClient, getExportURL),
26-
[filepath, axiosClient, ...resetKeys, getExportURL], // eslint-disable-line react-hooks/exhaustive-deps
27+
() => new H5GroveApi(filepath, baseUrl, fetcher, getExportURL),
28+
[filepath, ...resetKeys, fetcher, getExportURL], // eslint-disable-line react-hooks/exhaustive-deps
2729
);
2830

2931
return <DataProvider api={api}>{children}</DataProvider>;

packages/app/src/providers/h5grove/h5grove-api.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
assertGroupWithChildren,
66
hasNonNullShape,
77
} from '@h5web/shared/guards';
8-
import axios from 'axios';
98
import { beforeAll, expect, test } from 'vitest';
109

1110
import { assertListeningAt } from '../../test-utils';
@@ -23,8 +22,7 @@ beforeAll(async () => {
2322
});
2423

2524
test.skipIf(SKIP)('test file matches snapshot', async () => {
26-
const client = axios.create({ adapter: 'fetch', baseURL: H5GROVE_URL });
27-
const api = new H5GroveApi(TEST_FILE, client);
25+
const api = new H5GroveApi(TEST_FILE, H5GROVE_URL);
2826

2927
const root = await api.getEntity('/');
3028
assertGroup(root);

0 commit comments

Comments
 (0)