Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

loading state to stay until stream

Khuram Niaze1dc57ac9caf
diff --git a/src/components/profile/AiJobMatchResponseContent.tsx b/src/components/profile/AiJobMatchResponseContent.tsx
index bf40b3f..fd07d87 100644
--- a/src/components/profile/AiJobMatchResponseContent.tsx
+++ b/src/components/profile/AiJobMatchResponseContent.tsx
@@ -18,20 +18,26 @@ interface ParsedContent {
export const AiJobMatchResponseContent = ({ content }: { content: string }) => {
if (content.length <= 1) return null;
const parsedContent: ParsedContent = parse(content);
+ const {
+ detailed_analysis,
+ matching_score,
+ suggestions,
+ additional_comments,
+ } = parsedContent;
return (
<>
<div className="pt-2 flex justify-center">
- {parsedContent.matching_score ? (
- <RadialChartComponent score={parsedContent.matching_score} />
+ {matching_score ? (
+ <RadialChartComponent score={matching_score} />
) : (
<RadialChartSekeleton />
)}
</div>
<div className="mt-[-50px]">
- {parsedContent.detailed_analysis && (
+ {detailed_analysis && (
<>
<h2 className="font-semibold mb-2">Detailed Analysis:</h2>
- {parsedContent.detailed_analysis.map((analysis: any, i: number) => (
+ {detailed_analysis.map((analysis: any, i: number) => (
<div key={i}>
<h2 className="font-medium my-1">
{analysis.toString().length > 1 && analysis.category}
@@ -48,10 +54,10 @@ export const AiJobMatchResponseContent = ({ content }: { content: string }) => {
)}
</div>
<div className="pt-2">
- {parsedContent.suggestions && (
+ {suggestions && (
<>
<h2 className="font-semibold mb-2">Suggestions: </h2>
- {parsedContent.suggestions.map((analysis: any, i: number) => (
+ {suggestions.map((analysis: any, i: number) => (
<div key={i}>
<h2 className="font-medium my-1">
{analysis.toString().length > 1 && analysis.category}
@@ -68,11 +74,11 @@ export const AiJobMatchResponseContent = ({ content }: { content: string }) => {
)}
</div>
<div className="pt-2">
- {parsedContent.additional_comments && (
+ {additional_comments && (
<>
<h2 className="font-semibold mb-2">Additional Comments: </h2>
<SheetDescription>
- {parsedContent.additional_comments.map((c: string, i: number) => {
+ {additional_comments.map((c: string, i: number) => {
return <li key={i}>{c}</li>;
})}
</SheetDescription>
diff --git a/src/components/profile/AiJobMatchSection.tsx b/src/components/profile/AiJobMatchSection.tsx
index 29119cf..86eec94 100644
--- a/src/components/profile/AiJobMatchSection.tsx
+++ b/src/components/profile/AiJobMatchSection.tsx
@@ -44,6 +44,7 @@ export const AiJobMatchSection = ({
}: AiSectionProps) => {
const [aIContent, setAIContent] = useState<JobMatchResponse | any>("");
const [loading, setLoading] = useState(false);
+ const [isStreaming, setIsStreaming] = useState(false);
const [selectedResumeId, setSelectedResumeId] = useState<string>();
const [runningModelName, setRunningModelName] = useState<string>("");
const [runningModelError, setRunningModelError] = useState<string>("");
@@ -115,7 +116,7 @@ export const AiJobMatchSection = ({
const decoder = new TextDecoder();
let done = false;
setLoading(false);
-
+ setIsStreaming(true);
while (!done && !abortController.signal.aborted) {
const { value, done: doneReading } = await reader.read();
@@ -125,10 +126,12 @@ export const AiJobMatchSection = ({
setAIContent((prev: any) => prev + parsedChunk);
}
reader.releaseLock();
+ setIsStreaming(false);
} catch (error) {
const message = "Error fetching job matching response";
const description = error instanceof Error ? error.message : message;
setLoading(false);
+ setIsStreaming(false);
toast({
variant: "destructive",
title: "Error!",
@@ -140,7 +143,10 @@ export const AiJobMatchSection = ({
const abortStream = async () => {
abortControllerRef.current?.abort();
console.log("aborting stream");
- await readerRef?.current?.cancel();
+ setIsStreaming(false);
+ if (readerRef.current && !readerRef?.current.closed) {
+ await readerRef?.current.cancel();
+ }
};
const checkModelStatus = useCallback(async () => {
@@ -163,6 +169,7 @@ export const AiJobMatchSection = ({
// Check model status when sheet opens for Ollama
await checkModelStatus();
} else if (openState === false) {
+ abortStream();
// Clear status when closing
setRunningModelName("");
setRunningModelError("");
@@ -251,7 +258,7 @@ export const AiJobMatchSection = ({
</div>
)}
<div className="mt-2">
- {loading ? (
+ {loading || (isStreaming && aIContent.length <= 1) ? (
<div className="flex items-center flex-col">
<Loading />
<div>Loading...</div>
diff --git a/src/components/profile/AiResumeReviewSection.tsx b/src/components/profile/AiResumeReviewSection.tsx
index 6acb0bc..0492f60 100644
--- a/src/components/profile/AiResumeReviewSection.tsx
+++ b/src/components/profile/AiResumeReviewSection.tsx
@@ -205,7 +205,7 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
</span>
</Button>
</div>
- {loading ? (
+ {loading || (isStreaming && aIContent.length <= 1) ? (
<div className="flex items-center flex-col">
<Loading />
<div>Loading...</div>