Skip to content

Commit

Permalink
Fix request client variable (#707)
Browse files Browse the repository at this point in the history
* fix: request client variable

* fix: request client variable

* fix: request client variable

* fix: request client variable
  • Loading branch information
1pone authored Jul 23, 2024
1 parent 071fd18 commit ac171a3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/arex-request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arextest/arex-request",
"version": "0.3.10",
"version": "0.3.14",
"type": "module",
"main": "dist/arex-request.js",
"module": "dist/arex-request.js",
Expand Down
33 changes: 2 additions & 31 deletions packages/arex-request/src/components/Request/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Button, Checkbox, Select } from 'antd';
import React, { FC, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { isClient } from '../../constant';
import { sendRequest } from '../../helpers';
import { useArexRequestProps, useArexRequestStore } from '../../hooks';
import { ArexEnvironment, ArexRESTRequest, ArexRESTResponse } from '../../types';
Expand Down Expand Up @@ -38,7 +37,7 @@ export type RequestProps = {
const Request: FC<RequestProps> = () => {
const { onBeforeRequest = (request: ArexRESTRequest) => request, onRequest } =
useArexRequestProps();
const { store, dispatch } = useArexRequestStore();
const { store, dispatch, request } = useArexRequestStore();
const { t } = useTranslation();
const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout>();

Expand All @@ -57,35 +56,7 @@ const Request: FC<RequestProps> = () => {
return;
}

const ready = isClient || window.__AREX_EXTENSION_INSTALLED__;
dispatch((state) => {
state.response = {
type: ready ? 'loading' : 'EXTENSION_NOT_INSTALLED',
headers: undefined,
};
});

if (!ready) return;

sendRequest(onBeforeRequest(store.request), store.environment)
.then((res) => {
onRequest?.(null, { request: store.request, environment: store.environment }, res);
dispatch((state) => {
state.response = res.response;
state.consoles = res.consoles;
state.visualizer = res.visualizer;
state.testResult = res.testResult;
});
})
.catch((err) => {
onRequest?.(err, { request: store.request, environment: store.environment }, null);
dispatch((state) => {
state.response = {
type: err.code,
error: err,
};
});
});
request();
};

return (
Expand Down
6 changes: 3 additions & 3 deletions packages/arex-request/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const AREX_EXTENSION_CHROME_STORE_UEL =
'https://chromewebstore.google.com/detail/arex-chrome-extension/jmmficadjneeekafmnheppeoehlgjdjj';

// electron client
export const isClient = import.meta.env.MODE === 'electron';
export const isClientDev = isClient && import.meta.env.DEV;
export const isClientProd = isClient && import.meta.env.PROD;
export const isClient = () => !!window.electron;
export const isClientDev = isClient() && import.meta.env.DEV;
export const isClientProd = isClient() && import.meta.env.PROD;
5 changes: 3 additions & 2 deletions packages/arex-request/src/providers/RequestStoreProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ const RequestStoreProvider: FC<PropsWithChildren> = (props) => {
}, [environmentProps]);

const request = async (): Promise<ArexResponse | void> => {
const ready = isClient() || window.__AREX_EXTENSION_INSTALLED__;

dispatch((state) => {
state.response = {
type: window.__AREX_EXTENSION_INSTALLED__ ? 'loading' : 'EXTENSION_NOT_INSTALLED',
type: ready ? 'loading' : 'EXTENSION_NOT_INSTALLED',
headers: undefined,
};
});
const ready = isClient || window.__AREX_EXTENSION_INSTALLED__;

if (!ready) return;

Expand Down
1 change: 1 addition & 0 deletions packages/arex-request/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ declare global {
message: MessageInstance;
__AREX_EXTENSION_INSTALLED__: boolean; // 是否安装了arex-chrome-extension
__AREX_EXTENSION_VERSION__: string; // arex-chrome-extension 最新版本号
electron?: any;
}
}

0 comments on commit ac171a3

Please sign in to comment.