Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove axios from client bundle #833

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions/share/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const onRequestPost: PagesFunction<Env> = async (context) => {
JSON.stringify({
'Status': 500,
'Message': e instanceof Error ? e.message : e,
'ShortUrl': null,
'Key': null,
}),
{
'status': 500,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@mui/icons-material": "^6.1.5",
"@mui/material": "^6.1.5",
"@reduxjs/toolkit": "^2.3.0",
"axios": "^1.7.7",
"comlink": "^4.4.1",
"i18next": "^23.16.4",
"js-yaml": "^4.1.0",
Expand Down Expand Up @@ -97,6 +96,7 @@
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"@vitejs/plugin-react": "^4.3.3",
"axios": "^1.7.7",
"babel-plugin-i18next-extract": "^0.10.0",
"concurrently": "^9.0.1",
"eslint": "^8.57.1",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Error, Icon, Item, Progress } from '@discretize/gw2-ui-new';
import { firstUppercase } from '@discretize/react-discretize-components';
import DoneIcon from '@mui/icons-material/Done';
import { Box, Button, ButtonGroup, MenuItem, Select, Typography } from '@mui/material';
import axios from 'axios';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
Expand Down Expand Up @@ -59,9 +58,9 @@ export default function ModalContent({ character, buttons }) {
};

React.useEffect(() => {
axios
.get(`https://api.guildwars2.com/v2/professions/${firstUppercase(profession)}`)
.then((res) => setState({ error: undefined, skills: res.data.skills }))
fetch(`https://api.guildwars2.com/v2/professions/${firstUppercase(profession)}`)
.then((response) => response.json())
.then((res) => setState({ error: undefined, skills: res.skills }))
.catch((e) => {
console.error(e);
setState({ error: e.message });
Expand Down
7 changes: 3 additions & 4 deletions src/components/url-state/URLStateImport.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import React from 'react';
import { importFormState } from '../../state/async/formStateThunks';
import { useAppDispatch } from '../../state/redux-hooks';
Expand Down Expand Up @@ -63,10 +62,10 @@ const URLStateImport = ({ clearUrlOnSuccess }: URLStateImportProps) => {
// found shortened link, resolve the data.
// cf-function can be found in /functions/share/load.ts
const key = shortenerKey.slice(0, -2);
axios
.get(`share/load?${PARAMS.SHORTENER_KEY}=${key}`, { responseType: 'arraybuffer' })
fetch(`share/load?${PARAMS.SHORTENER_KEY}=${key}`)
.then((response) => response.arrayBuffer())
.then((response) => {
const binaryData = new Uint8Array(response.data);
const binaryData = new Uint8Array(response);
console.log(binaryData);

dispatch(importFormState({ binaryData, onSuccess: onLoadSuccess, onError: onLoadError }));
Expand Down
14 changes: 7 additions & 7 deletions src/state/async/formStateThunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import type { TFunction } from 'i18next';
import JsonUrl from 'json-url';
import pako from 'pako';
Expand Down Expand Up @@ -90,14 +89,15 @@ const getShortUrl = async (exportData: unknown) => {
const binaryData = pako.deflate(JSON.stringify(exportData));
console.timeEnd('Compressed binary data in:');

const response = await axios.post(`share/create`, binaryData).catch(console.error);
if (response?.data?.Status !== 200) {
console.log(
`URL shortener returned status ${response?.data?.Status}! Falling back to long URL.`,
);
const response = await fetch(`share/create`, { method: 'POST', body: binaryData })
.then((response) => response.json<{ Status: number; Message: string; Key: string | null }>())
.catch(console.error);

if (!response || response?.Status !== 200) {
console.log(`URL shortener returned status ${response?.Status}! Falling back to long URL.`);
throw new Error('failure');
}
const { Key } = response.data;
const { Key } = response;

const urlObject = new URL(window.location.href);
urlObject.searchParams.set(PARAMS.SHORTENER_KEY, `${Key}v1`);
Expand Down