Skip to content

Commit

Permalink
Render on each change
Browse files Browse the repository at this point in the history
  • Loading branch information
cham11ng committed Oct 2, 2023
1 parent 0c9eae4 commit ff289ea
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { calculateBaseScore, checkSeverity, getCVSS31, getWeight } from '../util
const Main = () => {
const [metrics, setMetrics] = useState({})
const [metricWeights, setMetricWeights] = useState({})
const [vector, setVector] = useState(getCVSS31({}))
const [result, setResult] = useState<any>({
vector: getCVSS31({}),
baseScore: null,
severity: {
name: "?",
Expand All @@ -32,15 +32,13 @@ const Main = () => {

setMetrics(newMetrics)
setMetricWeights(newMetricWeights)
setVector(getCVSS31(newMetrics))

if (Object.keys(newMetrics).length === Object.keys(metricToName).length) {
const baseScore = calculateBaseScore(newMetricWeights)
const output = {
vector: getCVSS31(newMetrics),
baseScore,
severity: checkSeverity(baseScore)
}
setResult(output)
const severity = checkSeverity(baseScore)

setResult(severity)
}
};

Expand Down Expand Up @@ -82,8 +80,8 @@ const Main = () => {
{result.severity.name}
<sub>{result.severity.bottom} - {result.severity.top}</sub>
</span><span className="score">{result.baseScore}</span>
<a className="vector" href={`#${result.vector}`}>{result.vector}</a>
<CopyButton text={result.vector} className='copy-button'>Copy</CopyButton>
<a className="vector" href={`#${vector}`}>{vector}</a>
<CopyButton text={vector} className='copy-button'>Copy</CopyButton>
</label>
</dd>
</dl>
Expand Down

0 comments on commit ff289ea

Please sign in to comment.