mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
random speaker button
This commit is contained in:
1 parent
9df2d53d36
commit
db7c2bb788
2 files changed
+40
-11
No files matched your search
+18
-6
@@ -165,7 +165,7 @@ class App extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
setSpeakerBySlug = (speakerSlug: string) : void => {
|
||||
let selectedSpeaker = undefined;
|
||||
let selectedSpeaker : Speaker | undefined = undefined;
|
||||
|
||||
SPEAKERS.forEach(speaker => {
|
||||
if (speaker.slug === speakerSlug) {
|
||||
@@ -173,12 +173,24 @@ class App extends React.Component<Props, State> {
|
||||
}
|
||||
})
|
||||
|
||||
if (selectedSpeaker !== undefined) {
|
||||
this.setState({
|
||||
speaker: selectedSpeaker,
|
||||
extrasMode: ExtrasMode.SPEAKER_INFO,
|
||||
});
|
||||
if (selectedSpeaker === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const speakers = SPEAKERS_BY_CATEGORY.get(this.state.currentSpeakerCategory) || [];
|
||||
|
||||
let isCategoryCorrect = speakers.find(speaker =>
|
||||
speaker.getSlug() === selectedSpeaker!.getSlug()) !== undefined;
|
||||
|
||||
let category = isCategoryCorrect
|
||||
? this.state.currentSpeakerCategory
|
||||
: CATEGORY_ALL;
|
||||
|
||||
this.setState({
|
||||
speaker: selectedSpeaker,
|
||||
extrasMode: ExtrasMode.SPEAKER_INFO,
|
||||
currentSpeakerCategory: category,
|
||||
});
|
||||
}
|
||||
|
||||
updateSpectrogram = (spectrogram: Spectrogram) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { CategoryDropdown } from './dropdowns/CategoryDropdown';
|
||||
import { Form } from './Form';
|
||||
import { Speaker, SpeakerCategory } from '../../model/Speakers';
|
||||
import { Speaker, SpeakerCategory, SPEAKERS } from '../../model/Speakers';
|
||||
import { SpeakerDropdown } from './dropdowns/SpeakerDropdown';
|
||||
import { SpeakerInfo } from './extras/SpeakerInfo';
|
||||
import { Spectrogram } from './extras/Spectrogram';
|
||||
@@ -140,6 +140,12 @@ class SpeakComponent extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
selectRandomSpeaker = () => {
|
||||
const index = Math.floor(Math.random() * SPEAKERS.length);
|
||||
const speaker = SPEAKERS[index]!;
|
||||
this.props.changeSpeakerCallback(speaker.getSlug());
|
||||
}
|
||||
|
||||
public render() {
|
||||
let speakerPictureOrSpectrogram;
|
||||
switch (this.props.extrasMode) {
|
||||
@@ -174,11 +180,22 @@ class SpeakComponent extends React.Component<Props, State> {
|
||||
|
||||
return (
|
||||
<section>
|
||||
<CategoryDropdown
|
||||
currentSpeakerCategory={this.props.currentSpeakerCategory}
|
||||
changeSpeakerCategoryCallback={this.props.changeSpeakerCategoryCallback}
|
||||
/>
|
||||
<div className="columns is-mobile is-gapless">
|
||||
<div className="column">
|
||||
<CategoryDropdown
|
||||
currentSpeakerCategory={this.props.currentSpeakerCategory}
|
||||
changeSpeakerCategoryCallback={this.props.changeSpeakerCategoryCallback}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="column">
|
||||
<button
|
||||
className="button is-light is-info"
|
||||
onClick={this.selectRandomSpeaker}
|
||||
>Random Speaker</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="columns is-mobile is-gapless">
|
||||
|
||||
<SpeakerDropdown
|
||||
|
||||
Reference in new issue
Block a user