Skip to content

[CT-3468] - bb/package-count #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2022
Merged

[CT-3468] - bb/package-count #115

merged 1 commit into from
Jun 24, 2022

Conversation

ben-brooker
Copy link
Contributor

@ben-brooker ben-brooker commented Jun 23, 2022

  • Integrated total package count onto landing page UI
  • Fetch uses method: HEAD to only fetch the headers (more efficient).
  • Before:

Screenshot 2022-06-23 at 11 59 07

-After:

Screenshot 2022-06-24 at 17 32 59

@filipsch
Copy link

filipsch commented Jun 23, 2022

  • Add "all" in front of the number
  • Don't make the number of packages bold

pages/index.tsx Outdated
const [searchInput, setSearchInput] = useState('');
const router = useRouter();

let packageCountFormat = packageCount==="all" ? " ": "font-bold"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this, we don't need it to be bold 👍

pages/index.tsx Outdated
Comment on lines 49 to 56
//to prevent the case where site crashes due to error response
if (!response || response.status!==200) {
return {
props: {
packageCount: "all"
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this, if it errors, it will simply not have a packageCount

pages/index.tsx Outdated
Search all R packages on CRAN and Bioconductor
</h1>
<div className="text-xl md:text-2xl lg:text-3xl">
Search <span className={packageCountFormat}>{packageCount}</span> R packages on CRAN and Bioconductor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packageCount should be number, that will be simpler for typing, in this case you want to add some logic to have all and then the number if it exists 🤝

pages/index.tsx Outdated

export default function HomePage() {
export default function HomePage({ packageCount }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to add the type of props, you can just do it inline here since it's only 1 prop

Suggested change
export default function HomePage({ packageCount }) {
export default function HomePage({ packageCount }: { packageCount?: number }) {

pages/index.tsx Outdated
Comment on lines 54 to 58
return {
props: {
packageCount: packageCount || ''
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a default value here since packageCount gets initialized either through the response or with null in the catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for info, if you set a default ``, then packageCount type becomes number | stringso better not do that 😅

pages/index.tsx Outdated
return {
notFound: true,
};
packageCount = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you defined the type in the component to be { packageCount?: number } (it's an optional props), you can set a default value to undefined, this way the prop will be ignored

Copy link
Contributor Author

@ben-brooker ben-brooker Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify this? When I set a packageCount to undefined it throws an JSON not serializable error

Copy link
Contributor

@ztsorojev ztsorojev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you format the number to add , (separate the thousands)?
It will make it easier to read 🤝

image

Search all R packages on CRAN and Bioconductor
</h1>
<div className="text-xl md:text-2xl lg:text-3xl">
{`Search all ${packageCount > 0 ? `${packageCount.toLocaleString(undefined, {maximumFractionDigits:0})}`:''} R packages on CRAN and Bioconductor`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to turn this into a utility function that can be reused 👌

Copy link
Contributor

@ztsorojev ztsorojev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@ztsorojev ztsorojev merged commit bbbeee8 into main Jun 24, 2022
@ztsorojev ztsorojev deleted the bb/package-count branch June 24, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants