Skip to content

Commit

Permalink
#270 : make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermau committed Feb 19, 2025
1 parent 21e766c commit fca5f5a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions web/src/ui/pages/softwareDetails/HeaderDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const HeaderDetailCard = memo((props: Props) => {
handleClose={
handlePopoverClose
}
></AuthorCard>
/>
</Popover>
</>
)}
Expand Down Expand Up @@ -225,7 +225,7 @@ export const HeaderDetailCard = memo((props: Props) => {
priority="secondary"
url={officialWebsite}
label={t("headerDetailCard.website")}
></LogoURLButton>
/>
)}
{documentationWebsite && (
<LogoURLButton
Expand All @@ -234,7 +234,7 @@ export const HeaderDetailCard = memo((props: Props) => {
priority="secondary"
url={documentationWebsite}
label={t("headerDetailCard.documentation")}
></LogoURLButton>
/>
)}
{sourceCodeRepository && (
<LogoURLButton
Expand All @@ -243,7 +243,7 @@ export const HeaderDetailCard = memo((props: Props) => {
priority="secondary"
url={sourceCodeRepository}
label={t("headerDetailCard.repository")}
></LogoURLButton>
/>
)}
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions web/src/ui/pages/softwareDetails/PreviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export const PreviewTab = (props: Props) => {
<SoftwareTypeTable
title="Test"
softwareType={softwareType}
></SoftwareTypeTable>
/>
)}
</p>
)}
Expand All @@ -363,15 +363,15 @@ export const PreviewTab = (props: Props) => {
priority="secondary"
url={comptoireDuLibreUrl}
label={t("previewTab.comptoire du libre sheet")}
></LogoURLButton>
/>
)}
{wikiDataUrl !== undefined && (
<LogoURLButton
className={cx(classes.externalLink, classes.item)}
priority="secondary"
url={wikiDataUrl}
label={t("previewTab.wikiData sheet")}
></LogoURLButton>
/>
)}
</>
)}
Expand All @@ -383,7 +383,7 @@ export const PreviewTab = (props: Props) => {
priority="secondary"
url={identifier.url}
labelFromURL={true}
></LogoURLButton>
/>
))}
</>
)}
Expand Down
27 changes: 17 additions & 10 deletions web/src/ui/shared/LogoURLButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,23 @@ export function LogoURLButton(props: Props) {

const { classes } = useStyles();

const { URLlogo, textFromURL } = type
? resolveLogoFromType(type)
: url
? resolveLogoFromURL(url)
: {
URLlogo: undefined,
textFromURL: undefined
};

const resolvedLabel = label ? label : labelFromURL ? textFromURL ?? "" : "";
const getUrlMetadata = () => {
if (type) return resolveLogoFromType(type);
if (url) return resolveLogoFromURL(url);
return {
URLlogo: undefined,
textFromURL: undefined
};
};

const { URLlogo, textFromURL } = getUrlMetadata();

const getLabel = () => {
if (label) return label;
if (labelFromURL) return textFromURL;
return "";
};
const resolvedLabel = getLabel();

return (
<Button
Expand Down

0 comments on commit fca5f5a

Please sign in to comment.