Skip to content

Commit 5a76298

Browse files
committed
fix: const to functions
1 parent b4dff9e commit 5a76298

12 files changed

Lines changed: 80 additions & 107 deletions

File tree

dataconnect/app/src/App.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import AdvancedSearchPage from "./pages/AdvancedSearch";
1010
import NotFound from "./pages/NotFound";
1111
import RootLayout from "./layout/RootLayout";
1212

13-
const App = () => {
13+
export default function App() {
1414
return (
1515
<Router>
1616
<RootLayout>
@@ -27,6 +27,4 @@ const App = () => {
2727
</RootLayout>
2828
</Router>
2929
);
30-
};
31-
32-
export default App;
30+
}

dataconnect/app/src/components/carousel.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ interface CarouselProps {
1313
}[];
1414
}
1515

16-
const Carousel = (
17-
{
18-
title,
19-
movies
20-
}: CarouselProps
21-
) => {
16+
export default function Carousel({ title, movies }: CarouselProps) {
2217
return (
2318
<section className="carousel py-8">
2419
<h2 className="text-gray-200 text-2xl font-bold mb-4">{title}</h2>
@@ -38,6 +33,4 @@ const Carousel = (
3833
</div>
3934
</section>
4035
);
41-
};
42-
43-
export default Carousel;
36+
}

dataconnect/app/src/components/moviecard.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ interface MovieCardProps {
1414
tags?: string[] | null;
1515
}
1616

17-
const MovieCard = (
18-
{
19-
id,
20-
title,
21-
imageUrl,
22-
rating,
23-
genre,
24-
tags
25-
}: MovieCardProps
26-
) => {
17+
export default function MovieCard({
18+
id,
19+
title,
20+
imageUrl,
21+
rating,
22+
genre,
23+
tags
24+
}: MovieCardProps) {
2725
const [user, setUser] = useState<User | null>(null);
2826
const [isFavorited, setIsFavorited] = useState(false);
2927
const auth = useContext(AuthContext);
@@ -40,16 +38,16 @@ const MovieCard = (
4038
return () => unsubscribe();
4139
}, [auth, id]);
4240

43-
const checkIfFavorited = async () => {
41+
async function checkIfFavorited() {
4442
try {
4543
const response = await getIfFavoritedMovie({ movieId: id });
4644
setIsFavorited(!!response.data.favorite_movie);
4745
} catch (error) {
4846
console.error('Error checking if favorited:', error);
4947
}
50-
};
48+
}
5149

52-
const handleFavoriteToggle = async (e: React.MouseEvent) => {
50+
async function handleFavoriteToggle(e: React.MouseEvent) {
5351
e.stopPropagation();
5452
e.preventDefault();
5553
if (!user) return;
@@ -63,13 +61,15 @@ const MovieCard = (
6361
} catch (error) {
6462
console.error('Error updating favorite status:', error);
6563
}
66-
};
64+
}
6765

68-
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
66+
function capitalize(str: string) {
67+
return str.charAt(0).toUpperCase() + str.slice(1);
68+
}
6969

70-
const handleCardClick = () => {
70+
function handleCardClick() {
7171
navigate(`/movie/${id}`);
72-
};
72+
}
7373

7474
return (
7575
<div
@@ -111,6 +111,4 @@ const MovieCard = (
111111
</div>
112112
</div>
113113
);
114-
};
115-
116-
export default MovieCard;
114+
}

dataconnect/app/src/components/navbar.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { upsertUser } from '@/lib/dataconnect-sdk';
66
import { FaSearch } from 'react-icons/fa';
77
import firebaseLogo from '@/assets/firebase_logo.svg';
88

9-
const Navbar = () => {
9+
export default function Navbar() {
1010
const [user, setUser] = useState<User | null>(null);
1111
const auth = useContext(AuthContext);
1212

@@ -23,14 +23,14 @@ const Navbar = () => {
2323
return () => unsubscribe();
2424
}, [auth]);
2525

26-
const handleSignIn = async () => {
26+
async function handleSignIn() {
2727
const provider = new GoogleAuthProvider();
2828
await signInWithPopup(auth, provider);
29-
};
29+
}
3030

31-
const handleSignOut = async () => {
31+
async function handleSignOut() {
3232
await signOut(auth);
33-
};
33+
}
3434

3535
return (
3636
<nav className="bg-black p-4">
@@ -89,6 +89,4 @@ const Navbar = () => {
8989
</div>
9090
</nav>
9191
);
92-
};
93-
94-
export default Navbar;
92+
}

dataconnect/app/src/pages/Actor.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { onAuthStateChanged, User } from 'firebase/auth';
1212
import { AuthContext } from '@/lib/firebase';
1313
import NotFound from './NotFound';
1414

15-
const ActorPage = () => {
15+
export default function ActorPage() {
1616
const { id } = useParams<{ id: string }>();
1717
const actorId = id || '';
1818
const [actor, setActor] = useState<GetActorByIdResponse['actor'] | null>(null);
@@ -55,16 +55,16 @@ const ActorPage = () => {
5555
}
5656
}, [actorId, navigate]);
5757

58-
const checkIfFavorited = async () => {
58+
async function checkIfFavorited() {
5959
try {
6060
const response = await getIfFavoritedActor({ actorId });
6161
setIsFavorited(!!response.data.favorite_actor);
6262
} catch (error) {
6363
console.error('Error checking if favorited:', error);
6464
}
65-
};
65+
}
6666

67-
const handleFavoriteToggle = async () => {
67+
async function handleFavoriteToggle() {
6868
if (!authUser) return;
6969
try {
7070
if (isFavorited) {
@@ -76,7 +76,7 @@ const ActorPage = () => {
7676
} catch (error) {
7777
console.error('Error updating favorite status:', error);
7878
}
79-
};
79+
}
8080

8181
if (loading) return <p>Loading...</p>;
8282

@@ -145,6 +145,4 @@ const ActorPage = () => {
145145
) : (
146146
<NotFound />
147147
);
148-
};
149-
150-
export default ActorPage;
148+
}

dataconnect/app/src/pages/AdvancedSearch.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { searchAll } from '@/lib/dataconnect-sdk';
66

77
const genres = ['', 'action', 'crime', 'drama', 'sci-fi', 'thriller', 'adventure'];
88

9-
const AdvancedSearchPage = () => {
9+
export default function AdvancedSearchPage() {
1010
const [searchQuery, setSearchQuery] = useState('');
1111
const [releaseYearRange, setReleaseYearRange] = useState({ min: 1900, max: 2030 });
1212
const [genre, setGenre] = useState('');
@@ -18,7 +18,7 @@ const AdvancedSearchPage = () => {
1818
reviews: [],
1919
});
2020

21-
const handleSearch = async (e: React.FormEvent<HTMLFormElement>) => {
21+
async function handleSearch(e: React.FormEvent<HTMLFormElement>) {
2222
e.preventDefault();
2323
try {
2424
const response = await searchAll({
@@ -38,7 +38,7 @@ const AdvancedSearchPage = () => {
3838
} catch (error) {
3939
console.error('Error fetching search results:', error);
4040
}
41-
};
41+
}
4242

4343
return (
4444
<div className="container mx-auto p-4 bg-gray-900 min-h-screen text-white">
@@ -213,6 +213,4 @@ const AdvancedSearchPage = () => {
213213
</div>
214214
</div>
215215
);
216-
};
217-
218-
export default AdvancedSearchPage;
216+
}

dataconnect/app/src/pages/Genre.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { useParams } from 'react-router-dom';
33
import MovieCard from '@/components/moviecard';
44
import { ListMoviesByGenreResponse, listMoviesByGenre } from '@/lib/dataconnect-sdk';
55

6-
const GenrePage = () => {
6+
export default function GenrePage() {
77
const { genre } = useParams<{ genre: string }>();
88
const [mostPopular, setMostPopular] = useState<ListMoviesByGenreResponse['mostPopular']>([]);
99
const [mostRecent, setMostRecent] = useState<ListMoviesByGenreResponse['mostRecent']>([]);
1010
const [loading, setLoading] = useState(true);
1111

1212
useEffect(() => {
13-
const fetchMovies = async () => {
13+
async function fetchMovies() {
1414
try {
1515
const response = await listMoviesByGenre({ genre });
1616
setMostPopular(response.data.mostPopular);
@@ -20,7 +20,7 @@ const GenrePage = () => {
2020
} finally {
2121
setLoading(false);
2222
}
23-
};
23+
}
2424

2525
fetchMovies();
2626
}, [genre]);
@@ -64,6 +64,4 @@ const GenrePage = () => {
6464
</section>
6565
</div>
6666
);
67-
};
68-
69-
export default GenrePage;
67+
}

dataconnect/app/src/pages/Home.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { useEffect, useState } from 'react';
22
import Carousel from '@/components/carousel';
33
import { listMovies, ListMoviesResponse } from '@/lib/dataconnect-sdk';
44

5-
const HomePage = () => {
5+
export default function HomePage() {
66
const [topMovies, setTopMovies] = useState<ListMoviesResponse["movies"]>([]);
77
const [latestMovies, setLatestMovies] = useState<ListMoviesResponse["movies"]>([]);
88

99
useEffect(() => {
10-
const fetchMovies = async () => {
10+
async function fetchMovies() {
1111
try {
1212
const topMoviesResponse = await listMovies({ orderByRating: "DESC", limit: 10 });
1313
const latestMoviesResponse = await listMovies({ orderByReleaseYear: "DESC", limit: 10 });
@@ -17,7 +17,7 @@ const HomePage = () => {
1717
} catch (error) {
1818
console.error("Error fetching movies:", error);
1919
}
20-
};
20+
}
2121

2222
fetchMovies();
2323
}, []);
@@ -28,6 +28,4 @@ const HomePage = () => {
2828
<Carousel title="Latest Movies" movies={latestMovies} />
2929
</div>
3030
);
31-
};
32-
33-
export default HomePage;
31+
}

dataconnect/app/src/pages/Movie.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
import { useContext, useEffect, useState } from 'react';
32
import { useParams, Link } from 'react-router-dom';
43
import { MdFavorite, MdFavoriteBorder, MdStar } from 'react-icons/md';
@@ -17,7 +16,7 @@ import { onAuthStateChanged, User } from 'firebase/auth';
1716
import { AuthContext } from '@/lib/firebase';
1817
import NotFound from './NotFound';
1918

20-
const MoviePage = () => {
19+
export default function MoviePage() {
2120
const { id } = useParams() as { id: string };
2221
const [movie, setMovie] = useState<GetMovieByIdResponse['movie'] | null>(null);
2322
const [loading, setLoading] = useState(true);
@@ -60,25 +59,25 @@ const MoviePage = () => {
6059
}
6160
}, [id, authUser]);
6261

63-
const fetchSimilarMovies = async (description: string) => {
62+
async function fetchSimilarMovies(description: string) {
6463
try {
6564
const response = await searchMovieDescriptionUsingL2similarity({ query: description });
6665
setSimilarMovies(response?.data?.movies_descriptionEmbedding_similarity);
6766
} catch (error) {
6867
console.error('Error fetching similar movies:', error);
6968
}
70-
};
69+
}
7170

72-
const checkIfFavorited = async () => {
71+
async function checkIfFavorited() {
7372
try {
7473
const response = await getIfFavoritedMovie({ movieId: id });
7574
setIsFavorited(!!response.data.favorite_movie);
7675
} catch (error) {
7776
console.error('Error checking if favorited:', error);
7877
}
79-
};
78+
}
8079

81-
const handleFavoriteToggle = async (e: React.MouseEvent) => {
80+
async function handleFavoriteToggle(e: React.MouseEvent) {
8281
e.stopPropagation();
8382
e.preventDefault();
8483
if (!authUser) return;
@@ -92,23 +91,23 @@ const MoviePage = () => {
9291
} catch (error) {
9392
console.error('Error updating favorite status:', error);
9493
}
95-
};
94+
}
9695

97-
const handleReviewSubmit = async (e: React.FormEvent) => {
96+
async function handleReviewSubmit(e: React.FormEvent) {
9897
e.preventDefault();
9998
if (!authUser) return;
10099
try {
101-
await addReview({ movieId: id, rating, reviewText });
100+
await addReview({ movieId: id, rating, reviewText });
102101
setReviewText('');
103102
setRating(0);
104103
const updatedMovie = await getMovieById({ id });
105104
setMovie(updatedMovie.data.movie);
106105
} catch (error) {
107106
console.error('Error adding review:', error);
108107
}
109-
};
108+
}
110109

111-
const handleReviewDelete = async (e: React.MouseEvent) => {
110+
async function handleReviewDelete(e: React.MouseEvent) {
112111
e.stopPropagation();
113112
e.preventDefault();
114113
if (!authUser || !userReview) return;
@@ -120,11 +119,13 @@ const MoviePage = () => {
120119
} catch (error) {
121120
console.error('Error deleting review:', error);
122121
}
123-
};
122+
}
123+
124124
if (loading) return <p>Loading...</p>;
125125
if (!movie) return <NotFound />;
126+
126127
return (
127-
<div className="container mx-auto p-4 bg-gray-900 min-h-screen text-white">
128+
<div className="container mx-auto p-4 bg-gray-900 min-h-screen text-white">
128129
<div className="flex flex-col md:flex-row mb-8">
129130
<img className="w-full md:w-1/3 object-cover rounded-lg shadow-md" src={movie.imageUrl} alt={movie.title} />
130131
<div className="md:ml-8 mt-4 md:mt-0 flex-1">
@@ -272,7 +273,6 @@ const MoviePage = () => {
272273
))}
273274
</div>
274275
</div>
275-
</div>);
276-
};
277-
278-
export default MoviePage;
276+
</div>
277+
);
278+
}

0 commit comments

Comments
 (0)