Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffer Engman committed Oct 7, 2023
1 parent cf1f887 commit dc6e5fb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.8.0
15 changes: 8 additions & 7 deletions app/src/components/Pad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { ColorOff, randomRGB, rgbToHex } from 'Utils/color'
import React, { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'

type Props = { x: number, y: number }
type Props = { x: number; y: number }

const Pad = ({ x, y }: Props) => {
const button = parseInt(`${y}${x}`)

const dispatch = useDispatch()
const [isMouseOver, setMouseOver] = useState(false)
const { isPressed, color } = useSelector((state: any) => state.pad.buttons[button])
const { isPressed, color } = useSelector(
(state: any) => state.pad.buttons[button]
)

useEffect(() => {
console.log("MOUNTED => ", button)
return () => console.log("DISMOUNTED!!!!")
// return () => console.log("DISMOUNTED!!!!")
}, [])

useEffect(
Expand All @@ -25,13 +26,13 @@ const Pad = ({ x, y }: Props) => {
)

useEffect(() => {
console.log('INVOKE PRESSED =>', button, 'STATE: ', isPressed)
// console.log('INVOKE PRESSED =>', button, 'STATE: ', isPressed)
if (isPressed) {
dispatch(changeColor(button, randomRGB()))
// dispatch(changeColor(button, randomRGB()))
return
}
if (!isPressed) {
setTimeout(() => dispatch(changeColor(button, ColorOff)), 1000)
// setTimeout(() => dispatch(changeColor(button, ColorOff)), 1000)
}
}, [isPressed])

Expand Down
17 changes: 17 additions & 0 deletions app/src/components/Slider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { changeColor } from 'Redux/components/pad/padActions'
import React from 'react'
import { useDispatch } from 'react-redux'

type Props = { buttonMap: number[] }

const Slider = ({ buttonMap }: Props) => {
const dispatch = useDispatch()

buttonMap.map((button) => {
dispatch(changeColor(button, [0, 200, 0]))
})

return <></>
}

export default Slider
7 changes: 7 additions & 0 deletions app/src/hooks/usePadPressed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useSelector } from 'react-redux'

const usePadPressed = (button: string) => {
const { isPressed } = useSelector((state: any) => state.pad.buttons[button])
}

export default usePadPressed
14 changes: 10 additions & 4 deletions app/src/pages/launchpad/launchpad.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Grid } from '@material-ui/core'
import Pad from 'Components/Pad'
import Slider from 'Components/Slider'
import Test from 'Components/Test'
import { CHANNELS } from 'Constants/ipc'
import React from 'react'

import React, { createContext } from 'react'

const createGrid = () => {
const rows = []
Expand All @@ -19,14 +19,20 @@ const createGrid = () => {
return rows
}

type Props = any
const SliderButtonMapping = {
buttons: [11, 21, 31, 41, 51, 61, 71, 81]
}

const GridContext = createContext('Components')

const Launchpad = (props: Props) => {
type Props = { component: any }
const Launchpad = ({ component }: Props) => {
// @ts-ignore
window.api.send(CHANNELS.LP.CLEAR)

return (
<>
<Slider buttonMap={SliderButtonMapping.buttons}/>
{createGrid().map((row) => (
<Grid container>
{row.map((pad) => (
Expand Down
2 changes: 1 addition & 1 deletion app/src/redux/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const store = configureStore({
serializableCheck: false,
}),
routerMiddleware,
logger,
// logger,
],
})

Expand Down

0 comments on commit dc6e5fb

Please sign in to comment.