From 14ff1ee1b22c77d166d6d1495ba7b98f9be9d547 Mon Sep 17 00:00:00 2001 From: WaDadidou <50441633+WaDadidou@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:07:09 -0500 Subject: [PATCH] feat(launchpad): add pluralize lib (#1334) * feat: enhance pluralOrNot function * chore: use library to handle plural strings --- package.json | 2 ++ .../FileUploaderSmall/FileUploaderSmall.web.tsx | 5 ++--- .../FeedNewArticle/FeedNewArticleScreen.tsx | 4 ++-- packages/utils/text.tsx | 3 --- yarn.lock | 16 ++++++++++++++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 05078338ab..73a2363631 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "@types/leaflet": "^1.9.12", "@types/leaflet.markercluster": "^1.5.4", "@types/papaparse": "^5.3.14", + "@types/pluralize": "^0.0.33", "assert": "^2.1.0", "axios": "^1.6.2", "bech32": "^2.0.0", @@ -126,6 +127,7 @@ "osmojs": "16.9.0", "papaparse": "^5.4.1", "plausible-tracker": "^0.3.8", + "pluralize": "^8.0.0", "protobufjs": "^7.2.5", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/packages/components/inputs/FileUploaderSmall/FileUploaderSmall.web.tsx b/packages/components/inputs/FileUploaderSmall/FileUploaderSmall.web.tsx index 6cda44ab67..29288413be 100644 --- a/packages/components/inputs/FileUploaderSmall/FileUploaderSmall.web.tsx +++ b/packages/components/inputs/FileUploaderSmall/FileUploaderSmall.web.tsx @@ -1,3 +1,4 @@ +import pluralize from "pluralize"; import React, { forwardRef, SyntheticEvent, @@ -27,7 +28,6 @@ import { DeleteButton } from "@/components/FilePreview/DeleteButton"; import { OptimizedImage } from "@/components/OptimizedImage"; import { CustomPressable } from "@/components/buttons/CustomPressable"; import { SpacerRow } from "@/components/spacer"; -import { pluralOrNot } from "@/utils/text"; import { LocalFileData } from "@/utils/types/files"; export const FileUploaderSmall = forwardRef< @@ -193,8 +193,7 @@ export const FileUploaderSmall = forwardRef< : !multiple && !filesCount ? "Select file" : multiple && filesCount - ? filesCount + - ` ${pluralOrNot("file", filesCount)} selected` + ? `${pluralize("file", filesCount, true)} selected` : multiple && !filesCount ? "Select files" : ""} diff --git a/packages/screens/FeedNewArticle/FeedNewArticleScreen.tsx b/packages/screens/FeedNewArticle/FeedNewArticleScreen.tsx index c7e5e8dc04..2b82e3faa4 100644 --- a/packages/screens/FeedNewArticle/FeedNewArticleScreen.tsx +++ b/packages/screens/FeedNewArticle/FeedNewArticleScreen.tsx @@ -1,3 +1,4 @@ +import pluralize from "pluralize"; import React, { useEffect, useRef, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { ScrollView, View } from "react-native"; @@ -45,7 +46,6 @@ import { } from "@/utils/style/colors"; import { fontSemibold13, fontSemibold20 } from "@/utils/style/fonts"; import { layout, screenContentMaxWidth } from "@/utils/style/layout"; -import { pluralOrNot } from "@/utils/text"; import { CustomLatLngExpression, NewArticleFormValues, @@ -291,7 +291,7 @@ export const FeedNewArticleScreen: ScreenFC<"FeedNewArticle"> = () => { ]} > {freePostCount - ? `You have ${freePostCount} free ${pluralOrNot( + ? `You have ${freePostCount} free ${pluralize( "Article", freePostCount, )} left` diff --git a/packages/utils/text.tsx b/packages/utils/text.tsx index 8b9ceaaf63..2ecc03bcee 100644 --- a/packages/utils/text.tsx +++ b/packages/utils/text.tsx @@ -32,6 +32,3 @@ export const replaceBetweenString = ( insertion: string, ) => `${origin.substring(0, startIndex)}${insertion}${origin.substring(endIndex)}`; - -export const pluralOrNot = (word: string, quantity: number) => - quantity > 1 ? word + "s" : word; diff --git a/yarn.lock b/yarn.lock index 7b057ed53d..764cde2450 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6878,6 +6878,13 @@ __metadata: languageName: node linkType: hard +"@types/pluralize@npm:^0.0.33": + version: 0.0.33 + resolution: "@types/pluralize@npm:0.0.33" + checksum: 282d42dc0187e5e0912f9f36ee0f5615bfd273a08d40afe5bf5881cb28daf1977abe10564543032aa0f42352ebba739ff3d86bf5562ac4691c6d1761fcc7cf39 + languageName: node + linkType: hard + "@types/prettier@npm:^2.6.1": version: 2.7.3 resolution: "@types/prettier@npm:2.7.3" @@ -17023,6 +17030,13 @@ __metadata: languageName: node linkType: hard +"pluralize@npm:^8.0.0": + version: 8.0.0 + resolution: "pluralize@npm:8.0.0" + checksum: 08931d4a6a4a5561a7f94f67a31c17e6632cb21e459ab3ff4f6f629d9a822984cf8afef2311d2005fbea5d7ef26016ebb090db008e2d8bce39d0a9a9d218736e + languageName: node + linkType: hard + "pngjs@npm:^3.3.0": version: 3.4.0 resolution: "pngjs@npm:3.4.0" @@ -20213,6 +20227,7 @@ __metadata: "@types/markdown-it": ^13.0.7 "@types/node": ^20.9.1 "@types/papaparse": ^5.3.14 + "@types/pluralize": ^0.0.33 "@types/react": ~18.2.45 "@types/react-native-countdown-component": ^2.7.0 "@types/uuid": ^9.0.0 @@ -20279,6 +20294,7 @@ __metadata: papaparse: ^5.4.1 patch-package: ^7.0.2 plausible-tracker: ^0.3.8 + pluralize: ^8.0.0 postinstall-postinstall: ^2.1.0 prettier: ^3.0.3 protobufjs: ^7.2.5