Skip to content

Commit

Permalink
fix: fix subdmain bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonTao committed Jun 11, 2024
1 parent 5cd0be9 commit e2680e3
Show file tree
Hide file tree
Showing 5 changed files with 577 additions and 521 deletions.
2 changes: 1 addition & 1 deletion components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
ref={chatContainerRef}
onScroll={handleScroll}
>
<div className="sticky z-10 top-0 flex w-full items-center justify-end gap-3 h-[84px] bg-white border-b border-[rgba(0,0,0,0.15)] pr-5">
<div className="sticky z-10 top-0 flex w-full items-center justify-end gap-3 h-[84px] bg-white border-b border-[rgba(0,0,0,0.15)] pl-4 md:pl-0 pr-4 md:pr-5">
{/* <div className="inline-flex items-center justify-center rounded-lg px-3 h-[44px] text-[13px] bg-white text-black border border-[rgba(0, 0, 0, 0.08)] cursor-pointer hover:border-black transition-all">
<p>{selectedConversation?.model?.id || defaultModelId}</p>
</div> */}
Expand Down
25 changes: 3 additions & 22 deletions components/Chat/SystemNodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import React, {
useState,
} from 'react';

import { useRouter } from 'next/router';

import { dappHosts } from '@/hooks/useHost';

import HomeContext from '@/pages/api/home/home.context';
Expand All @@ -18,10 +16,9 @@ const SystemNodes: React.FC = () => {
const [tippyInstance, setTippyInstance] = useState<any>(null);
const [nodes, setNodes] = useState<any[]>([]);
const [searchWords, setSearchWords] = useState('');
const { query } = useRouter();

const {
state: { api, selectedConversation, defaultModelId },
state: { api, selectedConversation, modelError },
dispatch: homeDispatch,
} = useContext(HomeContext);

Expand Down Expand Up @@ -66,22 +63,6 @@ const SystemNodes: React.FC = () => {
fetchNodes();
}, [channelIsDapp]);

useEffect(() => {
if (typeof window === 'undefined' || !channelIsDapp) return;
if (query?.subdomain) {
handleApiChange(`https://${query?.subdomain}`);
} else {
if (api === '' || api === '..') {
const host = window.location.host;
if (host === 'gaianet.ai' || host === 'www.gaianet.ai') {
handleApiChange(`https://knowledge.gaianet.network`);
} else {
handleApiChange(`https://knowledge.gaianet.xyz`);
}
}
}
}, [api, channelIsDapp, handleApiChange, query?.subdomain]);

const handleSearch = (e: any) => {
setSearchWords(e.target.value || '');
};
Expand Down Expand Up @@ -173,13 +154,13 @@ const SystemNodes: React.FC = () => {
onCreate={(instance) => setTippyInstance(instance)}
className="gaianet-tippy"
>
<div className="inline-flex items-center justify-between rounded-lg gap-3 px-3 w-[405px] h-[44px] text-[13px] bg-white text-black border border-[rgba(0, 0, 0, 0.08)] cursor-pointer hover:border-black transition-all">
<div className="inline-flex items-center justify-between rounded-lg gap-3 px-3 w-auto md:min-w-[405px] h-[44px] text-[13px] bg-white text-black border border-[rgba(0, 0, 0, 0.08)] cursor-pointer hover:border-black transition-all">
<div className="flex flex-col">
<p className="text-[13px] leading-[16px] ">
{selectedModelSubdomin || '-'}
</p>
<p className="text-[10px] leading-[13px] uppercase mt-[2px] text-[#888888]">
{selectedConversation?.model?.id || defaultModelId}
{modelError ? '-' : selectedConversation?.model?.id}
</p>
</div>
<IconChevronDown size="18" color="#C0C0C0" />
Expand Down
130 changes: 66 additions & 64 deletions components/Settings/QueryUrl.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
import {IconCheck, IconLink, IconX} from '@tabler/icons-react';
import {FC, KeyboardEvent, useEffect, useRef, useState} from 'react';
import { IconCheck, IconLink, IconX } from '@tabler/icons-react';
import { FC, KeyboardEvent, useEffect, useRef, useState } from 'react';

import {useTranslation} from 'next-i18next';
import { useTranslation } from 'next-i18next';

import {SidebarButton} from '../Sidebar/SidebarButton';
import { SidebarButton } from '../Sidebar/SidebarButton';

interface Props {
api: string;
onApiChange: (apiKey: string) => void;
api: string;
onApiChange: (apiKey: string) => void;
}

export const QueryUrl: FC<Props> = ({api, onApiChange}) => {
const {t} = useTranslation('sidebar');
const [isChanging, setIsChanging] = useState(false);
const [newKey, setNewKey] = useState(api);
const inputRef = useRef<HTMLInputElement>(null);
export const QueryUrl: FC<Props> = ({ api, onApiChange }) => {
const { t } = useTranslation('sidebar');
const [isChanging, setIsChanging] = useState(false);
// const [newKey, setNewKey] = useState(api);
const inputRef = useRef<HTMLInputElement>(null);

const handleEnterDown = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter') {
e.preventDefault();
handleUpdateKey(newKey);
}
};
const handleEnterDown = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter') {
e.preventDefault();
if (inputRef.current?.value)
handleUpdateKey(inputRef.current?.value?.trim());
}
};

const handleUpdateKey = (newKey: string) => {
onApiChange(newKey.trim());
setIsChanging(false);
};
const handleUpdateKey = (newKey: string) => {
onApiChange(newKey.trim());
setIsChanging(false);
};

useEffect(() => {
if (isChanging) {
inputRef.current?.focus();
}
}, [isChanging]);
useEffect(() => {
if (isChanging) {
inputRef.current?.focus();
}
}, [isChanging]);

return isChanging ? (
<div
className="duration:200 flex w-full cursor-pointer items-center rounded-md py-[11px] px-4 transition-colors hover:bg-gray-500/10">
<IconLink size={18} color="#322221" />
return isChanging ? (
<div className="duration:200 flex w-full cursor-pointer items-center rounded-md py-[11px] px-4 transition-colors hover:bg-gray-500/10">
<IconLink size={18} color="#322221" />

<input
ref={inputRef}
className="ml-2 h-[20px] flex-1 overflow-hidden overflow-ellipsis border-b border-neutral-400 bg-transparent pr-1 text-[12.5px] leading-3 text-left text-[#322221] outline-none focus:border-neutral-100"
value={newKey}
onChange={(e) => setNewKey(e.target.value)}
onKeyDown={handleEnterDown}
placeholder={t('API Url') || 'API Url'}
/>
<input
ref={inputRef}
className="ml-2 h-[20px] flex-1 overflow-hidden overflow-ellipsis border-b border-neutral-400 bg-transparent pr-1 text-[12.5px] leading-3 text-left text-[#322221] outline-none focus:border-neutral-100"
// value={newKey}
defaultValue={api}
// onChange={(e) => setNewKey(e.target.value)}
onKeyDown={handleEnterDown}
placeholder={t('API Url') || 'API Url'}
/>

<div className="flex w-[40px]">
<IconCheck
className="ml-auto min-w-[20px] text-neutral-400 hover:text-[#322221]"
size={18}
onClick={(e) => {
e.stopPropagation();
handleUpdateKey(newKey);
}}
/>
<div className="flex w-[40px]">
<IconCheck
className="ml-auto min-w-[20px] text-neutral-400 hover:text-[#322221]"
size={18}
onClick={(e) => {
e.stopPropagation();
if (inputRef.current?.value)
handleUpdateKey(inputRef.current?.value?.trim());
}}
/>

<IconX
className="ml-auto min-w-[20px] text-neutral-400 hover:text-[#322221]"
size={18}
onClick={(e) => {
e.stopPropagation();
setIsChanging(false);
setNewKey(api);
}}
/>
</div>
</div>
) : (
<SidebarButton
text={t('Chat API Url')}
icon={<IconLink size={18}/>}
onClick={() => setIsChanging(true)}
<IconX
className="ml-auto min-w-[20px] text-neutral-400 hover:text-[#322221]"
size={18}
onClick={(e) => {
e.stopPropagation();
setIsChanging(false);
// setNewKey(api);
}}
/>
);
</div>
</div>
) : (
<SidebarButton
text={t('Chat API Url')}
icon={<IconLink size={18} />}
onClick={() => setIsChanging(true)}
/>
);
};
6 changes: 6 additions & 0 deletions hooks/useHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ export const dappHosts = [
apiUrl: 'https://api.gaianet-test.link/',
},
];

export const useChannelIsPortal = () => {
if (typeof window === 'undefined') return false;
const host = window.location.host;
if (dappHosts.find((item) => item?.host === host)) return true;
};
Loading

0 comments on commit e2680e3

Please sign in to comment.