Skip to content

Commit

Permalink
fix: search respecting org switch and no patents found
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinceBaghel258025 committed May 2, 2024
1 parent dc2aea3 commit ffd4e39
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"drizzle-orm": "0.26.5",
"drizzle-orm": "0.30.9",
"drizzle-zod": "0.4.2",
"encoding": "^0.1.13",
"eslint": "8.37.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/chats/[chatid]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export async function GET(

const msg = fetchedChat[0].messages;
const chatlog = JSON.parse(msg as string) as ChatLog;
console.log("fetchedChat route", chatlog);
// console.log("fetchedChat route", chatlog);
return NextResponse.json({ chats: chatlog ? chatlog : [] });
}
7 changes: 3 additions & 4 deletions src/app/api/patentsearch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export async function POST(request: Request) {
chatlog.log.length,
);

console.log("prevChatData", nextChatData);

const res = await axios.get(`${baseUrl}/search/102`, {
params: {
q: query,
Expand All @@ -70,6 +68,9 @@ export async function POST(request: Request) {

console.log("data", data);

if (data?.length === 0) {
return NextResponse.json({ data: null }, { status: 404 });
}
const patentMessage = {
role: "assistant",
subRole: "patent-search",
Expand All @@ -89,7 +90,5 @@ export async function POST(request: Request) {
.where(eq(chats.id, Number(chatId)))
.run();

// console.log(data)

return NextResponse.json({ data: updatedChatLog });
}
2 changes: 1 addition & 1 deletion src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export default function Chat(props: ChatProps) {
</>
)}
<div className="h-0" ref={sheetContentRef} />
{scrollToBottom()}
{/* {scrollToBottom()} */}
</div>
);
}
48 changes: 27 additions & 21 deletions src/components/chatmessagecombinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,29 @@ const ChatMessageCombinator = ({
const queryClient = useQueryClient();
const sheetContentRef = useRef<HTMLDivElement>(null); // Specify the type as HTMLDivElement

const mutation = useMutation(
async (data: { id: string; msgs: Message[]; lastMessageIndex: number }) => {
const mutation = useMutation<
Message[] | null,
unknown,
{ msgs: Message[]; id: string; lastMessageIndex: number }
>({
mutationFn: async (data) => {
const res = await axios.post(`/api/patentsearch`, {
msgs: data.msgs,
orgId: orgId,
chatId: chatId,
lastMessageIndex: data.lastMessageIndex,
});
const result = res.data;
console.log("patentresult", result);
console.log("patentresult", res.data);
return res.data;
},
{
onSuccess: () => {
// Invalidate and refetch
queryClient.invalidateQueries(["chats", chatId]);
},
onSuccess: (data, variables) => {
if (!data) {
console.log("no patients found");
}
queryClient.invalidateQueries({ queryKey: ["chats", chatId] });
},
);
onError: (_error: any) => {},
});

const titleSplit = chatTitle?.replaceAll('"', "").split(":");
const chat_title = titleSplit?.[0];
Expand Down Expand Up @@ -236,6 +241,14 @@ const ChatMessageCombinator = ({
preferences.showSubRoll ? (
patentMessage ? (
<PatentData index={index} message={patentMessage} />
) : mutation.isLoading &&
mutation.variables?.id === msg.id ? (
<div>
<div className="w-[150px]">
<Skeleton className=" w-[150px] h-[225px] rounded object-cover" />
</div>
<Skeleton className="scroll-m-20 tracking-tight text-xs line-clamp-2 w-[150px]"></Skeleton>
</div>
) : (
<Button
disabled={mutation.isLoading}
Expand All @@ -248,17 +261,10 @@ const ChatMessageCombinator = ({
}
className={cn("mx-4 my-3", isLoading && "hidden")}
>
{mutation.isLoading &&
mutation.variables?.id === msg.id ? (
<div>
<div className="w-[150px]">
<Skeleton className=" w-[150px] h-[225px] rounded object-cover" />
</div>
<Skeleton className="scroll-m-20 tracking-tight text-xs line-clamp-2 w-[150px]"></Skeleton>
</div>
) : (
"Search For Patents"
)}
{mutation?.isError &&
mutation?.variables?.id === msg.id
? "No patents found. Search Again"
: "Search For Patents"}
</Button>
)
) : null
Expand Down
1 change: 0 additions & 1 deletion src/components/patentdata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const PatentData = ({
"item",
parseAsInteger,
);
console.log(parsedInput);
const [open, setOpen] = React.useState(
isOpen && dialogIndex === dialogNumber ? isOpen : false,
);
Expand Down
4 changes: 1 addition & 3 deletions src/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ const Search = (props: Props) => {
filters: `orgSlug: "${props.orgSlug}"`,
})
.then((response) => {
console.log(response);
return setResults(response.hits);
});
}, [throttledValue]);
}, [throttledValue, props?.orgSlug]);

return (
<CommandDialog open={showSearchDialog} onOpenChange={toggleSearchDialog}>
<CommandInput
onValueChange={(val) => {
console.log("got the input value");
setValue(val);
}}
value={value}
Expand Down

0 comments on commit ffd4e39

Please sign in to comment.