Skip to content

Commit

Permalink
chore: fixed react hook logic (#2514)
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding authored Mar 29, 2024
1 parent ba4ebcd commit 94eb2ee
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/components/ReleaseNotesVersions/ReleaseNotesVersions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function ReleaseNotesVersions(): JSX.Element | null {
const [selectedVersion, setSelectedVersion] = useState<VersionOption | null>(null);
const history = useHistory();
const isBrowser = useIsBrowser();
const isExternal = isBrowser && isExternalDomain(externalDomainURL, isBrowser);

const versionsList = useVersions("default");

Expand All @@ -54,15 +53,11 @@ export function ReleaseNotesVersions(): JSX.Element | null {
...Object.entries(ArchivedVersions).map(([versionName, versionUrl]) => ({
label: `${versionName} `,
value: `${versionName} `,
url: versionUrl,
url: versionUrl + "/release-notes",
isExternal: versionUrl.startsWith("http"),
})),
];

if (isExternal) {
return <></>;
}

useEffect(() => {
const savedVersion = localStorage.getItem("selectedVersion");
if (savedVersion) {
Expand All @@ -73,6 +68,8 @@ export function ReleaseNotesVersions(): JSX.Element | null {
}
}, [selectedVersion?.value]);

const isExternal = isBrowser && isExternalDomain(externalDomainURL, isBrowser);

const handleVersionChange = (selectedOption: VersionOption | null) => {
setSelectedVersion(selectedOption);
localStorage.setItem("selectedVersion", selectedOption?.value ?? "");
Expand Down Expand Up @@ -112,24 +109,28 @@ export function ReleaseNotesVersions(): JSX.Element | null {
}),
};

return (
<Admonition type="tip">
<p>
Are you looking for the release notes to a specific version of Palette? Use the version selector below to
navigate to the release notes of the desired version.
</p>
<div className={styles.dropdownContainer}>
<Select
classNamePrefix="reactSelect"
onChange={handleVersionChange}
value={selectedVersion}
options={versions}
components={{ Option: CustomOption }}
styles={customSelectStyles}
/>
</div>
</Admonition>
);
if (isExternal) {
return null;
} else {
return (
<Admonition type="tip">
<p>
Are you looking for the release notes to a specific version of Palette? Use the version selector below to
navigate to the release notes of the desired version.
</p>
<div className={styles.dropdownContainer}>
<Select
classNamePrefix="reactSelect"
onChange={handleVersionChange}
value={selectedVersion}
options={versions}
components={{ Option: CustomOption }}
styles={customSelectStyles}
/>
</div>
</Admonition>
);
}
}

//isExternalDomain checks if the url is external
Expand Down

0 comments on commit 94eb2ee

Please sign in to comment.