Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
haishanh committed Sep 18, 2023
1 parent d978da1 commit 27a80fa
Show file tree
Hide file tree
Showing 52 changed files with 268 additions and 197 deletions.
10 changes: 8 additions & 2 deletions src/api/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ export function fetchData(apiConfig: ClashAPIConfig, listener: unknown): Unsubsc
const ws = new WebSocket(url);

let frozenState = false;
const onFrozen = () => { frozenState = true; ws.close(); },
onResume = () => { frozenState = false; fetchData(apiConfig, undefined); };
const onFrozen = () => {
frozenState = true;
ws.close();
},
onResume = () => {
frozenState = false;
fetchData(apiConfig, undefined);
};
document.addEventListener('freeze', onFrozen, { capture: true, once: true });
document.addEventListener('resume', onResume, { capture: true, once: true });

Expand Down
2 changes: 1 addition & 1 deletion src/api/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ function fetchLogsWithFetch(apiConfig: LogsAPIConfig, appendLog: AppendLogFn) {

// eslint-disable-next-line no-console
console.log('GET /logs error:', err.message);
}
},
);
}
6 changes: 3 additions & 3 deletions src/api/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function fetchProxies(config: ClashAPIConfig) {
export async function requestToSwitchProxy(
apiConfig: ClashAPIConfig,
groupName: string,
name: string
name: string,
) {
const body = { name };
const { url, init } = getURLAndInit(apiConfig);
Expand All @@ -41,7 +41,7 @@ export async function requestToSwitchProxy(
export async function requestDelayForProxy(
apiConfig: ClashAPIConfig,
name: string,
latencyTestUrl = 'http://www.gstatic.com/generate_204'
latencyTestUrl = 'http://www.gstatic.com/generate_204',
) {
const { url, init } = getURLAndInit(apiConfig);
const qs = `timeout=5000&url=${encodeURIComponent(latencyTestUrl)}`;
Expand Down Expand Up @@ -69,6 +69,6 @@ export async function healthcheckProviderByName(config: ClashAPIConfig, name: st
const options = { ...init, method: 'GET' };
return await fetch(
url + '/providers/proxies/' + encodeURIComponent(name) + '/healthcheck',
options
options,
);
}
2 changes: 1 addition & 1 deletion src/api/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type RuleAPIItem = {
function normalizeAPIResponse(json: { rules: Array<RuleAPIItem> }): Array<RuleItem> {
invariant(
json.rules && json.rules.length >= 0,
'there is no valid rules list in the rules API response'
'there is no valid rules list in the rules API response',
);

// attach an id
Expand Down
15 changes: 9 additions & 6 deletions src/api/traffic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const textDecoder = new TextDecoder('utf-8');

const Size = 150;

type Traffic = { up: number; down: number }
type Traffic = { up: number; down: number };

const traffic = {
labels: Array(Size).fill(0),
Expand Down Expand Up @@ -85,7 +85,10 @@ function fetchData(apiConfig: ClashAPIConfig) {
const ws = new WebSocket(url);

let frozenState = false;
const onFrozen = () => { frozenState = true; ws.close(); },
const onFrozen = () => {
frozenState = true;
ws.close();
},
onResume = () => {
frozenState = false;

Expand All @@ -99,10 +102,10 @@ function fetchData(apiConfig: ClashAPIConfig) {
document.addEventListener('freeze', onFrozen, { capture: true, once: true });
document.addEventListener('resume', onResume, { capture: true, once: true });

ws.addEventListener('error', function(_ev) {
ws.addEventListener('error', function (_ev) {
wsState = 3;
});
ws.addEventListener('close', function(_ev) {
ws.addEventListener('close', function (_ev) {
wsState = 3;
if (!frozenState) {
// For unexpected close, remove listeners and re-fetch
Expand All @@ -112,7 +115,7 @@ function fetchData(apiConfig: ClashAPIConfig) {
fetchDataWithFetch(apiConfig);
}
});
ws.addEventListener('message', function(event) {
ws.addEventListener('message', function (event) {
parseAndAppend(event.data);
});
return traffic;
Expand All @@ -135,7 +138,7 @@ function fetchDataWithFetch(apiConfig: ClashAPIConfig) {
// eslint-disable-next-line no-console
console.log('fetch /traffic error', err);
fetched = false;
}
},
);
return traffic;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type VersionData = {

export async function fetchVersion(
endpoint: string,
apiConfig: ClashAPIConfig
apiConfig: ClashAPIConfig,
): Promise<VersionData> {
let json = {};
try {
Expand Down
2 changes: 1 addition & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Modal.setAppElement(rootEl);
root.render(
<React.StrictMode>
<Root />
</React.StrictMode>
</React.StrictMode>,
);

setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/APIConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function APIConfig({ dispatch }: { dispatch: DispatchFn }) {

onConfirm();
},
[onConfirm]
[onConfirm],
);

const detectApiServer = async () => {
Expand Down
12 changes: 8 additions & 4 deletions src/components/APIDiscovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import { connect } from './StateProvider';

const { useCallback, useEffect } = React;

function APIDiscovery({ dispatch, apiConfig, modals }: {
dispatch: DispatchFn,
apiConfig: ClashAPIConfig,
modals: StateModals,
function APIDiscovery({
dispatch,
apiConfig,
modals,
}: {
dispatch: DispatchFn;
apiConfig: ClashAPIConfig;
modals: StateModals;
}) {
if (!window.fetch) {
const { detail } = errors[DOES_NOT_SUPPORT_FETCH];
Expand Down
4 changes: 2 additions & 2 deletions src/components/BackendList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function BackendListImpl({
(conf: ClashAPIConfig) => {
removeClashAPIConfig(conf);
},
[removeClashAPIConfig]
[removeClashAPIConfig],
);
const onSelect = React.useCallback(
(conf: ClashAPIConfig) => {
selectClashAPIConfig(conf);
},
[selectClashAPIConfig]
[selectClashAPIConfig],
);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ function Button(props: ButtonProps, ref: React.Ref<HTMLButtonElement>) {
if (isLoading) return;
onClick && onClick(e);
},
[isLoading, onClick]
[isLoading, onClick],
);
const btnClassName = cx(
s0.btn,
{ [s0.minimal]: kind === 'minimal', [s0.circular]: kind === 'circular' },
className
className,
);
return (
<button
Expand Down
2 changes: 1 addition & 1 deletion src/components/CollapsibleSectionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Header({ name, type, toggle, isOpen, qty }: Props) {
toggle();
}
},
[toggle]
[toggle],
);
return (
<div
Expand Down
24 changes: 14 additions & 10 deletions src/components/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ const mapState2 = (s: State) => ({
const Config = connect(mapState2)(ConfigImpl);
export default connect(mapState)(ConfigContainer);

function ConfigContainer({ dispatch, configs, apiConfig }: {
dispatch: DispatchFn,
configs: ClashGeneralConfig,
apiConfig: ClashAPIConfig,
function ConfigContainer({
dispatch,
configs,
apiConfig,
}: {
dispatch: DispatchFn;
configs: ClashGeneralConfig;
apiConfig: ClashAPIConfig;
}) {
useEffect(() => {
dispatch(fetchConfigs(apiConfig));
Expand Down Expand Up @@ -106,7 +110,7 @@ function ConfigImpl({
(name: keyof ClashGeneralConfig, val: ClashGeneralConfig[keyof ClashGeneralConfig]) => {
setConfigStateInternal({ ...configState, [name]: val });
},
[configState]
[configState],
);

const handleSwitchOnChange = useCallback(
Expand All @@ -116,7 +120,7 @@ function ConfigImpl({
setConfigState(name, value);
dispatch(updateConfigs(apiConfig, { 'allow-lan': value }));
},
[apiConfig, dispatch, setConfigState]
[apiConfig, dispatch, setConfigState],
);

const handleChangeValue = useCallback(
Expand Down Expand Up @@ -144,12 +148,12 @@ function ConfigImpl({
return;
}
},
[apiConfig, dispatch, setConfigState]
[apiConfig, dispatch, setConfigState],
);

const handleInputOnChange = useCallback<React.ChangeEventHandler<HTMLInputElement>>(
(e) => handleChangeValue(e.target),
[handleChangeValue]
[handleChangeValue],
);

const { selectChartStyleIndex, updateAppConfig } = useStoreActions();
Expand All @@ -176,7 +180,7 @@ function ConfigImpl({
throw new Error(`unknown input name ${name}`);
}
},
[apiConfig, dispatch, updateAppConfig]
[apiConfig, dispatch, updateAppConfig],
);

const mode = useMemo(() => {
Expand All @@ -201,7 +205,7 @@ function ConfigImpl({
onBlur={handleInputOnBlur}
/>
</div>
) : null
) : null,
)}

<div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ConnectionTable.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
white-space: nowrap;
}
td {
border:none;
border: none;
white-space: nowrap;
padding: 8px 13px;
font-size: 0.9em;
font-family: var(--font-normal);
}
& >tbody>tr:nth-of-type(odd)>* {
& > tbody > tr:nth-of-type(odd) > * {
background: var(--color-row-odd);
}
}
Expand Down
Loading

0 comments on commit 27a80fa

Please sign in to comment.