Skip to content

Commit

Permalink
fix setstate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tevko committed Dec 17, 2024
1 parent d71cc97 commit 700b055
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 37 deletions.
69 changes: 41 additions & 28 deletions client-report/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const App = (props) => {
const [computedStats, setComputedStats] = useState(null);
const [nothingToShow, setNothingToShow] = useState(true);
const [hasError, setError] = useState(false);
const [parsedNarrativeUncertainty, setParsedNarrativeUncertainty] = useState(null);
const [parsedNarrativeConsensus, setParsedNarrativeConsensus] = useState(null);

let corMatRetries;

Expand All @@ -84,6 +86,15 @@ const App = (props) => {
}
}, [window.location?.pathname]);

useEffect(() => {
if (narrative?.group_informed_consensus) {
setParsedNarrativeConsensus(narrative.group_informed_consensus);
}
if (narrative?.uncertainty) {
setParsedNarrativeUncertainty(narrative.uncertainty);
}
}, [narrative?.uncertainty, narrative?.group_informed_consensus, JSON.stringify(narrative)])

const getMath = async (conversation_id) => {
return net
.polisGet("/api/v3/math/pca2", {
Expand Down Expand Up @@ -146,7 +157,11 @@ const App = (props) => {
}
const decodedChunk = decoder.decode(value, { stream: true });

if (!decodedChunk.includes('POLIS-PING:')) setNarrative(n => Object.assign((n || {}), JSON.parse(decodedChunk)));
if (!decodedChunk.includes('POLIS-PING:')) {
const o = narrative || {};
const c = JSON.parse(decodedChunk);
setNarrative({...o, ...c});
}
}
}

Expand Down Expand Up @@ -511,8 +526,6 @@ const App = (props) => {
);
}

console.log(conversation, narrative)

return (
<div style={{ margin: "0px 10px" }} data-testid="reports-overview">
<Heading conversation={conversation} />
Expand Down Expand Up @@ -552,31 +565,31 @@ const App = (props) => {
<>
<button onClick={() => setModel(m => m === "claude" ? "gemini" : "claude" )}>Toggle Model</button>
<h4>Current Model: {model}</h4>
{narrative ? (
<>
<ConsensusNarrative
math={math}
comments={comments}
conversation={conversation}
ptptCount={ptptCount}
formatTid={formatTid}
voteColors={voteColors}
narrative={narrative}
model={model}
/>
<UncertaintyNarrative
math={math}
comments={comments}
uncertainty={uncertainty}
conversation={conversation}
ptptCount={ptptCount}
formatTid={formatTid}
voteColors={voteColors}
narrative={narrative}
model={model}
/>
</>
) : "...Loading"}
{parsedNarrativeConsensus ? (
<ConsensusNarrative
math={math}
comments={comments}
conversation={conversation}
ptptCount={ptptCount}
formatTid={formatTid}
voteColors={voteColors}
narrative={parsedNarrativeConsensus}
model={model}
/>
) : "...Loading Consensus \n"}
{parsedNarrativeUncertainty ? (
<UncertaintyNarrative
math={math}
comments={comments}
uncertainty={uncertainty}
conversation={conversation}
ptptCount={ptptCount}
formatTid={formatTid}
voteColors={voteColors}
narrative={parsedNarrativeUncertainty}
model={model}
/>
) : "...Loading Uncertainty \n"}
</>
) : (
<>
Expand Down
8 changes: 4 additions & 4 deletions client-report/src/components/lists/consensusNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const ConsensusNarrative = ({
narrative,
model
}) => {
console.log(narrative?.group_informed_consensus)
if (!narrative?.group_informed_consensus) {

if (!narrative) {
return <div>Loading Consensus...</div>;
}
const txt = model === "claude" ? narrative.group_informed_consensus.responseClaude.content[0].text : narrative.group_informed_consensus.responseGemini;
const txt = model === "claude" ? narrative.responseClaude.content[0].text : narrative.responseGemini;

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);

Expand All @@ -40,7 +40,7 @@ const ConsensusNarrative = ({
<p style={globals.paragraph}>
This narrative summary may contain hallucinations. Check each clause.
</p>
<Narrative sectionData={narrative.group_informed_consensus} model={model} />
<Narrative sectionData={narrative} model={model} />
<div style={{ marginTop: 50 }}>
<CommentList
conversation={conversation}
Expand Down
6 changes: 3 additions & 3 deletions client-report/src/components/lists/uncertaintyNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const UncertaintyNarrative = ({
narrative,
model
}) => {
if (!conversation || !narrative || !narrative?.uncertainty?.responseClaude || !narrative?.uncertainty?.responseGemini) {
if (!conversation || !narrative || !narrative?.responseClaude || !narrative?.responseGemini) {
return <div>Loading Uncertainty...</div>;
}

const txt = model === "claude" ? narrative?.uncertainty.responseClaude.content[0].text : narrative?.uncertainty.responseGemini;
const txt = model === "claude" ? narrative?.responseClaude.content[0].text : narrative?.responseGemini;

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);

Expand All @@ -44,7 +44,7 @@ const UncertaintyNarrative = ({
<p style={globals.paragraph}>
This narrative summary may contain hallucinations. Check each clause.
</p>
<Narrative sectionData={narrative.uncertainty} model={model} />
<Narrative sectionData={narrative} model={model} />
<div style={{ marginTop: 50 }}>
<CommentList
conversation={conversation}
Expand Down
2 changes: 0 additions & 2 deletions client-report/src/components/narrative/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import React from "react";
const Narrative = ({ sectionData, model }) => {
if (!sectionData) return null;

console.log("narrativeData", sectionData);

const txt = model === "claude" ? sectionData.responseClaude.content[0].text : sectionData.responseGemini;

const respData = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);
Expand Down

0 comments on commit 700b055

Please sign in to comment.