Skip to content

Commit

Permalink
Add Bank Switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrammalik committed Sep 15, 2022
1 parent e4c8edb commit fed1a9e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
33 changes: 33 additions & 0 deletions src/components/BankSwitch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import bank from "../redux/reducer/bank";

function BankSwitch() {
const dispatch = useDispatch();
const bankState = useSelector((state) => state.bank);
const switchBank = () => {
dispatch({
type: "switch",
});
};

useEffect(() => {
const boxSwitch = document.getElementById("box-switch");
if (bankState === bank.bankOne) {
boxSwitch.style.float = "left";
} else if (bankState === bank.bankTwo) {
boxSwitch.style.float = "right";
}
}, [bankState]);

return (
<div className="flex flex-col items-center">
<p>Bank</p>
<div onClick={switchBank} className="bg-black w-16 h-5 cursor-pointer">
<div className="bg-slate-50 h-[80%] w-4 mx-[1px] my-[2px]" id="box-switch"></div>
</div>
</div>
);
}

export default BankSwitch;
2 changes: 1 addition & 1 deletion src/components/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSelector } from "react-redux";
function Display() {
const currentDisplay = useSelector((state) => state.display);
return (
<div id="display" className="bg-slate-300">
<div id="display" className="bg-slate-300 w-[150px] text-center p-1">
{currentDisplay}
</div>
);
Expand Down
15 changes: 5 additions & 10 deletions src/components/DrumMachine.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React from "react";
import PadGroup from "./PadGroup";
import Display from "./Display";
import { useDispatch } from "react-redux";
import BankSwitch from "./BankSwitch";

function DrumMachine() {
const dispatch = useDispatch();
const switchBank = () => {
dispatch({
type: "switch",
});
};

return (
<div id="drum-machine" className="flex items-center justify-evenly bg-slate-200 gap-4 p-2">
<PadGroup></PadGroup>
<Display></Display>
<button onClick={switchBank}>switch</button>
<div className="flex flex-col justify-center items-center gap-2">
<Display></Display>
<BankSwitch></BankSwitch>
</div>
</div>
);
}
Expand Down

1 comment on commit fed1a9e

@vercel
Copy link

@vercel vercel bot commented on fed1a9e Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.