mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-12 12:34:24 +01:00
🔧 refactor: Reduce Complexity of Initial Load Effect & Message Styling (#3213)
* move shared conditions and early bail to reduce cognitive complexity, improve readability * refactor: make condition as close to the original as possible * chore: adjust comment in chat route * style: fix original styling of non-multi messages * refactor: separate messagerender logic from 'Message' --------- Co-authored-by: RehaS <beratson@gmail.com>
This commit is contained in:
parent
791b0139bc
commit
ed5ee1f86f
4 changed files with 179 additions and 181 deletions
|
|
@ -38,14 +38,14 @@ export default function ChatRoute() {
|
|||
const assistantListMap = useAssistantListMap();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
startupConfig &&
|
||||
conversationId === 'new' &&
|
||||
endpointsQuery.data &&
|
||||
modelsQuery.data &&
|
||||
!modelsQuery.data?.initial &&
|
||||
!hasSetConversation.current
|
||||
) {
|
||||
const shouldSetConvo =
|
||||
startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial;
|
||||
/* Early exit if startupConfig is not loaded and conversation is already set and only initial models have loaded */
|
||||
if (!shouldSetConvo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (conversationId === 'new' && endpointsQuery.data && modelsQuery.data) {
|
||||
const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
|
||||
|
||||
newConversation({
|
||||
|
|
@ -63,14 +63,7 @@ export default function ChatRoute() {
|
|||
});
|
||||
|
||||
hasSetConversation.current = true;
|
||||
} else if (
|
||||
startupConfig &&
|
||||
initialConvoQuery.data &&
|
||||
endpointsQuery.data &&
|
||||
modelsQuery.data &&
|
||||
!modelsQuery.data?.initial &&
|
||||
!hasSetConversation.current
|
||||
) {
|
||||
} else if (initialConvoQuery.data && endpointsQuery.data && modelsQuery.data) {
|
||||
newConversation({
|
||||
template: initialConvoQuery.data,
|
||||
/* this is necessary to load all existing settings */
|
||||
|
|
@ -80,9 +73,6 @@ export default function ChatRoute() {
|
|||
});
|
||||
hasSetConversation.current = true;
|
||||
} else if (
|
||||
startupConfig &&
|
||||
!hasSetConversation.current &&
|
||||
!modelsQuery.data?.initial &&
|
||||
conversationId === 'new' &&
|
||||
assistantListMap[EModelEndpoint.assistants] &&
|
||||
assistantListMap[EModelEndpoint.azureAssistants]
|
||||
|
|
@ -103,9 +93,6 @@ export default function ChatRoute() {
|
|||
});
|
||||
hasSetConversation.current = true;
|
||||
} else if (
|
||||
startupConfig &&
|
||||
!hasSetConversation.current &&
|
||||
!modelsQuery.data?.initial &&
|
||||
assistantListMap[EModelEndpoint.assistants] &&
|
||||
assistantListMap[EModelEndpoint.azureAssistants]
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue