From 87a286ef072c01872e2ef2f2618ce39585f5fa8e Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Sat, 20 Jul 2024 14:36:47 +0800 Subject: [PATCH] refactor setting page --- app/components/settings.tsx | 781 +++++++++++++++++------------------- 1 file changed, 372 insertions(+), 409 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 00306b393af..ad63b2b906b 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -657,6 +657,368 @@ export function Settings() { const clientConfig = useMemo(() => getClientConfig(), []); const showAccessCode = enabledAccessControl && !clientConfig?.isApp; + const accessCodeComponent = showAccessCode && ( + + { + accessStore.update( + (access) => (access.accessCode = e.currentTarget.value), + ); + }} + /> + + ); + + const useCustomConfigComponent = // Conditionally render the following ListItem based on clientConfig.isApp + !clientConfig?.isApp && ( // only show if isApp is false + + + accessStore.update( + (access) => (access.useCustomConfig = e.currentTarget.checked), + ) + } + > + + ); + + const openAIConfigComponent = accessStore.provider === + ServiceProvider.OpenAI && ( + <> + + + accessStore.update( + (access) => (access.openaiUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.openaiApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const azureConfigComponent = accessStore.provider === + ServiceProvider.Azure && ( + <> + + + accessStore.update( + (access) => (access.azureUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.azureApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.azureApiVersion = e.currentTarget.value), + ) + } + > + + + ); + + const googleConfigComponent = accessStore.provider === + ServiceProvider.Google && ( + <> + + + accessStore.update( + (access) => (access.googleUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.googleApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.googleApiVersion = e.currentTarget.value), + ) + } + > + + + ); + + const anthropicConfigComponent = accessStore.provider === + ServiceProvider.Anthropic && ( + <> + + + accessStore.update( + (access) => (access.anthropicUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.anthropicApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.anthropicApiVersion = e.currentTarget.value), + ) + } + > + + + ); + + const baiduConfigComponent = accessStore.provider === + ServiceProvider.Baidu && ( + <> + + + accessStore.update( + (access) => (access.baiduUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.baiduApiKey = e.currentTarget.value), + ); + }} + /> + + + { + accessStore.update( + (access) => (access.baiduSecretKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const byteDanceConfigComponent = accessStore.provider === + ServiceProvider.ByteDance && ( + <> + + + accessStore.update( + (access) => (access.bytedanceUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.bytedanceApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const alibabaConfigComponent = accessStore.provider === + ServiceProvider.Alibaba && ( + <> + + + accessStore.update( + (access) => (access.alibabaUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.alibabaApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + return (
@@ -903,46 +1265,12 @@ export function Settings() { - {showAccessCode && ( - - { - accessStore.update( - (access) => (access.accessCode = e.currentTarget.value), - ); - }} - /> - - )} + {accessCodeComponent} {!accessStore.hideUserApiKey && ( <> - { - // Conditionally render the following ListItem based on clientConfig.isApp - !clientConfig?.isApp && ( // only show if isApp is false - - - accessStore.update( - (access) => - (access.useCustomConfig = e.currentTarget.checked), - ) - } - > - - ) - } + {useCustomConfigComponent} + {accessStore.useCustomConfig && ( <> - {accessStore.provider === ServiceProvider.OpenAI && ( - <> - - - accessStore.update( - (access) => - (access.openaiUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.openaiApiKey = e.currentTarget.value), - ); - }} - /> - - - )} - {accessStore.provider === ServiceProvider.Azure && ( - <> - - - accessStore.update( - (access) => - (access.azureUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.azureApiKey = e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.azureApiVersion = - e.currentTarget.value), - ) - } - > - - - )} - {accessStore.provider === ServiceProvider.Google && ( - <> - - - accessStore.update( - (access) => - (access.googleUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.googleApiKey = e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.googleApiVersion = - e.currentTarget.value), - ) - } - > - - - )} - {accessStore.provider === ServiceProvider.Anthropic && ( - <> - - - accessStore.update( - (access) => - (access.anthropicUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.anthropicApiKey = - e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.anthropicApiVersion = - e.currentTarget.value), - ) - } - > - - - )} - {accessStore.provider === ServiceProvider.Baidu && ( - <> - - - accessStore.update( - (access) => - (access.baiduUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.baiduApiKey = e.currentTarget.value), - ); - }} - /> - - - { - accessStore.update( - (access) => - (access.baiduSecretKey = e.currentTarget.value), - ); - }} - /> - - - )} - - {accessStore.provider === ServiceProvider.ByteDance && ( - <> - - - accessStore.update( - (access) => - (access.bytedanceUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.bytedanceApiKey = - e.currentTarget.value), - ); - }} - /> - - - )} - - {accessStore.provider === ServiceProvider.Alibaba && ( - <> - - - accessStore.update( - (access) => - (access.alibabaUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.alibabaApiKey = e.currentTarget.value), - ); - }} - /> - - - )} + {openAIConfigComponent} + {azureConfigComponent} + {googleConfigComponent} + {anthropicConfigComponent} + {baiduConfigComponent} + {byteDanceConfigComponent} + {alibabaConfigComponent} )}