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

fix hyphen issue for sync and controller code #1725

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

yadvirkaur
Copy link
Collaborator

@yadvirkaur yadvirkaur commented Jul 24, 2024

  • Passed sanity tests.
  • Ran npm test & fixed newly introduced lint errors.
  • Checked console for errors.

#1111

@yadvirkaur yadvirkaur requested a review from gurjit03 July 24, 2024 07:08
Copy link
Collaborator

@gurjit03 gurjit03 left a comment

Choose a reason for hiding this comment

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

Great work @yadvirkaur ji 🔥. Can you please resolve the below comments and also please add a unit test for this function and/or component.
And one more request please whenever you work/touch a file lets convert it to Typescript immediately to get better type support and enhance DX.
https://github.com/KhalisFoundation/sttm-web/blob/dev/CONTRIBUTING.md

@@ -274,26 +273,18 @@ export default class WebControllerPage extends React.PureComponent {
pattern="[A-Z,a-z]{3}-[A-Z,a-z]{3}"
onKeyUp={e => {
const typedValue = e.currentTarget.value;
if (isMobile) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@yadvirkaur I can see there is difference in the logic in Mobile and Desktop. Is it something reconsidered now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously:

For the Bani Controller:

  • Mobile Devices: The code checked if the user had typed four characters without a hyphen and then inserted a hyphen after the third character.

  • Other Devices: The code added a hyphen automatically after the third character.

For Sangat Sync:

The code for all devices added a hyphen automatically after the third character.

Now:
I've now unified the logic for the Bani Controller to ensure consistent behaviour across all devices. The code now adds a hyphen automatically after the third character for all devices and ensures that no extra hyphens are added.

Copy link
Collaborator

@gurjit03 gurjit03 Jul 25, 2024

Choose a reason for hiding this comment

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

@yadvirkaur cool, thanks for the explainations, I totally got it. It's just I am unaware of these changes, if these are the changes requested lets do it. Also I would add, lets please make sure all these changes are mentioned in the ticket too, easier to review and followup.
Otherwise I would request to kindly confirm, as I am sure there might be good reason for this seperation.

Copy link
Collaborator Author

@yadvirkaur yadvirkaur Jul 25, 2024

Choose a reason for hiding this comment

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

@gurjit03 hnji veerji!
The mobile-specific logic for the Bani controller is fine as it is since it adds a hyphen after 4 characters only if the user hasn't already added one, so no risk of double hyphens there.

However, this can cause confusion between the Bani Controller and Sangat Sync since they handle hyphens differently for mobile devices.

@saintsoldierx @Gauravjeetsingh veerji please confirm if we need separation of logic or if we can have a unified logic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't remember the reason for separate logic, but if its working with the unified logic, let's keep that. Realistically it makes sense to have same logic for both mobile and desktop browsers.

if (isParsedValueExist && typedChar !== 'Backspace') {
e.currentTarget.value = typedValue + '-';
} else if (typedChar === '-' && hasHyphen) {
e.currentTarget.value = typedValue.replace(/-+/g, '-');
Copy link
Collaborator

Choose a reason for hiding this comment

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

@yadvirkaur I might be wrong here but we are replacing /-+/g both - and + aint? Or does it represents - n number of times? if so, can you please update implementation a bit to be more clear. It can cause confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The expression (/-+/g, '-') here matches one or more hyphens and replaces them with a single hyphen. It's not related to the + character itself. To make it clearer, I can update it to (/[-]+/g, '-'). Let me know if that works!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@yadvirkaur yes that works perfectly fine

@yadvirkaur yadvirkaur merged commit c082f0f into KhalisFoundation:dev Aug 21, 2024
1 check passed
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