Skip to content

Commit 06bf524

Browse files
committed
Show error and problem counts in 'Problems' tab title
1 parent 573b863 commit 06bf524

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

src/Playground.res

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,21 +1711,74 @@ let make = (~versions: array<string>) => {
17111711

17121712
let headers = Array.mapWithIndex(tabs, (tab, i) => {
17131713
let title = switch tab {
1714-
| Output => "Output"
1715-
| JavaScript => "JavaScript"
1716-
| Problems => "Problems"
1717-
| Settings => "Settings"
1714+
| Output => "Output"->React.string
1715+
1716+
| JavaScript => "JavaScript"->React.string
1717+
1718+
| Problems => {
1719+
let problemCounts: {"warnings": int, "errors": int} = switch compilerState {
1720+
| Compiling({state: ready})
1721+
| Ready(ready)
1722+
| Executing({state: ready})
1723+
| SwitchingCompiler(ready, _) => {
1724+
"warnings": switch ready.result {
1725+
| Comp(Success({warnings})) => warnings->Array.length
1726+
| _ => 0
1727+
},
1728+
"errors": switch ready.result {
1729+
| FinalResult.Comp(Fail(result)) =>
1730+
switch result {
1731+
| SyntaxErr(errors) | TypecheckErr(errors) | OtherErr(errors) => errors->Array.length
1732+
| WarningErr(errors) => errors->Array.length
1733+
| WarningFlagErr(_) => 1
1734+
}
1735+
| Conv(Fail({details})) => details->Array.length
1736+
| Comp(Success(_)) => 0
1737+
| Conv(Success(_)) => 0
1738+
| Comp(UnexpectedError(_))
1739+
| Conv(UnexpectedError(_))
1740+
| Comp(Unknown(_))
1741+
| Conv(Unknown(_)) => 1
1742+
| Nothing => 0
1743+
},
1744+
}
1745+
1746+
| SetupFailed(_) | Init => {
1747+
"warnings": 0,
1748+
"errors": 0,
1749+
}
1750+
}
1751+
1752+
<div className="inline-flex items-center gap-2">
1753+
{if problemCounts["errors"] > 0 {
1754+
<span className="text-fire bg-fire-100 px-0.5">
1755+
{problemCounts["errors"]->React.int}
1756+
</span>
1757+
} else {
1758+
React.null
1759+
}}
1760+
{if problemCounts["warnings"] > 0 {
1761+
<span className="text-orange bg-orange-15 px-0.5">
1762+
{problemCounts["warnings"]->React.int}
1763+
</span>
1764+
} else {
1765+
React.null
1766+
}}
1767+
{"Problems"->React.string}
1768+
</div>
1769+
}
1770+
1771+
| Settings => "Settings"->React.string
17181772
}
1773+
17191774
let onClick = evt => {
17201775
ReactEvent.Mouse.preventDefault(evt)
17211776
ReactEvent.Mouse.stopPropagation(evt)
17221777
setCurrentTab(_ => tab)
17231778
}
17241779
let active = currentTab === tab
17251780
let className = makeTabClass(active)
1726-
<button key={Int.toString(i) ++ ("-" ++ title)} onClick className disabled>
1727-
{React.string(title)}
1728-
</button>
1781+
<button key={Int.toString(i)} onClick className disabled> {title} </button>
17291782
})
17301783

17311784
<main className={"flex flex-col bg-gray-100 overflow-hidden"}>

0 commit comments

Comments
 (0)