Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): remove brain choice when search page displays #2044

Merged
merged 1 commit into from
Jan 21, 2024
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
100 changes: 54 additions & 46 deletions frontend/lib/components/ui/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
import { ChangeEvent } from 'react';
import { ChangeEvent, useEffect } from "react";
import { LuSearch } from "react-icons/lu";

import { useChatInput } from '@/app/chat/[chatId]/components/ActionsBar/components/ChatInput/hooks/useChatInput';
import { useChat } from '@/app/chat/[chatId]/hooks/useChat';
import { useChatContext } from '@/lib/context';
import { useChatInput } from "@/app/chat/[chatId]/components/ActionsBar/components/ChatInput/hooks/useChatInput";
import { useChat } from "@/app/chat/[chatId]/hooks/useChat";
import { useChatContext } from "@/lib/context";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";

import styles from './SearchBar.module.scss';
import styles from "./SearchBar.module.scss";

export const SearchBar = (): JSX.Element => {
const { message, setMessage } = useChatInput()
const { setMessages } = useChatContext()
const { addQuestion } = useChat()

const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
setMessage(event.target.value);
};

const handleEnter = async (event: React.KeyboardEvent<HTMLInputElement>): Promise<void> => {
if (event.key === 'Enter') {
await submit()
}
};

const submit = async (): Promise<void> => {
setMessages([]);
try {
await addQuestion(message);
} catch (error) {
console.error(error);
}
const { message, setMessage } = useChatInput();
const { setMessages } = useChatContext();
const { addQuestion } = useChat();
const { setCurrentBrainId } = useBrainContext();

useEffect(() => {
setCurrentBrainId(null);
});

const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
setMessage(event.target.value);
};

const handleEnter = async (
event: React.KeyboardEvent<HTMLInputElement>
): Promise<void> => {
if (event.key === "Enter") {
await submit();
}

/* eslint-disable @typescript-eslint/restrict-template-expressions */

return (
<div className={styles.search_bar_wrapper}>
<input
className={styles.search_input}
type="text"
placeholder="Search"
value={message}
onChange={handleChange}
onKeyDown={(event) => void handleEnter(event)}
/>
<LuSearch
className={`${styles.search_icon} ${!message ? styles.disabled : ''}`}
onClick={() => void submit()}
/>
</div>
)
}
};

const submit = async (): Promise<void> => {
setMessages([]);
try {
await addQuestion(message);
} catch (error) {
console.error(error);
}
};

/* eslint-disable @typescript-eslint/restrict-template-expressions */

return (
<div className={styles.search_bar_wrapper}>
<input
className={styles.search_input}
type="text"
placeholder="Search"
value={message}
onChange={handleChange}
onKeyDown={(event) => void handleEnter(event)}
/>
<LuSearch
className={`${styles.search_icon} ${!message ? styles.disabled : ""}`}
onClick={() => void submit()}
/>
</div>
);
};
Loading