Skip to content

Commit a41548b

Browse files
committed
feat: update file name text
1 parent c781b6c commit a41548b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

apps/web/@/molecules/home/filter/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation"
66
import { cn } from "ui"
77

88
import { FilterValues, PeriodValues } from "@/types/filter"
9-
import { capitalizeFirstLetter } from "@/utils/capitalize"
9+
import { capitalizeFirstLetter } from "@/utils/text"
1010

1111
import { FilterItem } from "./filter-item"
1212

apps/web/@/molecules/upload/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
Typography,
1515
} from "ui"
1616

17+
import { truncateFileName } from "@/utils/text"
18+
1719
import AssetManagement from "./AssetsManagement"
1820
import FileManagerContainer, { useFileManager } from "./FileManagerContainer"
1921
import UploadImageButton from "./UploadImageButton"
@@ -57,9 +59,9 @@ const SelectedFiles: React.FC = () => {
5759
<div className="flex h-full flex-1 items-center justify-start">
5860
<Typography
5961
variant="span"
60-
className="max-w-[100px] truncate text-sm font-semibold"
62+
className="text-sm font-semibold"
6163
>
62-
{selectedFiles[0].name}
64+
{truncateFileName(selectedFiles[0].name)}
6365
</Typography>
6466
<Typography
6567
variant="span"

apps/web/@/utils/capitalize.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/web/@/utils/text.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const MAX_FILE_NAME_LENGTH = 20
2+
3+
export const capitalizeFirstLetter = (value: string) => {
4+
return value.charAt(0).toUpperCase() + value.slice(1)
5+
}
6+
7+
export const truncateFileName = (name: string, maxLength = MAX_FILE_NAME_LENGTH) => {
8+
if (name.length <= maxLength) return name
9+
const half = Math.floor((maxLength - 3) / 2)
10+
return `${name.slice(0, half)}...${name.slice(-half)}`
11+
}

0 commit comments

Comments
 (0)