Skip to content

Commit

Permalink
Fix incorrect selectedSlugFromUrl (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kafkas authored Aug 1, 2023
1 parent 4a1b76d commit 3a56732
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/ui/app/src/docs-context/DocsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ export const DocsContextProvider: React.FC<DocsContextProvider.Props> = ({

const rootSlug = activeVersion ?? "";

const getFullSlug = useCallback((slug: string) => `${rootSlug ? `${rootSlug}/` : ""}${slug}`, [rootSlug]);

const selectedSlugFromUrl = useMemo(() => {
switch (resolvedUrlPath.type) {
case "clientLibraries":
case "endpoint":
case "mdx-page":
case "topLevelEndpoint":
case "apiSubpackage":
return `${rootSlug}/${resolvedUrlPath.slug}`;
return getFullSlug(resolvedUrlPath.slug);
case "api":
case "section":
return undefined;
default:
assertNever(resolvedUrlPath);
}
}, [rootSlug, resolvedUrlPath]);
}, [resolvedUrlPath, getFullSlug]);

const [selectedSlug, setSelectedSlug] = useState(selectedSlugFromUrl);

Expand Down Expand Up @@ -83,8 +85,6 @@ export const DocsContextProvider: React.FC<DocsContextProvider.Props> = ({
_setActiveVersion(version);
}, []);

const getFullSlug = useCallback((slug: string) => `${rootSlug ? `${rootSlug}/` : ""}${slug}`, [rootSlug]);

useEffect(() => {
if (selectedSlug == null) {
setSelectedSlug(selectedSlugFromUrl);
Expand Down

0 comments on commit 3a56732

Please sign in to comment.