Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Open
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
13 changes: 12 additions & 1 deletion src/hooks/useWs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import {
TSocketResponse,
TSocketResponseData,
} from '@site/src/configs/websocket/types';
import { getIsBrowser } from '@site/src/utils';
import { useCallback, useState } from 'react';

const useWS = <T extends TSocketEndpointNames>(name?: T) => {
const [is_loading, setIsLoading] = useState(false);
const [error, setError] = useState<unknown>();
const [data, setData] = useState<TSocketResponseData<T>>();
const [full_response, setFullResponse] = useState<TSocketResponse<T>>();
let hash;

const isBrowser = getIsBrowser();
if (isBrowser) {
hash = window.location.hash;
}

const clear = useCallback(() => {
setError(null);
Expand All @@ -24,7 +31,11 @@ const useWS = <T extends TSocketEndpointNames>(name?: T) => {

if (name) {
if (payload === undefined || name == 'api_token' || name == 'app_register') {
payload = { [name]: 1, ...payload };
if (hash === '#api_token' || hash === '#app_register') {
payload = { ...payload };
} else {
payload = { [name]: 1, ...payload };
}
}
} else {
payload = { ...payload };
Expand Down