Skip to content

Commit

Permalink
Get recording ID in effect callback
Browse files Browse the repository at this point in the history
  • Loading branch information
bhackett1024 committed Dec 13, 2024
1 parent 6cab82e commit b634e52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/components/PerformanceMockup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { OriginDisplay } from "./performance/OriginDisplay";
import { useEffect, useState } from "react";
import { fetchPerformanceResult } from "@/performance/performanceResult";
import { getRecordingId } from "@/performance/params";
import { assert } from "@/performance/utils";

export default function PerformanceMockup() {
const recordingId = getRecordingId();
if (!recordingId) {
return <div className="Status">Invalid or missing recordingId</div>;
}

const [result, setResult] = useState<PerformanceAnalysisResult | string | null>(null);

useEffect(() => {
if (!result) {
fetchPerformanceResult(recordingId).then(setResult);
const recordingId = getRecordingId();
if (recordingId) {
fetchPerformanceResult(recordingId).then(setResult);
} else {
setResult("Invalid or missing recordingId");
}
}
}, [recordingId, result]);
}, [result]);

if (!result) {
return <div className="Status">Loading...</div>;
Expand All @@ -29,6 +30,8 @@ export default function PerformanceMockup() {
}

const { recordingURL } = result;
const recordingId = getRecordingId();
assert(recordingId);

return (
<div className="App h-screen w-screen flex flex-col text-xl">
Expand Down
2 changes: 1 addition & 1 deletion src/performance/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function assert(v: any) {
export function assert(v: any): asserts v {
if (!v) {
throw new Error("Assertion Failed!");
}
Expand Down

0 comments on commit b634e52

Please sign in to comment.