Created
March 28, 2021 19:40
-
-
Save FunctionDJ/d49daa952a80d98bd03054ad2586ccc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ReactElement } from "react"; | |
import { Alert } from "react-bootstrap"; | |
import { ChangeVarNumber_T } from "../../interfaces/actions"; | |
interface Props { | |
data: ChangeVarNumber_T | |
} | |
export const ChangeVarNumber = ({ data }: Props) => { | |
const value = ( | |
<code> | |
{typeof data.value === "object" // this is so stupid | |
? data.value.varName | |
: data.value | |
} | |
</code> | |
); | |
const variable = ( | |
<code> | |
{data.varName} | |
</code> | |
); | |
let content: ReactElement; | |
switch (data.changeType) { | |
case "add": { | |
content = ( | |
<> | |
{"Add "} | |
{value} | |
{" to "} | |
{variable} | |
</> | |
); | |
break; | |
} | |
case "set": { | |
content = ( | |
<> | |
{"Set "} | |
{value} | |
{" to "} | |
{variable} | |
</> | |
); | |
break; | |
} | |
case "mul": { | |
content = ( | |
<> | |
{"Multiply "} | |
{variable} | |
{" with "} | |
{value} | |
</> | |
); | |
break; | |
} | |
default: { | |
throw new Error("unhandled changeType"); | |
} | |
} | |
return ( | |
<Alert variant="primary"> | |
{content} | |
</Alert> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment