-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Added shortcut to today's date in Fresh Releases using a Calendar Ico… #3125
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks for working on this it will improve the page straight away!
<FontAwesomeIcon | ||
icon={faCalendarCheck} | ||
size="2xl" | ||
style={{ color: "#353070" }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a constant COLOR_LB_BLUE
, which you can import from frontend/js/src/utils/constants.ts
Also you can directly use the color
prop instead of style:
color={COLOR_LB_BLUE}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion
Made the necessary changes, thanks for the suggestion |
const today = new Date(); | ||
const todayString = today.toISOString().split("T")[0]; | ||
const formattedTodayString = formatReleaseDate(todayString); | ||
const filteredDates = Object.keys(releasesPerDate).filter((date) => | ||
date !== todayString | ||
? releasesPerDate[date] >= minReleasesThreshold | ||
: releasesPerDate[date] > 0 | ||
); | ||
|
||
dataArr = filteredDates.map((item) => formatReleaseDate(item)); | ||
dataArr = filteredDates.map((item) => | ||
formatReleaseDate(item) === formattedTodayString ? ( | ||
<FontAwesomeIcon | ||
icon={faCalendarCheck} | ||
size="2xl" | ||
color={COLOR_LB_BLUE} | ||
/> | ||
) : ( | ||
formatReleaseDate(item) | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had another read through the code and I figured we can simplify this quite a lot thanks to a utility function from the date-fns library that we use in LB:
https://date-fns.org/v4.1.0/docs/isToday
From testing in the console on their website, it should be as simple as doing:
and removing today, todayString and formattedTodayString.
Of course you'll need to import { isToday } from "date-fns";
const filteredDates = Object.keys(releasesPerDate).filter((date) =>
!isToday(new Date(date))
? releasesPerDate[date] >= minReleasesThreshold
: releasesPerDate[date] > 0
);
dataArr = filteredDates.map((item) =>
isToday(new Date(item)) ? (
<FontAwesomeIcon
icon={faCalendarCheck}
size="2xl"
color={COLOR_LB_BLUE}
/>
) : (
formatReleaseDate(item)
)
);
@@ -15,7 +18,7 @@ function createMarks( | |||
sortDirection: string, | |||
order: string | |||
) { | |||
let dataArr: Array<string> = []; | |||
let dataArr: Array<React.ReactNode> = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be more appropriate:
let dataArr: Array<React.ReactNode> = []; | |
let dataArr: Array<string | JSX.Element> = []; |
Problem
LB-1528: Add shortcut to today's date in Fresh Releases
Solution
Added a calendar icon in the datewise scroll bar as a ticker to directly refer to today's date.
Action