This commit is contained in:
BFlat authored and Brandon Thomas committed 2023-04-01 01:43:25 -07:00
1 parent e375af5eea
commit f075aa6fc6
4 files changed
-139

No files matched your search

@@ -7,7 +7,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faStar,
faArrowRight,
faWaveformLines,
faVolume,
} from "@fortawesome/pro-solid-svg-icons";
import { Analytics } from "../../../../common/Analytics";
@@ -1,7 +1,6 @@
import React from "react";
import { TtsCategoryType } from "../../../../../AppWrapper";
import { TtsModelListItem } from "@storyteller/components/src/api/tts/ListTtsModels";
import { ExploreVoicesTray } from "./components/ExploreVoicesTray";
import { ScopedVoiceModelOptions } from "./components/ScopedVoiceModelOptions";
import { VoiceCountLabel } from "./components/VoiceCountLabel";
@@ -1,136 +0,0 @@
import React from "react";
import { faEraser } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { LanguageOptions } from "../filters/LanguageOptions";
import { TtsCategoryType } from "../../../../../../AppWrapper";
import { TtsModelListItem } from "@storyteller/components/src/api/tts/ListTtsModels";
import { CategoryOptions } from "../filters/CategoryOptions";
import { t } from "i18next";
interface Props {
allTtsCategories: TtsCategoryType[];
allTtsModels: TtsModelListItem[];
allTtsCategoriesByTokenMap: Map<string, TtsCategoryType>;
allTtsModelsByTokenMap: Map<string, TtsModelListItem>;
ttsModelsByCategoryToken: Map<string, Set<TtsModelListItem>>;
dropdownCategories: TtsCategoryType[][];
setDropdownCategories: (dropdownCategories: TtsCategoryType[][]) => void;
selectedCategories: TtsCategoryType[];
setSelectedCategories: (selectedCategories: TtsCategoryType[]) => void;
maybeSelectedTtsModel?: TtsModelListItem;
setMaybeSelectedTtsModel: (maybeSelectedTtsModel: TtsModelListItem) => void;
selectedTtsLanguageScope: string;
setSelectedTtsLanguageScope: (selectedTtsLanguageScope: string) => void;
}
export function ExploreVoicesTray(props: Props) {
const {
allTtsCategories,
allTtsCategoriesByTokenMap,
ttsModelsByCategoryToken,
dropdownCategories,
setDropdownCategories,
selectedCategories,
setSelectedCategories,
maybeSelectedTtsModel,
} = props;
const doChangeCategory = (level: number, maybeToken: string) => {
// Slice off all the irrelevant child category choices, then append new choice.
let newCategorySelections = selectedCategories.slice(0, level);
// And the dropdowns themselves
let newDropdownCategories = dropdownCategories.slice(0, level + 1);
let category = allTtsCategoriesByTokenMap.get(maybeToken);
if (!!category) {
newCategorySelections.push(category);
}
setSelectedCategories(newCategorySelections);
const newSubcategories = allTtsCategories.filter((category) => {
return category.maybe_super_category_token === maybeToken;
});
newDropdownCategories.push(newSubcategories);
setDropdownCategories(newDropdownCategories);
// We might have switched into a category without our selected TTS model.
// If so, pick a new TTS model.
let maybeNewModel = undefined;
const availableModelsForCategory = ttsModelsByCategoryToken.get(maybeToken);
if (!!availableModelsForCategory && !!maybeSelectedTtsModel) {
const modelValid = availableModelsForCategory.has(maybeSelectedTtsModel);
if (!modelValid) {
maybeNewModel = Array.from(availableModelsForCategory)[0];
}
}
if (!!maybeNewModel) {
props.setMaybeSelectedTtsModel(maybeNewModel);
}
};
const handleChangeCategory = (level: number, maybeCategoryToken?: string) => {
if (!maybeCategoryToken) {
return true;
}
doChangeCategory(level, maybeCategoryToken);
return true;
};
return (
<div>
<div className="row gx-3 gy-3">
<div className="col-12 col-lg-3 input-icon-search">
<label className="sub-title">
{t("tts.TtsModelListPage.exploreModal.languageLabel")}
</label>
<LanguageOptions
selectedTtsLanguageScope={props.selectedTtsLanguageScope}
setSelectedTtsLanguageScope={props.setSelectedTtsLanguageScope}
/>
</div>
<div className="col-12 col-md-12 col-lg-9 input-icon-search">
<div className="d-flex align-items-start">
<label className="sub-title flex-grow-1">
{t("tts.TtsModelListPage.exploreModal.categoryLabel")}
</label>
<button
className="ms-3 fw-medium btn-link"
onClick={() => {
handleChangeCategory(0, "*");
}}
type="button"
>
<FontAwesomeIcon icon={faEraser} className="me-2" />
{t("tts.TtsModelListPage.exploreModal.clearCategoryFilterButton")}
</button>
</div>
<CategoryOptions
allTtsCategories={props.allTtsCategories}
allTtsModels={props.allTtsModels}
allTtsCategoriesByTokenMap={props.allTtsCategoriesByTokenMap}
allTtsModelsByTokenMap={props.allTtsModelsByTokenMap}
ttsModelsByCategoryToken={props.ttsModelsByCategoryToken}
dropdownCategories={props.dropdownCategories}
setDropdownCategories={props.setDropdownCategories}
selectedCategories={props.selectedCategories}
setSelectedCategories={props.setSelectedCategories}
maybeSelectedTtsModel={props.maybeSelectedTtsModel}
setMaybeSelectedTtsModel={props.setMaybeSelectedTtsModel}
handleChangeCategory={handleChangeCategory}
selectedTtsLanguageScope={props.selectedTtsLanguageScope}
/>
</div>
</div>
</div>
);
}
@@ -1,5 +1,4 @@
import React from "react";
import { Trans } from "react-i18next";
import { TtsModelListItem } from "@storyteller/components/src/api/tts/ListTtsModels";
import { TtsCategoryType } from "../../../../../../AppWrapper";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";