Skip to content

Commit 2d21114

Browse files
committed
feat: show KeyConfiguration if serverSide not config openai key.
1 parent 7bde534 commit 2d21114

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

chatfiles-ui/components/Sidebar/KeySettings.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import { KeyConfiguration, ModelType } from '@/types';
2626
interface Props {
2727
keyConfiguration: KeyConfiguration;
2828
onKeyConfigrationChange: (keySettings: KeyConfiguration) => void;
29+
keyConfigurationButtonRef: React.RefObject<HTMLButtonElement>;
2930
}
3031

3132
export const KeySettings: FC<Props> = ({
3233
keyConfiguration,
3334
onKeyConfigrationChange,
35+
keyConfigurationButtonRef,
3436
}) => {
3537
const [fromkeyConfigration, setFromKeyConfigration] = useState<KeyConfiguration>({
3638
apiType: keyConfiguration.apiType,
@@ -65,7 +67,7 @@ export const KeySettings: FC<Props> = ({
6567
<>
6668
<Sheet>
6769
<SheetTrigger asChild>
68-
<Button className="w-64 dark:border-gray-50" variant="outline">OpenAI API Key Settings</Button>
70+
<Button ref={keyConfigurationButtonRef} className="w-64 dark:border-gray-50" variant="outline">OpenAI API Key Settings</Button>
6971
</SheetTrigger>
7072
<SheetContent position="left" size="sm">
7173
<SheetHeader>

chatfiles-ui/components/Sidebar/Sidebar.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface Props {
3838
}) => void;
3939
keyConfiguration: KeyConfiguration;
4040
onKeyConfigrationChange: (keySettings: KeyConfiguration) => void;
41+
keyConfigurationButtonRef: React.RefObject<HTMLButtonElement>;
4142
}
4243

4344
export const Sidebar: FC<Props> = ({
@@ -59,7 +60,8 @@ export const Sidebar: FC<Props> = ({
5960
onExportConversations,
6061
onImportConversations,
6162
keyConfiguration,
62-
onKeyConfigrationChange
63+
onKeyConfigrationChange,
64+
keyConfigurationButtonRef,
6365
}) => {
6466
const { t } = useTranslation('sidebar');
6567
const [searchTerm, setSearchTerm] = useState<string>('');
@@ -207,6 +209,7 @@ export const Sidebar: FC<Props> = ({
207209
onImportConversations={onImportConversations}
208210
keyConfiguration={keyConfiguration}
209211
onKeyConfigrationChange={onKeyConfigrationChange}
212+
keyConfigurationButtonRef={keyConfigurationButtonRef}
210213
/>
211214
</aside>
212215
);

chatfiles-ui/components/Sidebar/SidebarSettings.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface Props {
1818
}) => void;
1919
keyConfiguration: KeyConfiguration;
2020
onKeyConfigrationChange: (keySettings: KeyConfiguration) => void;
21+
keyConfigurationButtonRef: React.RefObject<HTMLButtonElement>;
2122
}
2223

2324
export const SidebarSettings: FC<Props> = ({
@@ -28,6 +29,7 @@ export const SidebarSettings: FC<Props> = ({
2829
onImportConversations,
2930
keyConfiguration,
3031
onKeyConfigrationChange,
32+
keyConfigurationButtonRef,
3133
}) => {
3234
const { t } = useTranslation('sidebar');
3335

@@ -52,7 +54,7 @@ export const SidebarSettings: FC<Props> = ({
5254
onToggleLightMode(lightMode === 'light' ? 'dark' : 'light')
5355
}
5456
/>
55-
<KeySettings keyConfiguration={keyConfiguration} onKeyConfigrationChange={onKeyConfigrationChange}/>
57+
<KeySettings keyConfiguration={keyConfiguration} onKeyConfigrationChange={onKeyConfigrationChange} keyConfigurationButtonRef={keyConfigurationButtonRef}/>
5658
</div>
5759
);
5860
};

chatfiles-ui/pages/index.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ const Home: React.FC<HomeProps> = ({ serverSideApiKeyIsSet }) => {
6060
azureDeploymentName: '',
6161
azureEmbeddingDeploymentName: '',
6262
});
63-
6463
const stopConversationRef = useRef<boolean>(false);
6564

65+
const keyConfigurationButtonRef = useRef<HTMLButtonElement>(null);
66+
const handlekeyConfigurationButtonClick = () => {
67+
if (keyConfigurationButtonRef.current) {
68+
keyConfigurationButtonRef.current.click();
69+
}
70+
};
71+
6672
const handleSend = async (message: Message, deleteCount = 0) => {
6773
if (selectedConversation) {
6874
let updatedConversation: Conversation;
@@ -510,6 +516,12 @@ const Home: React.FC<HomeProps> = ({ serverSideApiKeyIsSet }) => {
510516
}
511517
}, [selectedConversation]);
512518

519+
useEffect(() => {
520+
if (!serverSideApiKeyIsSet) {
521+
handlekeyConfigurationButtonClick();
522+
}
523+
});
524+
513525
useEffect(() => {
514526
const theme = localStorage.getItem('theme');
515527
if (theme) {
@@ -583,10 +595,6 @@ const Home: React.FC<HomeProps> = ({ serverSideApiKeyIsSet }) => {
583595
/>
584596
</div>
585597

586-
{/* (!serverSideApiKeyIsSet) ? (
587-
<KeySettings keyConfiguration={keyConfiguration} onKeyConfigrationChange={handleKeyConfigrationChange} />
588-
) */}
589-
590598
<div className="flex h-full w-full pt-[48px] sm:pt-0">
591599
{showSidebar ? (
592600
<div>
@@ -610,6 +618,7 @@ const Home: React.FC<HomeProps> = ({ serverSideApiKeyIsSet }) => {
610618
onImportConversations={handleImportConversations}
611619
keyConfiguration={keyConfiguration}
612620
onKeyConfigrationChange={handleKeyConfigrationChange}
621+
keyConfigurationButtonRef={keyConfigurationButtonRef}
613622
/>
614623

615624
<div

0 commit comments

Comments
 (0)