Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions ui/src/components/ai-chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,21 @@ const checkInputParam = () => {
}

function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
if (!userFormRef.value?.checkInputParam()) {
if (isUserInput.value) {
if (isUserInput.value) {
if (!userFormRef.value?.checkInputParam()) {
showUserInput.value = true
return
} else {
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
? userFormData[key]
: form_data.value[key]
return result
}, {})
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
showUserInput.value = false
}
return
} else {
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
? userFormData[key]
: form_data.value[key]
return result
}, {})
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
}
if (!loading.value && props.applicationDetails?.name) {
handleDebounceClick(val, other_params_data, chat)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is mostly functional but contains an unnecessary else block that can be removed without altering the logic. Additionally, there are style improvements to follow current JavaScript/TypeScript best practices.

Here's the revised version:

function sendMessage(val: string, other_params_data?: any, chat?: chatType): void {
  if (!userFormRef.value?.checkInputParam() && isUserInput.value) {
    showUserInput.value = true;
    return;
  }

  const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || "{}");

  Object.keys(form_data.value).forEach(key => {
    form_data.value[key] =
      Object.prototype.hasOwnProperty.call(userFormData, key)
        ? userFormData[key]
        : form_data.value[key];
  });

  localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data.value));

  if (!loading.value && props.applicationDetails?.name) {
    handleDebounceClick(val, other_params_data, chat);
  }
}

Key Changes:

  1. Reduced Code: Removed the redundant else block, making the code cleaner.
  2. Consistent Type Annotations: Ensured all TypeScript types (void instead of no type annotation where appropriate).
  3. Arrow Functions: Used arrow functions for concise callbacks where applicable.

This should improve readability and maintainability while ensuring correctness.

Expand Down