Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
christinaroise committed Sep 25, 2024
1 parent 80741ed commit f3905e9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions studio/components/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ const LanguageSelector = ({
const handleLanguageSelection = (lang: Language, isSelected: boolean) => {
let updatedValue: Language[];

// Handle deselection of a language
if (isSelected) {
// Remove the deselected language from the current value
// Deselect the language
updatedValue = value.filter((item) => item.id !== lang.id);

// If the deselected language is the current default
Expand All @@ -44,14 +43,15 @@ const LanguageSelector = ({
(language) => language.id === lang.id,
);

// Attempt to find the next selected language after the deselected one
// Get the next selected language in the supportedLanguages order
const nextDefaultLanguage =
supportedLanguages
.slice(indexInSupported + 1) // Get languages after the deselected one
.find((language) =>
updatedValue.some((item) => item.id === language.id),
) || updatedValue[0]; // Fallback to the first selected language if none found

// Set the new default if there's a next selected language
updatedValue = updatedValue.map((item) => ({
...item,
default: item.id === nextDefaultLanguage.id,
Expand Down

0 comments on commit f3905e9

Please sign in to comment.