forked from QuivrHQ/quivr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add onboarding step 3 (QuivrHQ#1324)
* feat: add OnboardingContext * feat: add Step3 boilerplate * feat: activate step3 * feat: add <Step3/> content * feat: add shouldStream guard on useStreamText
- Loading branch information
1 parent
945178d
commit 85eba3d
Showing
20 changed files
with
180 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 5 additions & 8 deletions
13
.../components/ChatDialogueArea/components/ChatDialogue/components/Onboarding/Onboarding.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { useState } from "react"; | ||
|
||
import { Step1 } from "./components"; | ||
import { Step2 } from "./components/Step2"; | ||
import { OnboardingState } from "../types"; | ||
import { Step3 } from "./components/Step3"; | ||
|
||
export const Onboarding = (): JSX.Element => { | ||
const [currentStep, setCurrentStep] = useState<OnboardingState>("DOWNLOAD"); | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<Step1 changeStateTo={setCurrentStep} currentStep={currentStep} /> | ||
<Step2 currentStep={currentStep} /> | ||
<div className="flex flex-col gap-2 mb-3"> | ||
<Step1 /> | ||
<Step2 /> | ||
<Step3 /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
...nents/ChatDialogueArea/components/ChatDialogue/components/Onboarding/components/Step2.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...nents/ChatDialogueArea/components/ChatDialogue/components/Onboarding/components/Step3.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Fragment } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { OnboardingState } from "@/lib/context/OnboardingContext/types"; | ||
import { useOnboardingContext } from "@/lib/hooks/useOnboardingContext"; | ||
|
||
import { MessageRow } from "../../QADisplay"; | ||
import { checkIfShouldDisplayStep } from "../helpers/checkIfShouldDisplayStep"; | ||
import { useStreamText } from "../hooks/useStreamText"; | ||
import { stepsContainerStyle } from "../styles"; | ||
|
||
const stepId: OnboardingState = "UPLOADED"; | ||
|
||
export const Step3 = (): JSX.Element => { | ||
const { currentStep } = useOnboardingContext(); | ||
const shouldStepBeDisplayed = checkIfShouldDisplayStep({ | ||
currentStep, | ||
step: stepId, | ||
}); | ||
|
||
const { t } = useTranslation(["chat"]); | ||
const firstMessage = t("onboarding.last_step"); | ||
const secondMessageStream = t("onboarding.ask_question_to_file"); | ||
const shouldStreamMessage = currentStep === stepId; | ||
|
||
const { streamingText: streamingAssistantMessage, isDone: isAssistantDone } = | ||
useStreamText({ | ||
text: firstMessage, | ||
enabled: shouldStepBeDisplayed, | ||
shouldStream: shouldStreamMessage, | ||
}); | ||
|
||
const { streamingText: firstMessageStream } = useStreamText({ | ||
text: secondMessageStream, | ||
enabled: isAssistantDone && shouldStepBeDisplayed, | ||
shouldStream: shouldStreamMessage, | ||
}); | ||
|
||
if (!shouldStepBeDisplayed) { | ||
return <Fragment />; | ||
} | ||
|
||
return ( | ||
<MessageRow speaker={"assistant"} brainName={"Quivr"}> | ||
<div className={stepsContainerStyle}> | ||
<p>{streamingAssistantMessage}</p> | ||
<p>{firstMessageStream}</p> | ||
</div> | ||
</MessageRow> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...at/[chatId]/components/ChatDialogueArea/components/ChatDialogue/components/types/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
frontend/lib/context/OnboardingContext/knowledgeToFeed-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use client"; | ||
|
||
import { createContext, useState } from "react"; | ||
|
||
import { OnboardingState } from "./types"; | ||
|
||
type OnboardingContextType = { | ||
currentStep: OnboardingState; | ||
setCurrentStep: React.Dispatch<React.SetStateAction<OnboardingState>>; | ||
}; | ||
|
||
export const OnboardingContext = createContext< | ||
OnboardingContextType | undefined | ||
>(undefined); | ||
|
||
export const OnboardingContextProvider = ({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}): JSX.Element => { | ||
const [currentStep, setCurrentStep] = useState<OnboardingState>("DOWNLOAD"); | ||
|
||
return ( | ||
<OnboardingContext.Provider | ||
value={{ | ||
currentStep, | ||
setCurrentStep, | ||
}} | ||
> | ||
{children} | ||
</OnboardingContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type OnboardingState = "DOWNLOAD" | "UPLOAD" | "UPLOADED"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useContext } from "react"; | ||
|
||
import { OnboardingContext } from "../context/OnboardingContext/knowledgeToFeed-provider"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const useOnboardingContext = () => { | ||
const context = useContext(OnboardingContext); | ||
if (!context) { | ||
throw new Error( | ||
"useOnboardingContext must be used within a OnboardingContextProvider" | ||
); | ||
} | ||
|
||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.