diff --git a/src/components/Header.tsx b/src/components/Header.tsx index fe6dcbb..7bfe0d4 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -13,23 +13,11 @@ import { IconRuler, IconSettings, } from '@tabler/icons-solidjs' -import { - For, - ParentComponent, - Show, - createEffect, - createMemo, - createSignal, -} from 'solid-js' +import { For, ParentComponent, Show, createMemo, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { LANG, ROUTE } from '~/config/enum' import { themes } from '~/constants' -import { - endpoint, - selectedEndpoint, - setCurTheme, - setSelectedEndpoint, -} from '~/signals' +import { setCurTheme, setSelectedEndpoint } from '~/signals' import { useProxies } from '~/signals/proxies' const Nav: ParentComponent<{ href: string; tooltip: string }> = ({ @@ -80,14 +68,6 @@ const ThemeSwitcher = () => ( export const Header = () => { const [t, { locale }] = useI18n() const { proxyProviders } = useProxies() - - createEffect(() => { - // Need fix: useRequest is not reactive so we need to useProxies again or request wont have endpoint - if (selectedEndpoint() && endpoint()) { - useProxies().updateProxy() - } - }) - const navs = createMemo(() => { const list = [ { diff --git a/src/signals/index.ts b/src/signals/index.ts index 64e2987..f9db34e 100644 --- a/src/signals/index.ts +++ b/src/signals/index.ts @@ -3,6 +3,17 @@ import ky from 'ky' import { createSignal } from 'solid-js' import { themes } from '~/constants' +export const useRequest = () => { + const e = endpoint() + + return ky.create({ + prefixUrl: e?.url, + headers: { + Authorization: e?.secret ? `Bearer ${e.secret}` : '', + }, + }) +} + export const [selectedEndpoint, setSelectedEndpoint] = makePersisted( createSignal(''), { @@ -33,14 +44,3 @@ export const endpoint = () => export const secret = () => endpoint()?.secret export const wsEndpointURL = () => endpoint()?.url.replace('http', 'ws') - -export const useRequest = () => { - const e = endpoint() - - return ky.create({ - prefixUrl: e?.url, - headers: { - Authorization: e?.secret ? `Bearer ${e.secret}` : '', - }, - }) -} diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index d67d053..b0baaa6 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -1,5 +1,5 @@ -import { createSignal } from 'solid-js' -import { useRequest } from '~/signals' +import { createEffect, createSignal } from 'solid-js' +import { endpoint, selectedEndpoint, useRequest } from '~/signals' import { autoCloseConns, urlForDelayTest } from '~/signals/config' import type { Proxy, ProxyNode, ProxyProvider } from '~/types' @@ -140,3 +140,9 @@ export function useProxies() { healthCheckByProviderName, } } + +createEffect(() => { + if (selectedEndpoint() && endpoint()) { + useProxies().updateProxy() + } +})