Skip to content

Commit

Permalink
dynamic mapping for nmt
Browse files Browse the repository at this point in the history
  • Loading branch information
srihari07-web committed Sep 13, 2024
1 parent 38b643d commit 67b1e89
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions frontend/components/TryOut/NMT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ interface LanguageCodeNames {
}

export default function NMT({ services }: { services: any }) {
const languageOptions = Object.entries(services).flatMap(([serviceId, serviceData]) =>
serviceData.languageFilters.sourceLanguages.map((language: string) => ({
serviceId,
language,
label: (LANGUAGE_CODE_NAMES as LanguageCodeNames)[language],
}))
const languageOptions = Object.entries(services).flatMap(
([serviceId, serviceData]) =>
(serviceData as any).languageFilters.sourceLanguages.map(
(language: string) => ({
serviceId,
language,
label: (LANGUAGE_CODE_NAMES as LanguageCodeNames)[language],
})
)
);

const [service, setService] = useState(languageOptions[0].serviceId);
Expand All @@ -70,7 +73,9 @@ export default function NMT({ services }: { services: any }) {

const toast = useToast();

const handleLanguageChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const handleLanguageChange = (
event: React.ChangeEvent<HTMLSelectElement>
) => {
const selectedLanguage = event.target.value;
const selectedOption = languageOptions.find(
(option) => option.language === selectedLanguage
Expand Down Expand Up @@ -178,7 +183,8 @@ export default function NMT({ services }: { services: any }) {
setOutputText("");
toast({
title: "Warning",
description: "You have reached maximum trials in a minute",
description:
"You have reached maximum trials in a minute",
status: "warning",
duration: 4000,
isClosable: true,
Expand All @@ -188,7 +194,8 @@ export default function NMT({ services }: { services: any }) {
setOutputText("");
toast({
title: "Warning",
description: "Service Currently Unavailable, Please Try Again Later",
description:
"Service Currently Unavailable, Please Try Again Later",
status: "warning",
duration: 4000,
isClosable: true,
Expand All @@ -200,7 +207,8 @@ export default function NMT({ services }: { services: any }) {
setOutputText("");
toast({
title: "Warning",
description: "Service Currently Unavailable, Please Try Again Later",
description:
"Service Currently Unavailable, Please Try Again Later",
status: "warning",
duration: 4000,
isClosable: true,
Expand Down

0 comments on commit 67b1e89

Please sign in to comment.