Skip to content

Commit 1815d39

Browse files
committed
clean up
1 parent 99e0222 commit 1815d39

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

app/src/features/detail/components/PackageSidebar.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,21 @@ interface PackageSidebarProps {
3333

3434
const PackageSidebar = ({ data, loading, error }: PackageSidebarProps) => {
3535
const router = useRouter();
36-
const [docsRelativeUrl, setDocsRelativeUrl] = React.useState<string>("");
37-
const [docsLinkLabel, setDocsLinkLabel] = React.useState<string>("");
36+
const docsRelativeUrl =
37+
data?.docsIpfsUrl && data.name && data.version
38+
? `/docs/${encodeURIComponent(data.name)}/${encodeURIComponent(data.version)}`
39+
: "";
3840

39-
React.useEffect(() => {
40-
if (!data?.docsIpfsUrl) {
41-
setDocsRelativeUrl("");
42-
setDocsLinkLabel("");
43-
return;
44-
}
41+
const docsOrigin =
42+
(typeof window !== "undefined" && window.location?.origin) ||
43+
process.env.NEXT_PUBLIC_APP_ORIGIN ||
44+
"";
4545

46-
const relativePath = `/docs/${encodeURIComponent(data.name)}/${encodeURIComponent(data.version)}`;
47-
setDocsRelativeUrl(relativePath);
48-
49-
const configuredOrigin = process.env.NEXT_PUBLIC_APP_ORIGIN ?? "";
50-
51-
if (typeof window !== "undefined" && window.location?.origin) {
52-
setDocsLinkLabel(`${window.location.origin}${relativePath}`);
53-
} else if (configuredOrigin) {
54-
setDocsLinkLabel(`${configuredOrigin}${relativePath}`);
55-
} else {
56-
setDocsLinkLabel(relativePath);
57-
}
58-
}, [data?.docsIpfsUrl, data?.name, data?.version]);
46+
const docsLinkLabel = docsRelativeUrl
47+
? docsOrigin
48+
? `${docsOrigin}${docsRelativeUrl}`
49+
: docsRelativeUrl
50+
: "";
5951

6052
if (loading) {
6153
return (

0 commit comments

Comments
 (0)