Skip to content

Commit

Permalink
Feat: add and implement truncateText on movie title
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardsavin committed Aug 25, 2023
1 parent d640d9a commit 5cde42d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ yarn-error.log*

# typescript
*.tsbuildinfo

# idea
.idea
13 changes: 11 additions & 2 deletions src/components/movie-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Image from "next/image";
import MovieModal from "./movie-modal";
import { Dialog, DialogContent, DialogTrigger } from "../components/ui/dialog";
import { Dialog, DialogContent, DialogTrigger } from "~/components/ui/dialog";
import type { MovieInfo } from "~/pages/api/tmdb-fetch-movie-info";
import type { Movie } from "@prisma/client";

Expand All @@ -9,6 +9,15 @@ type MovieCardProps = {
movieDb?: Movie;
};

// Truncate the movie title if it's too long
const truncateText = (string: string, maxLength: number) => {
if (string.length > maxLength) {
return string.substring(0, maxLength) + "...";
} else {
return string;
}
};

// Display the movie recommendations with a poster, title, release year and overview
const MovieCard = ({ movieInfo, movieDb }: MovieCardProps) => {
const imageWidth = 250;
Expand All @@ -24,7 +33,7 @@ const MovieCard = ({ movieInfo, movieDb }: MovieCardProps) => {
<div className="mt-4 flex flex-col">
<h2 className="font-clash_display font-semibold text-yellow-100">
<p className="cursor-pointer text-xl">
{movieInfo?.title || movieDb?.title}
{truncateText(movieInfo?.title || (movieDb?.title as string), 20)}
</p>{" "}
<p className="font-archivo">
Expand Down

1 comment on commit 5cde42d

@vercel
Copy link

@vercel vercel bot commented on 5cde42d Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.