Skip to content

Commit 35dcc78

Browse files
committed
refactor: remove useAuthenticatedImage hook and update avatar image handling across components
1 parent d41ac9d commit 35dcc78

File tree

5 files changed

+4
-87
lines changed

5 files changed

+4
-87
lines changed

app/(main)/contests/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { ResponsiveContainer, LineChart as RechartsLineChart, CartesianGrid, XAx
2020
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
2121
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card';
2222
import { UserProfileCard } from '@/components/shared/user-profile-card';
23-
import { useAuthenticatedImage } from '@/hooks/use-authenticated-image';
2423
import { getInitials } from '@/lib/utils';
2524

2625
const fetcher = (url: string) => api.get(url).then(res => res.data.data);
@@ -174,7 +173,6 @@ function ContestTrend({ contestId }: { contestId: string }) {
174173
}
175174

176175
function LeaderboardRow({ entry, rank, problemIds }: { entry: LeaderboardEntry, rank: number, problemIds: string[] }) {
177-
const authenticatedAvatarUrl = useAuthenticatedImage(entry.avatar_url);
178176

179177
const getRankColor = (rank: number) => {
180178
if (rank === 1) return 'text-yellow-400';
@@ -196,7 +194,7 @@ function LeaderboardRow({ entry, rank, problemIds }: { entry: LeaderboardEntry,
196194
<HoverCardTrigger asChild>
197195
<div className="flex items-center gap-3 cursor-pointer">
198196
<Avatar className="h-8 w-8">
199-
<AvatarImage src={authenticatedAvatarUrl || undefined} alt={entry.nickname} />
197+
<AvatarImage src={entry.avatar_url} alt={entry.nickname} />
200198
<AvatarFallback>{getInitials(entry.nickname)}</AvatarFallback>
201199
</Avatar>
202200
<span className="font-medium">{entry.nickname}</span>

app/(main)/profile/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
1515
import { getInitials } from '@/lib/utils';
1616
import { useState } from 'react';
1717
import { useRouter } from 'next/navigation';
18-
import { useAuthenticatedImage } from '@/hooks/use-authenticated-image'; // 1. Import the hook
1918

2019
const profileSchema = z.object({
2120
nickname: z.string().min(1, 'Nickname is required').max(50),
@@ -28,9 +27,6 @@ export default function ProfilePage() {
2827
const router = useRouter();
2928
const [isUploading, setIsUploading] = useState(false);
3029

31-
// 2. Use the hook here as well
32-
const authenticatedAvatarUrl = useAuthenticatedImage(user?.avatar_url);
33-
3430
const form = useForm<z.infer<typeof profileSchema>>({
3531
resolver: zodResolver(profileSchema),
3632
values: {
@@ -98,7 +94,7 @@ export default function ProfilePage() {
9894
</CardHeader>
9995
<CardContent className="flex flex-col items-center gap-4">
10096
<Avatar className="h-32 w-32">
101-
<AvatarImage key={authenticatedAvatarUrl} src={authenticatedAvatarUrl || undefined} alt={user.nickname} />
97+
<AvatarImage src={user.avatar_url} alt={user.nickname} />
10298
<AvatarFallback>{getInitials(user.nickname)}</AvatarFallback>
10399
</Avatar>
104100
<Input id="avatar-upload" type="file" accept="image/*" onChange={handleAvatarUpload} className="hidden" />

components/layout/user-nav.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ import { useAuth } from "@/hooks/use-auth";
1414
import { getInitials } from "@/lib/utils";
1515
import Link from "next/link";
1616
import { useRouter } from "next/navigation";
17-
import { useAuthenticatedImage } from "@/hooks/use-authenticated-image"; // 1. Import the hook
1817

1918
export function UserNav() {
2019
const { user, logout } = useAuth();
2120
const router = useRouter();
22-
23-
const authenticatedAvatarUrl = useAuthenticatedImage(user?.avatar_url);
2421

2522
const handleLogout = () => {
2623
logout();
@@ -36,7 +33,7 @@ export function UserNav() {
3633
<DropdownMenuTrigger asChild>
3734
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
3835
<Avatar className="h-9 w-9">
39-
<AvatarImage key={authenticatedAvatarUrl} src={authenticatedAvatarUrl || undefined} alt={user.nickname} />
36+
<AvatarImage src={user.avatar_url} alt={user.nickname} />
4037
<AvatarFallback>{getInitials(user.nickname)}</AvatarFallback>
4138
</Avatar>
4239
</Button>

components/shared/user-profile-card.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import useSWR from 'swr';
44
import api from '@/lib/api';
55
import { User } from '@/lib/types';
6-
import { useAuthenticatedImage } from '@/hooks/use-authenticated-image';
76
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
87
import { getInitials } from '@/lib/utils';
98
import { Skeleton } from '@/components/ui/skeleton';
@@ -17,7 +16,6 @@ interface UserProfileCardProps {
1716

1817
export function UserProfileCard({ userId }: UserProfileCardProps) {
1918
const { data: user, error, isLoading } = useSWR<User>(`/users/${userId}`, fetcher);
20-
const authenticatedAvatarUrl = useAuthenticatedImage(user?.avatar_url);
2119

2220
if (isLoading) return <UserProfileCardSkeleton />;
2321
if (error || !user) return <div className="text-sm text-destructive">Could not load user profile.</div>;
@@ -26,7 +24,7 @@ export function UserProfileCard({ userId }: UserProfileCardProps) {
2624
<div className="flex flex-col gap-4">
2725
<div className="flex items-center gap-4">
2826
<Avatar className="h-16 w-16">
29-
<AvatarImage src={authenticatedAvatarUrl || undefined} alt={user.nickname} />
27+
<AvatarImage src={user.avatar_url} alt={user.nickname} />
3028
<AvatarFallback>{getInitials(user.nickname)}</AvatarFallback>
3129
</Avatar>
3230
<div className="flex flex-col">

hooks/use-authenticated-image.ts

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

0 commit comments

Comments
 (0)