Skip to content

Commit

Permalink
Merge pull request #12 from fac30/Jason-Warren/Mood-Data
Browse files Browse the repository at this point in the history
Jason warren/mood data
  • Loading branch information
maxitect authored Nov 27, 2024
2 parents d1596d9 + 44bdff2 commit ad3e081
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/app/moods/components/Cube.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client'

import { useContext } from 'react'
import { NeurochemContext } from '../page'

export function Cube() {
const context = useContext(NeurochemContext)

if (!context) {
throw new Error('Cube must be used within a NeurochemContext Provider')
}

const { neuroState } = context

return (
<div className="p-4 border rounded">
<h3 className="text-white">Coordinates:</h3>
<p className="text-white">x (dopamine): {neuroState.dopamine}</p>
<p className="text-white">y (serotonin): {neuroState.serotonin}</p>
<p className="text-white">z (adrenaline): {neuroState.adrenaline}</p>
</div>
)
}
38 changes: 38 additions & 0 deletions src/app/moods/components/Slider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use client'

import { useContext } from 'react'
import { NeurochemContext } from '../page'

interface SliderProps {
chem: 'dopamine' | 'serotonin' | 'adrenaline'
}

export function Slider({ chem }: SliderProps) {
const context = useContext(NeurochemContext)

if (!context) {
throw new Error('Slider must be used within a NeurochemContext Provider')
}

const { neuroState, setNeuroState } = context

const handleChange = (value: number) => {
setNeuroState((prev) => ({
...prev,
[chem]: value
}))
}

return (
<div>
<label className="text-white">{chem}</label>
<input
type="range"
min="0"
max="10"
value={neuroState[chem]}
onChange={(e) => handleChange(parseInt(e.target.value))}
/>
</div>
)
}
13 changes: 13 additions & 0 deletions src/app/moods/components/SliderBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'

import { Slider } from './Slider'

export function SliderBox() {
return (
<div className="flex flex-col gap-4">
<Slider chem="dopamine" />
<Slider chem="serotonin" />
<Slider chem="adrenaline" />
</div>
)
}
38 changes: 33 additions & 5 deletions src/app/moods/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
export default function Page() {
'use client'

import { createContext, useState } from 'react'
import { Cube } from './components/Cube'
import { SliderBox } from './components/SliderBox'

interface NeurochemState {
dopamine: number;
serotonin: number;
adrenaline: number;
}

interface NeurochemContextType {
neuroState: NeurochemState;
setNeuroState: React.Dispatch<React.SetStateAction<NeurochemState>>;
}

export const NeurochemContext = createContext<NeurochemContextType | null>(null)

export default function MoodsPage() {
const [neuroState, setNeuroState] = useState({
dopamine: 5,
serotonin: 5,
adrenaline: 5
})

return (
<>
<h1 className="text-white">this is the moods page</h1>
</>
);
<NeurochemContext.Provider value={{ neuroState, setNeuroState }}>
<div className="flex flex-col gap-4">
<Cube />
<SliderBox />
</div>
</NeurochemContext.Provider>
)
}

0 comments on commit ad3e081

Please sign in to comment.