Skip to content

Commit

Permalink
Merge pull request #29 from sillsdev/reopen_with_custom_name
Browse files Browse the repository at this point in the history
fix: reopen with custom display name (#29)
  • Loading branch information
andrew-polk authored Nov 1, 2024
2 parents b262bfe + 738f9a4 commit 84564b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export interface ILanguageChooser {
script: IScript | undefined
) => void;
selectUnlistedLanguage: () => void;
resetTo: (initialLanguageTag: string) => void;
resetTo: (
initialLanguageTag: string,
initialCustomDisplayName?: string
) => void;
}

export const useLanguageChooser = (
Expand Down Expand Up @@ -76,7 +79,10 @@ export const useLanguageChooser = (

// For reopening to a specific selection. We should then also set the search string
// such that the selected language is visible.
function resetTo(initialLanguageTag: string) {
function resetTo(
initialLanguageTag: string,
initialCustomDisplayName?: string // all info can be captured in language tag except display name
) {
// clear everything
setSelectedLanguage(undefined);
setSelectedScript(undefined);
Expand All @@ -90,8 +96,11 @@ export const useLanguageChooser = (
onSearchStringChange(initialSelections.language?.languageSubtag || "");
setSelectedLanguage(initialSelections.language);
saveLanguageDetails(
initialSelections.customDetails || ({} as ICustomizableLanguageDetails),
initialSelections.script
{
...initialSelections.customDetails,
displayName: initialCustomDisplayName,
} as ICustomizableLanguageDetails,
initialSelections?.script
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const LanguageChooser: React.FunctionComponent<{
searchString: string
) => ILanguage[];
initialLanguageTag?: string;
initialCustomDisplayName?: string;
onClose: (
languageSelection: IOrthography | undefined,
languageTag: string | undefined
Expand All @@ -59,7 +60,7 @@ export const LanguageChooser: React.FunctionComponent<{
const lp: ILanguageChooser = useLanguageChooser(props.searchResultModifier);

useEffect(() => {
lp.resetTo(props.initialLanguageTag || "");
lp.resetTo(props.initialLanguageTag || "", props.initialCustomDisplayName);
// We only want this to run once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const DialogDemo: React.FunctionComponent<{
<LanguageChooser
searchResultModifier={defaultSearchResultModifier}
initialLanguageTag={languageTag}
initialCustomDisplayName={selectedValue?.customDetails?.displayName}
onClose={handleClose}
rightPanelComponent={
props.demoRightPanelComponent ? (
Expand Down

0 comments on commit 84564b1

Please sign in to comment.