Skip to content
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

feat: add interval refresh on the sks people counter #415

Merged

Conversation

thesun901
Copy link
Contributor

lastest_sks_user_data_repo.dart: add interval refresh
sks_user_data.dart: refactor model attributes to match API responses

@mikolaj-jalocha
Copy link
Member

@tomasz-trela if u have enought time, pls perform a review and ping me when done, I will check it out as well ;)

@mikolaj-jalocha mikolaj-jalocha added the enhancement New feature or request label Nov 20, 2024
@mikolaj-jalocha mikolaj-jalocha linked an issue Nov 20, 2024 that may be closed by this pull request
Copy link
Member

@tomasz-trela tomasz-trela left a comment

Choose a reason for hiding this comment

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

Everything looks good besides code duplication. Right now I can't test if it is working, but code looks good.

Comment on lines 9 to 18
extension RefIntervalRefreshX on Ref {
void setRefresh(Duration interval) {
final timer = Timer.periodic(
interval,
(t) => invalidateSelf(),
);
onDispose(timer.cancel);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

We have this part of code in file parkings_repository.dart so my idea is to move this to separate file(like ref_extesions.dart) in utils folder and use it in 2 places.

Copy link
Contributor Author

@thesun901 thesun901 Nov 20, 2024

Choose a reason for hiding this comment

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

Sure thing! I can take care of refactorization. By the way - to test code it is nessesary to add SksAppBar somewhere. It wasn't placed anywhere before so I left it as it was.

Copy link
Member

Choose a reason for hiding this comment

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

You can add it at app bar at main screen (for testing purposes)

Copy link
Member

Choose a reason for hiding this comment

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

good catch Tomuś

@tomasz-trela
Copy link
Member

@mikolaj-jalocha

Copy link
Member

@mikolaj-jalocha mikolaj-jalocha left a comment

Choose a reason for hiding this comment

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

Good Work! Nice use of properly named extension! Minor adjustment of mine and one declared by Tomek

final currentTime = DateTime.now();
final sksRefreshInterval = sksData.isResultRecent
? sksData.nextUpdateTimestamp.difference(currentTime)
: const Duration(minutes: 1);
Copy link
Member

@mikolaj-jalocha mikolaj-jalocha Nov 20, 2024

Choose a reason for hiding this comment

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

Please extract it to some const, eg. in config (duration time)

return SksUserData.fromJson(response.data as Map<String, dynamic>);
final sksData = SksUserData.fromJson(response.data as Map<String, dynamic>);

final currentTime = DateTime.now();
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion, please check DateTimeUtils. In mentioned file Simon created handy extension now. Maybe it'll suit you here as well

Copy link
Member

Choose a reason for hiding this comment

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

tbh this can stays as it is (imo)

Copy link
Member

Choose a reason for hiding this comment

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

I agree, placed it here as fun fact lets say

Copy link
Member

@simon-the-shark simon-the-shark left a comment

Choose a reason for hiding this comment

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

good job guys

Comment on lines 9 to 18
extension RefIntervalRefreshX on Ref {
void setRefresh(Duration interval) {
final timer = Timer.periodic(
interval,
(t) => invalidateSelf(),
);
onDispose(timer.cancel);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

good catch Tomuś

return SksUserData.fromJson(response.data as Map<String, dynamic>);
final sksData = SksUserData.fromJson(response.data as Map<String, dynamic>);

final currentTime = DateTime.now();
Copy link
Member

Choose a reason for hiding this comment

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

tbh this can stays as it is (imo)

add files: sks_people_live_consts.dart
ref_extensions.dart

change files:
home_viev.dart: add SksAppBar to AppBar

parkings_repository.dart, latest_sks_user_data_repository.dart: refactor code
Copy link
Member

@mikolaj-jalocha mikolaj-jalocha left a comment

Choose a reason for hiding this comment

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

LGTM!

@mikolaj-jalocha mikolaj-jalocha merged commit 0f3599b into main Nov 20, 2024
2 checks passed
@mikolaj-jalocha mikolaj-jalocha deleted the feat/add-interval-refresh-on-the-sks-people-counter branch November 20, 2024 19:00
simon-the-shark pushed a commit that referenced this pull request Nov 21, 2024
* feat: add interval refresh on the sks people counter

* refactor: add separate files for refresh on ref and consts

add files: sks_people_live_consts.dart
ref_extensions.dart

change files:
home_viev.dart: add SksAppBar to AppBar

parkings_repository.dart, latest_sks_user_data_repository.dart: refactor code

* refactor: delete unused imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

feat/ add interval refresh on the sks people counter
4 participants