Skip to content

Commit

Permalink
feat(launchpad): add pluralize lib (#1334)
Browse files Browse the repository at this point in the history
* feat: enhance pluralOrNot function

* chore: use library to handle plural strings
  • Loading branch information
WaDadidou authored Nov 5, 2024
1 parent 1dbef31 commit 14ff1ee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pluralize from "pluralize";
import React, {
forwardRef,
SyntheticEvent,
Expand Down Expand Up @@ -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<
Expand Down Expand Up @@ -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"
: ""}
Expand Down
4 changes: 2 additions & 2 deletions packages/screens/FeedNewArticle/FeedNewArticleScreen.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -291,7 +291,7 @@ export const FeedNewArticleScreen: ScreenFC<"FeedNewArticle"> = () => {
]}
>
{freePostCount
? `You have ${freePostCount} free ${pluralOrNot(
? `You have ${freePostCount} free ${pluralize(
"Article",
freePostCount,
)} left`
Expand Down
3 changes: 0 additions & 3 deletions packages/utils/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14ff1ee

Please sign in to comment.