An easy-to-use platform for EEG experimentation in the classroom
at main 191 lines 5.7 kB view raw
1import React, { Component } from 'react'; 2import { Button } from '../ui/button'; 3 4enum HELP_STEP { 5 MENU, 6 SIGNAL_EXPLANATION, 7 SIGNAL_SALINE, 8 SIGNAL_CONTACT, 9 SIGNAL_MOVEMENT, 10 LEARN_BRAIN, 11 LEARN_BLINK, 12 LEARN_THOUGHTS, 13 LEARN_ALPHA, 14} 15 16interface Props { 17 handleClose: () => void; 18} 19 20interface State { 21 helpStep: HELP_STEP; 22} 23 24// TODO: Refactor this into a more reusable Sidebar component that can be used in Collect, Clean, and Analyze screen 25export class HelpSidebar extends Component<Props, State> { 26 constructor(props) { 27 super(props); 28 this.state = { 29 helpStep: HELP_STEP.MENU, 30 }; 31 this.handleStartLearn = this.handleStartLearn.bind(this); 32 this.handleStartSignal = this.handleStartSignal.bind(this); 33 this.handleNext = this.handleNext.bind(this); 34 this.handleBack = this.handleBack.bind(this); 35 } 36 37 handleStartSignal() { 38 this.setState({ helpStep: HELP_STEP.SIGNAL_EXPLANATION }); 39 } 40 41 handleStartLearn() { 42 this.setState({ helpStep: HELP_STEP.LEARN_BRAIN }); 43 } 44 45 handleNext() { 46 if ( 47 this.state.helpStep === HELP_STEP.SIGNAL_MOVEMENT || 48 this.state.helpStep === HELP_STEP.LEARN_ALPHA 49 ) { 50 this.setState({ helpStep: HELP_STEP.MENU }); 51 } else { 52 this.setState((prevState) => ({ 53 ...prevState, 54 helpStep: prevState.helpStep + 1, 55 })); 56 } 57 } 58 59 handleBack() { 60 this.setState((prevState) => ({ 61 ...prevState, 62 helpStep: prevState.helpStep - 1, 63 })); 64 } 65 66 renderMenu() { 67 return ( 68 <div className="flex flex-col"> 69 <h1 className="mb-4">What would you like to do?</h1> 70 <div 71 role="button" 72 tabIndex={0} 73 className="text-lg p-1 cursor-pointer hover:bg-gray-100" 74 onClick={this.handleStartSignal} 75 onKeyDown={(e) => e.key === 'Enter' && this.handleStartSignal()} 76 > 77 Improve the signal quality of your sensors 78 </div> 79 <div 80 role="button" 81 tabIndex={0} 82 className="text-lg p-1 cursor-pointer hover:bg-gray-100" 83 onClick={this.handleStartLearn} 84 onKeyDown={(e) => e.key === 'Enter' && this.handleStartLearn()} 85 > 86 Learn about how the subjects movements create noise 87 </div> 88 </div> 89 ); 90 } 91 92 renderHelp(header: string, content: string) { 93 return ( 94 <> 95 <div className="text-lg h-[80%]"> 96 <h1 className="mb-4">{header}</h1> 97 {content} 98 </div> 99 <div className="flex gap-2 mt-4"> 100 <Button 101 variant="secondary" 102 className="w-full" 103 onClick={this.handleBack} 104 > 105 Back 106 </Button> 107 <Button 108 variant="default" 109 className="w-full" 110 onClick={this.handleNext} 111 > 112 Next 113 </Button> 114 </div> 115 </> 116 ); 117 } 118 119 renderHelpContent() { 120 switch (this.state.helpStep) { 121 case HELP_STEP.SIGNAL_EXPLANATION: 122 return this.renderHelp( 123 'Improve the signal quality', 124 'In order to collect quality data, you want to make sure that all electrodes have a strong connection' 125 ); 126 case HELP_STEP.SIGNAL_SALINE: 127 return this.renderHelp( 128 'Tip #1: Saturate the sensors in saline', 129 'Make sure the sensors are thoroughly soaked with saline solution. They should be wet to the touch' 130 ); 131 case HELP_STEP.SIGNAL_CONTACT: 132 return this.renderHelp( 133 'Tip #2: Ensure the sensors are making firm contact', 134 'Re-seat the headset to make sure that all sensors contact the head with some tension. Take extra care to make sure the reference electrodes (the ones right behind the ears) make proper contact. You may need to sweep hair out of the way to accomplish this' 135 ); 136 case HELP_STEP.SIGNAL_MOVEMENT: 137 return this.renderHelp( 138 'Tip #3: Stay still', 139 'To reduce noise during your experiment, ensure your subject is relaxed and has both feet on the floor. Sometimes, focusing on relaxing the jaw and the tongue can improve the EEG signal' 140 ); 141 case HELP_STEP.LEARN_BRAIN: 142 return this.renderHelp( 143 'Your brain produces electricity', 144 'Using the device that you are wearing, we can detect the electrical activity of your brain.' 145 ); 146 case HELP_STEP.LEARN_BLINK: 147 return this.renderHelp( 148 'Try blinking your eyes', 149 'Does the signal change? Eye movements create noise in the EEG signal' 150 ); 151 case HELP_STEP.LEARN_THOUGHTS: 152 return this.renderHelp( 153 'Try thinking of a cat', 154 "Does the signal change? Although EEG can measure overall brain activity, it's not capable of reading minds" 155 ); 156 case HELP_STEP.LEARN_ALPHA: 157 return this.renderHelp( 158 'Try closing your eyes for 10 seconds', 159 'You may notice a change in your signal due to an increase in alpha waves' 160 ); 161 case HELP_STEP.MENU: 162 default: 163 return this.renderMenu(); 164 } 165 } 166 167 render() { 168 return ( 169 <div className="h-full p-4 bg-white border-l border-gray-200"> 170 <div className="flex justify-end"> 171 <button onClick={this.props.handleClose} aria-label="Close"> 172 173 </button> 174 </div> 175 {this.renderHelpContent()} 176 </div> 177 ); 178 } 179} 180 181export const HelpButton: React.FC<{ onClick: () => void }> = ({ onClick }) => { 182 return ( 183 <button 184 className="h-11 w-11 rounded-full bg-brand text-white flex items-center justify-center font-bold text-lg" 185 onClick={onClick} 186 aria-label="Help" 187 > 188 ? 189 </button> 190 ); 191};