-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(FlipClock): add ShowYear parameter #6224
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
Conversation
Reviewer's GuideThis PR adds a new ShowYear option to the FlipClock component—enabling optional rendering and animation of the year digits—and refactors the JavaScript timing logic into a generic unit configuration. It also updates the Razor component, sample page, localization, and tests to support the new parameter. Sequence Diagram for Refactored JavaScript Clock LogicsequenceDiagram
participant Timer
participant go()
participant getDate()
participant getConfig()
participant setDigits()
Timer->>go(): Executes every second
go()->>getDate(): Get current time data
getDate()-->>go(): Returns {years, months, ...}
go()->>getConfig(): Get unit configurations
getConfig()-->>go(): Returns [{key:'years',...}, {key:'months',...}]
loop For each time unit
go()->>go(): Check if value changed
alt Value has changed
go()->>setDigits(): Update DOM for the unit
end
end
Class Diagram for FlipClock Component ChangesclassDiagram
class FlipClock {
+bool ShowYear
+bool ShowMonth
+bool ShowDay
+bool ShowHour
+bool ShowMinute
+bool ShowSecond
+FlipClockViewMode ViewMode
}
class FlipClocks {
-bool _showYear
-bool _showMonth
-bool _showDay
-bool _showHour
-bool _showMinute
-bool _showSecond
}
FlipClocks --|> FlipClock : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6224 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 704 704
Lines 31105 31113 +8
Branches 4397 4398 +1
=========================================
+ Hits 31105 31113 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- In getDate(), you’re calling new Date() multiple times and always returning the current year in countdown mode—consider using a single Date instance and properly computing a year delta when countDown is true.
- The new ShowYear localization keys (e.g. ShowYear_Description, ShowYearText, ShowYearIntro) don’t appear to be added to en-US.json/zh-CN.json—please include those entries so the sample renders correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In getDate(), you’re calling new Date() multiple times and always returning the current year in countdown mode—consider using a single Date instance and properly computing a year delta when countDown is true.
- The new ShowYear localization keys (e.g. ShowYear_Description, ShowYearText, ShowYearIntro) don’t appear to be added to en-US.json/zh-CN.json—please include those entries so the sample renders correctly.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/FlipClock/FlipClock.razor:8` </location>
<code_context>
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" id="@Id">
+ @if (ShowYear)
+ {
+ <div class="bb-flip-clock-list year">
+ @RenderItem(10)
+ @RenderItem(10)
</code_context>
<issue_to_address>
DRY up repeating @RenderItem calls
Consider replacing the repeated `@RenderItem(10)` lines with a `@for` loop to eliminate duplication and improve maintainability.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
<div class="bb-flip-clock-list year">
@RenderItem(10)
@RenderItem(10)
@RenderItem(10)
@RenderItem(10)
</div>
=======
<div class="bb-flip-clock-list year">
@for (var i = 0; i < 4; i++)
{
@RenderItem(10)
}
</div>
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js:127` </location>
<code_context>
}
}
+const setYear = (list, year, countDown) => {
+ if (list) {
+ list.classList.remove('flip');
</code_context>
<issue_to_address>
Consider refactoring the repeated time unit update logic into a generic helper and loop to reduce duplication and centralize state management.
Here’s one way to collapse the repeated “year/month/day/…” logic into a small generic loop and helper, while only ever calling new Date() once:
```js
// 1) Replace setTime + setYear with a single generic:
const setDigits = (list, value, digits, countDown) => {
if (!list) return;
list.classList.remove('flip');
for (let i = 0; i < digits; i++) {
const place = digits - 1 - i;
const digit = Math.floor(value / 10 ** place) % 10;
setFlip(list.children[i], digit, countDown);
}
list.classList.add('flip');
};
// 2) In your initializer, build a config array and shared last-state:
const unitConfig = [
{ key: 'years', list: el.querySelector('.bb-flip-clock-list.year'), digits: 4 },
{ key: 'months', list: el.querySelector('.bb-flip-clock-list.month'), digits: 2 },
{ key: 'days', list: el.querySelector('.bb-flip-clock-list.day'), digits: 2 },
{ key: 'hours', list: el.querySelector('.bb-flip-clock-list.hour'), digits: 2 },
{ key: 'minutes',list: el.querySelector('.bb-flip-clock-list.minute'), digits: 2 },
{ key: 'seconds',list: el.querySelector('.bb-flip-clock-list.second'), digits: 2 },
];
const lastValues = {}; // will hold lastValues.years, .months, …
// 3) Simplify getDate() to a single Date() call:
const getDate = () => {
if (!countDown && !options.fixed) {
const now = new Date();
return {
years: now.getFullYear(),
months: now.getMonth() + 1,
days: now.getDate(),
hours: now.getHours(),
minutes: now.getMinutes(),
seconds: now.getSeconds()
};
}
// … your existing elapsed / countdown logic returning the same shape …
};
// 4) Collapse go() into one small loop:
const go = () => {
const d = getDate();
unitConfig.forEach(({ key, list, digits }) => {
const v = d[key];
if (lastValues[key] !== v) {
lastValues[key] = v;
setDigits(list, v, digits, countDown);
}
});
return d;
};
```
Benefits:
- No more separate `setYear` vs `setTime`.
- Only one `new Date()` per tick.
- All “lastX” state lives in a single object.
- Adding/removing units (e.g. weeks) is just editing `unitConfig`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@sourcery-ai review |
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.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- It appears the locale files weren’t updated with the new ShowYear and ShowYear_Description keys—please add them to both en-US.json and zh-CN.json.
- Several DemoBlock examples for month/day/hour/minute/second were removed from FlipClocks.razor—please restore them (or confirm the intent) so existing usage demos aren’t lost.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- It appears the locale files weren’t updated with the new ShowYear and ShowYear_Description keys—please add them to both en-US.json and zh-CN.json.
- Several DemoBlock examples for month/day/hour/minute/second were removed from FlipClocks.razor—please restore them (or confirm the intent) so existing usage demos aren’t lost.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #6223
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add support for optionally displaying the year in the FlipClock component by introducing a ShowYear parameter, updating samples and JavaScript logic, and ensuring coverage with a new unit test.
New Features:
Enhancements:
Documentation:
Tests: