Skip to content

Commit

Permalink
Review fixes :)
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-sierzega committed Sep 29, 2023
1 parent 8b7d820 commit 9ffecde
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/app/jest.coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"branches": 67.71
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { FunctionComponent } from "App/__deprecated__/renderer/types/function-co
import { noop } from "App/__deprecated__/renderer/utils/noop"
import React, { useEffect, useState } from "react"
import { useSelector } from "react-redux"
import { filterContacts } from "App/messages/helpers/messages.helpers"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name"
import { filterContacts } from "App/contacts/helpers/filter-contacts/filter-contacts"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name-ascending"

export const ContactSelectModal: FunctionComponent<
ContactsSelectModalProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { applyValidationRulesToImportedContacts } from "App/contacts/helpers/app
import { ExportContactsResult } from "App/contacts/constants"
import DeleteContactsPopup from "./delete-contacts-popup/delete-contacts-popup.component"
import { differenceWith, isEqual } from "lodash"
import { filterContacts } from "App/messages/helpers/messages.helpers"
import { filterContacts } from "App/contacts/helpers/filter-contacts/filter-contacts"

const allPossibleFormErrorCausedByAPI: FormError[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { Contact } from "App/contacts/reducers/contacts.interface"
import { filterRecordsByPhrase } from "App/utils/filter-records-by-phrase"
import { checkFullName } from "App/utils/check-full-name"

export const filterContacts = (
contacts: Contact[],
searchPhrase: string
): Contact[] => {
const filteredResult = filterRecordsByPhrase(
contacts,
searchPhrase,
["firstName", "lastName", "primaryPhoneNumber", "secondaryPhoneNumber"],
[checkFullName]
)

return filteredResult
}
2 changes: 1 addition & 1 deletion packages/app/src/contacts/selectors/contacts.selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "App/contacts/reducers/contacts.interface"
import { contactsStateSelector } from "App/contacts/selectors/contacts-state.selector"
import { getContacts } from "App/contacts/helpers/contacts.helpers"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name-ascending"

export const contactsSelector = createSelector<
ReduxRootState,
Expand Down
28 changes: 1 addition & 27 deletions packages/app/src/messages/helpers/messages.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Contact } from "App/contacts/reducers/contacts.interface"
import { TextEncoder } from "util"
import { Receiver } from "App/messages/reducers/messages.interface"
import { filterRecordsByPhrase } from "App/utils/filter-records-by-phrase"
import { checkFullName } from "App/utils/check-full-name"

export type ContactsCollection = Record<string, Contact>
export type Getter = (
Expand Down Expand Up @@ -70,33 +71,6 @@ export const getStringSizeInBytes = (content: string) => {
return new TextEncoder().encode(content).length
}

const checkFullName = <T extends { firstName?: string; lastName?: string }>(
{ firstName, lastName }: T,
searchPhrase: string
) => {
if (firstName && lastName) {
const fullName = `${firstName} ${lastName}`.trim().toLowerCase()
if (fullName.includes(searchPhrase)) {
return true
}
}
return false
}

export const filterContacts = (
contacts: Contact[],
searchPhrase: string
): Contact[] => {
const filteredResult = filterRecordsByPhrase(
contacts,
searchPhrase,
["firstName", "lastName", "primaryPhoneNumber", "secondaryPhoneNumber"],
[checkFullName]
)

return filteredResult
}

export const filterReceivers = (
receivers: Receiver[],
searchPhrase: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mapThreadsToReceivers,
} from "App/messages/helpers/threads.helpers"
import { isContactMatchingPhoneNumber } from "App/contacts/helpers/is-contact-matching-phone-number/is-contact-matching-phone-number"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name-ascending"

export const getReceiversSelector = createSelector<
RootState & ReduxRootState,
Expand Down
19 changes: 19 additions & 0 deletions packages/app/src/utils/check-full-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export const checkFullName = <
T extends { firstName?: string; lastName?: string }
>(
{ firstName, lastName }: T,
searchPhrase: string
): boolean => {
if (firstName && lastName) {
const fullName = `${firstName} ${lastName}`.trim().toLowerCase()
if (fullName.includes(searchPhrase)) {
return true
}
}
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { sortByLastNameAscending } from "App/utils/sort-by-last-name"
import { sortByLastNameAscending } from "App/utils/sort-by-last-name-ascending"

const people = [
{ name: "John", lastName: "Januszkowski" },
Expand Down
File renamed without changes.

0 comments on commit 9ffecde

Please sign in to comment.