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

feature: add new filter to bulding search #107

Merged
merged 3 commits into from
Jun 26, 2024
Merged

feature: add new filter to bulding search #107

merged 3 commits into from
Jun 26, 2024

Conversation

kamilfedio
Copy link
Member

#97
I added the filters mentioned and improve graphql&model of bulidings

@kamilfedio kamilfedio self-assigned this Jun 22, 2024
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 work. I have one proposition of a simple refactor.

(item.addres?.toLowerCase().contains(filterStr) ?? false) ||
(item.naturalName?.toLowerCase().contains(filterStr) ?? false) ||
(!filterStr.contains('-')
? item.name.toLowerCase().replaceAll('-', '').contains(filterStr)
Copy link
Member

Choose a reason for hiding this comment

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

it stopped being easily readable at this point and I would strongly recomend some refactor to divide this into smaller logically separated pieces.

so you can do this in many ways, but my personal proposition would be:

in map view config file

abstract class BuildingSearchConfig {
  static const buildingCodeSeparator = "-";
}

then create util file, example location: lib\features\buildings_map\utils.dart

extension ContainsCaseUnsensitive on String? {
  bool containsUnsensitive(String str) {
    if (this == null) return false;
    return this!.toLowerCase().contains(str.toLowerCase());
  }

bool containsBuildingCode(String buildingCode) {
    if (buildingCode.contains(BuildingSearchConfig.buildingCodeSeparator)) {
      return containsUnsensitive(buildingCode);
    }
    return this
            ?.replaceAll(BuildingSearchConfig.buildingCodeSeparator, "")
            .containsUnsensitive(buildingCode) ??
        false;
  }
}

and the usage would be:

  @override
  bool filterMethod(BuildingModel item, String filterStr) {
    return item.name.containsBuildingCode(filterStr) ||
        item.addres.containsUnsensitive(filterStr) ||
        item.naturalName.containsUnsensitive(filterStr);
  }

it's just a proposition, you can refactor it in some other way you find suitable. Also I hope I haven't broken the logic :)

@kamilfedio
Copy link
Member Author

@simon-the-shark Okay, I used your idea

@simon-the-shark
Copy link
Member

You can merge :)

@kamilfedio kamilfedio merged commit c5bf5cd into main Jun 26, 2024
@kamilfedio kamilfedio deleted the MOBILE-51 branch June 26, 2024 22:43
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.

None yet

2 participants