Refactor: Move util function to proper folder

This commit is contained in:
igorrCarvalho 2024-05-29 18:13:33 -03:00
commit 9c19d5cdf1
2 changed files with 9 additions and 9 deletions

View file

@ -2,6 +2,7 @@ import { useState } from "react";
import IconComponent, {
ForwardedIconComponent,
} from "../../../../../components/genericIconComponent";
import formatFileName from "./utils/format-file-name";
export default function FilePreview({
error,
@ -18,15 +19,6 @@ export default function FilePreview({
const [isHovered, setIsHovered] = useState(false);
const formatFileName = (name) => {
const fileExtension = name.split(".").pop(); // Get the file extension
const baseName = name.slice(0, name.lastIndexOf(".")); // Get the base name without the extension
if (baseName.length > 6) {
return `${baseName.slice(0, 29)}...${fileExtension}`;
}
return name;
};
return (
<div className="relative inline-block">
{loading ? (

View file

@ -0,0 +1,8 @@
export default function formatFileName(name: string): string {
const fileExtension = name.split(".").pop(); // Get the file extension
const baseName = name.slice(0, name.lastIndexOf(".")); // Get the base name without the extension
if (baseName.length > 6) {
return `${baseName.slice(0, 29)}...${fileExtension}`;
}
return name;
}