From 056f838172b8302155e737f77b450bba17308da6 Mon Sep 17 00:00:00 2001 From: parsa aghaei Date: Mon, 29 Jun 2026 13:45:40 +0330 Subject: [PATCH] fix: testimonial arrow layout/direction logic, language switcher fonts, getCleanImgSrc sanitizer --- .../components/projects/projects.tsx | 28 ++++++++----------- .../selectLanguage/selectLanguage.tsx | 4 +-- .../components/testimonials/testimonials.tsx | 22 ++++++++------- src/app/lib/functions/client-utils.ts | 11 ++++++++ 4 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 src/app/lib/functions/client-utils.ts diff --git a/src/app/(routes)/(website)/components/projects/projects.tsx b/src/app/(routes)/(website)/components/projects/projects.tsx index 4ecaa46..78bb49a 100644 --- a/src/app/(routes)/(website)/components/projects/projects.tsx +++ b/src/app/(routes)/(website)/components/projects/projects.tsx @@ -14,6 +14,8 @@ import { motion, AnimatePresence } from "framer-motion"; import Image from "next/image"; import { X, ChevronLeft, ChevronRight } from "lucide-react"; +import { toPersianDigits, getCleanImgSrc } from "@/app/lib/functions/client-utils"; + interface MyProjectsProps { dict: { website: { @@ -30,9 +32,6 @@ interface MyProjectsProps { const MAX_PROJECTS = 6; const MAX_CATEGORIES = 5; -const toPersianDigits = (str: string | number): string => - String(str).replace(/\d/g, d => '۰۱۲۳۴۵۶۷۸۹'[parseInt(d)]); - export default function Projects({ dict }: MyProjectsProps) { const [categories, setCategories] = useState([]); const [projects, setProjects] = useState([]); @@ -283,20 +282,15 @@ export default function Projects({ dict }: MyProjectsProps) {
{/* Left: Image */}
- {selectedProject.images.map((image, idx) => { - const imgSrc = image.src.startsWith("http") - ? image.src - : `/images/projects/${image.src}`; - return ( - {`Image - ); - })} + {selectedProject.images.map((image, idx) => ( + {`Image + ))}
diff --git a/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx b/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx index c63a878..48390f2 100644 --- a/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx +++ b/src/app/(routes)/(website)/components/selectLanguage/selectLanguage.tsx @@ -30,7 +30,7 @@ export default function SelectLanguage() { > { e.preventDefault(); setCookie("selectedLocale", "fa"), router.refresh(); @@ -41,7 +41,7 @@ export default function SelectLanguage() { { e.preventDefault(); setCookie("selectedLocale", "en"), router.refresh(); diff --git a/src/app/(routes)/(website)/components/testimonials/testimonials.tsx b/src/app/(routes)/(website)/components/testimonials/testimonials.tsx index 6fce376..47e6b31 100644 --- a/src/app/(routes)/(website)/components/testimonials/testimonials.tsx +++ b/src/app/(routes)/(website)/components/testimonials/testimonials.tsx @@ -6,6 +6,8 @@ import { Quote, ChevronLeft, ChevronRight } from "lucide-react"; import Image from "next/image"; import { getCookie } from "cookies-next"; +import { getCleanImgSrc } from "@/app/lib/functions/client-utils"; + interface TestimonialData { name: string; position: string; @@ -73,7 +75,7 @@ export default function Testimonials({ dict }: TestimonialsProps) {
-
+
{testimonial.name} 3 && ( <>
diff --git a/src/app/lib/functions/client-utils.ts b/src/app/lib/functions/client-utils.ts new file mode 100644 index 0000000..4c1f392 --- /dev/null +++ b/src/app/lib/functions/client-utils.ts @@ -0,0 +1,11 @@ +export const toPersianDigits = (str: string | number): string => + String(str).replace(/\d/g, d => '۰۱۲۳۴۵۶۷۸۹'[parseInt(d)]); + +export const getCleanImgSrc = (src: string): string => { + if (!src) return '/images/placeholder.jpg'; + if (src.startsWith('http://') || src.startsWith('https://')) { + const urlPath = new URL(src).pathname; + return urlPath.startsWith('/storage') ? urlPath : `/images${urlPath}`; + } + return src; +};