Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature mark option selected #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ button .active {
font-size: 17px;
}

.selected-option {
box-shadow: none;
color: #000;
background-color: #ffffffcc;
border: none;
width: 140px;
padding: 24px;
font-size: 17px;
}

.App {
height: 100vh;
display: flex;
Expand Down
35 changes: 22 additions & 13 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class App extends Component {
audioUrl : rainAudio, // Default
bgImg : rainImg,
desiredTime : 120, // Default
selectedTime : 120,
selectedAudio : 'Rain'
}
}

timeSelect(x) {
this.setState({
desiredTime : x.duration
desiredTime : x.duration,
});
}

Expand All @@ -63,28 +65,33 @@ class App extends Component {

if (x === this.state.audioNames[1]){
this.setState({
audioUrl : forestAudio,
bgImg : forestImg
audioUrl : forestAudio,
bgImg : forestImg,
selectedAudio : x
});
}else if (x === this.state.audioNames[2]) {
this.setState({
audioUrl : parkAudio,
bgImg : parkImg
audioUrl : parkAudio,
bgImg : parkImg,
selectedAudio : x
});
}else if (x === this.state.audioNames[3]) {
this.setState({
audioUrl : streamAudio,
bgImg : streamImg
audioUrl : streamAudio,
bgImg : streamImg,
selectedAudio : x
});
}else if (x === this.state.audioNames[4]) {
this.setState({
audioUrl : wavesAudio,
bgImg : wavesImg
audioUrl : wavesAudio,
bgImg : wavesImg,
selectedAudio : x
});
}else {
this.setState({
audioUrl : rainAudio,
bgImg : rainImg
audioUrl : rainAudio,
bgImg : rainImg,
selectedAudio : x
});
}
}
Expand All @@ -99,12 +106,14 @@ class App extends Component {
}
render() {
console.log(this.state.timeBtnClass);
const { selectedAudio, desiredTime } = this.state

const timeOptions = this.state.timeValues.map((duration) =>
<button key={duration} onClick={ () => {this.timeSelect({duration})} }>{duration/60} Minutes</button>
<button key={duration} onClick={ () => {this.timeSelect({duration})} } className={desiredTime === duration ? 'selected-option' : undefined}>{duration/60} Minutes</button>
);

const audioOptions = this.state.audioNames.map((audioName) =>
<button key={audioName} onClick={ () => {this.audioSelect({audioName})} }>{audioName}</button>
<button key={audioName} onClick={ () => {this.audioSelect({audioName})} } className={selectedAudio === audioName ? 'selected-option' : undefined}>{audioName}</button>
);

return (
Expand Down