diff --git a/src/components/PromptList.tsx b/src/components/PromptList.tsx
index 9b7c0291..695c1135 100644
--- a/src/components/PromptList.tsx
+++ b/src/components/PromptList.tsx
@@ -12,6 +12,7 @@ export function PromptList({ prompts }: { prompts: Prompt[] }) {
const { currentPromptId, setCurrentPromptId } = usePromptsStore();
const groupedPrompts = groupPromptsByRelativeDate(prompts);
+
return (
{Object.entries(groupedPrompts).map(([group, prompts]) => (
diff --git a/src/hooks/useBreadcrumb.ts b/src/hooks/useBreadcrumb.ts
index 83609da7..0189afcc 100644
--- a/src/hooks/useBreadcrumb.ts
+++ b/src/hooks/useBreadcrumb.ts
@@ -1,4 +1,4 @@
-import { extractTitleFromMessage } from "@/lib/utils";
+import { extractTitleFromMessage, sanitizeQuestionPrompt } from "@/lib/utils";
import { useLocation } from "react-router-dom";
import { usePromptsStore } from "./usePromptsStore";
@@ -20,7 +20,12 @@ export function useBreadcrumb() {
try {
const chat = prompts.find((prompt) => prompt.chat_id === currentPromptId);
const title = chat?.question_answers?.[0].question.message ?? "";
- return extractTitleFromMessage(title) ?? "";
+
+ const sanitized = sanitizeQuestionPrompt({
+ question: title,
+ answer: chat?.question_answers?.[0]?.answer?.message ?? "",
+ });
+ return extractTitleFromMessage(sanitized) ?? "";
} catch {
return "";
}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 502f353f..107fdfde 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -20,7 +20,6 @@ export function extractTitleFromMessage(message: string) {
if (match) {
const beforeMarkdown = match[1].trim();
const afterMarkdown = match[2].trim();
-
const title = beforeMarkdown || afterMarkdown;
return title;
}
@@ -121,12 +120,25 @@ export function sanitizeQuestionPrompt({
answer: string;
}) {
try {
+ // Check if 'answer' is truthy; if so, try to find and return the text after "Query:"
if (answer) {
- return question.split("Query:").pop() ?? "";
+ const index = question.indexOf("Query:");
+ if (index !== -1) {
+ // Return the substring starting right after the first occurrence of "Query:"
+ // Adding the length of "Query:" to the index to start after it
+ return question.substring(index + "Query:".length).trim();
+ } else {
+ // If there is no "Query:" in the string, log the condition and return an empty string
+ console.log("No 'Query:' found in the question.");
+ return "";
+ }
+ } else {
+ // If 'answer' is not provided or falsy, return the original question
+ return question;
}
-
- return question;
- } catch {
+ } catch (error) {
+ // Log the error and return the original question as a fallback
+ console.error("Error processing the question:", error);
return question;
}
}