From 8ae8688996338fb88c39255e336326c95f0f6961 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 30 Apr 2025 00:07:08 +0600 Subject: [PATCH] wip --- .../GenerateCourse/GenerateAICourse.tsx | 16 +++++- src/components/TopicDetail/TopicDetail.tsx | 2 +- src/components/TopicDetail/TopicDetailAI.tsx | 52 ++++++++++++++++--- src/helper/generate-ai-course.ts | 3 ++ 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/components/GenerateCourse/GenerateAICourse.tsx b/src/components/GenerateCourse/GenerateAICourse.tsx index 092cc0964..f7e57f8b2 100644 --- a/src/components/GenerateCourse/GenerateAICourse.tsx +++ b/src/components/GenerateCourse/GenerateAICourse.tsx @@ -54,6 +54,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { const params = getUrlParams(); const paramsTerm = params?.term; const paramsDifficulty = params?.difficulty; + const paramsSrc = params?.src || 'search'; if (!paramsTerm || !paramsDifficulty) { return; } @@ -87,6 +88,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { instructions: paramsCustomInstructions, goal: paramsGoal, about: paramsAbout, + src: paramsSrc, }); }, [term, difficulty]); @@ -98,9 +100,18 @@ export function GenerateAICourse(props: GenerateAICourseProps) { about?: string; isForce?: boolean; prompt?: string; + src?: string; }) => { - const { term, difficulty, isForce, prompt, instructions, goal, about } = - options; + const { + term, + difficulty, + isForce, + prompt, + instructions, + goal, + about, + src, + } = options; if (!isLoggedIn()) { window.location.href = '/ai'; @@ -121,6 +132,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { about, isForce, prompt, + src, }); }; diff --git a/src/components/TopicDetail/TopicDetail.tsx b/src/components/TopicDetail/TopicDetail.tsx index d87f15d62..00d71807a 100644 --- a/src/components/TopicDetail/TopicDetail.tsx +++ b/src/components/TopicDetail/TopicDetail.tsx @@ -70,7 +70,7 @@ type PaidResourceType = { const paidResourcesCache: Record = {}; -const defaultChatHistory: AIChatHistoryType[] = [ +export const defaultChatHistory: AIChatHistoryType[] = [ { role: 'assistant', content: 'Hey, I am your AI instructor. How can I help you today? 🤖', diff --git a/src/components/TopicDetail/TopicDetailAI.tsx b/src/components/TopicDetail/TopicDetailAI.tsx index 18817ee76..36b488eaa 100644 --- a/src/components/TopicDetail/TopicDetailAI.tsx +++ b/src/components/TopicDetail/TopicDetailAI.tsx @@ -12,7 +12,13 @@ import { billingDetailsOptions } from '../../queries/billing'; import { getAiCourseLimitOptions } from '../../queries/ai-course'; import { queryClient } from '../../stores/query-client'; import { isLoggedIn, removeAuthToken } from '../../lib/jwt'; -import { BotIcon, Loader2Icon, LockIcon, SendIcon } from 'lucide-react'; +import { + BotIcon, + Loader2Icon, + LockIcon, + RotateCcwIcon, + SendIcon, +} from 'lucide-react'; import { showLoginPopup } from '../../lib/popup'; import { cn } from '../../lib/classname'; import TextareaAutosize from 'react-textarea-autosize'; @@ -27,6 +33,7 @@ import { markdownToHtmlWithHighlighting } from '../../lib/markdown'; import type { ResourceType } from '../../lib/resource-progress'; import { getPercentage } from '../../lib/number'; import { roadmapTreeMappingOptions } from '../../queries/roadmap-tree'; +import { defaultChatHistory } from './TopicDetail'; type TopicDetailAIProps = { resourceId: string; @@ -217,9 +224,16 @@ export function TopicDetailAI(props: TopicDetailAIProps) { ); const hasSubjects = roadmapTreeMapping?.subjects && roadmapTreeMapping?.subjects?.length > 0; + const hasChatHistory = aiChatHistory.length > 1; return ( -
+
+ {isDataLoading && ( +
+ +
+ )} + {hasSubjects && (

@@ -232,7 +246,7 @@ export function TopicDetailAI(props: TopicDetailAIProps) { {subject} @@ -265,10 +279,33 @@ export function TopicDetailAI(props: TopicDetailAIProps) {

)} - {!isDataLoading && !isPaidUser && ( -

- {usagePercentage}% used -

+ {!isDataLoading && ( +
+ {hasChatHistory && ( + + )} + + {!isPaidUser && ( + <> + +

+ {usagePercentage}% used +

+ + )} +
)}
@@ -349,7 +386,6 @@ export function TopicDetailAI(props: TopicDetailAIProps) { void; onLoadingChange?: (isLoading: boolean) => void; onError?: (error: string) => void; + src?: string; }; export async function generateCourse(options: GenerateCourseOptions) { @@ -37,6 +38,7 @@ export async function generateCourse(options: GenerateCourseOptions) { instructions, goal, about, + src = 'search', } = options; onLoadingChange?.(true); @@ -85,6 +87,7 @@ export async function generateCourse(options: GenerateCourseOptions) { instructions, goal, about, + src, }), credentials: 'include', },