Skip to content

Commit c4fa374

Browse files
foenx0315RizonFTW
andauthored
Ranranaway (#6)
* feat(add): introduce new components, hooks, and API routes; update existing files and configurations * shift every single thing to react-icons and more bug fixes * shift every single thing to react-icons and more bug fixes * shift every single thing to react-icons and more bug fixes * everything works! * chore: update change logs * fix: dashboard navbar text color and hover * feat: update database from PostgreSQL to MySQL (wordings not like db db), add system status API, and enhance footer with status display * feat(add): new nsfw warning * refactor: improve user authentication logic and enhance API response handling * chore: update changelog * feat: implement NSFW warning modal with age verification for links containing adult content * chore: update og logic * chore: update og logic --------- Co-authored-by: RizonFTW <rizon@nodebyte.co.uk> Co-authored-by: Rizon <kye021@hotmail.co.uk>
1 parent 8d9536f commit c4fa374

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

pages/[handle].tsx

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ import AnimatedBackground from '@/components/core/animated-backgrounds/animated-
1818
import { ProfilePageMeta } from '@/components/meta/metadata';
1919
import TabbedSections from '@/components/core/user-profile/tabbed-sections';
2020

21+
type ServerUser = {
22+
id?: string;
23+
handle?: string;
24+
name?: string | null;
25+
bio?: string | null;
26+
image?: string | null;
27+
};
28+
2129
type ProfilePageProps = {
2230
serverHandle?: string | null;
31+
serverUser?: ServerUser | null;
2332
};
2433

25-
const ProfilePage = ({ serverHandle }: ProfilePageProps) => {
34+
const ProfilePage = ({ serverHandle, serverUser }: ProfilePageProps) => {
2635
const { query } = useRouter();
2736
const { handle } = query;
2837
const normalizedHandle =
@@ -51,7 +60,7 @@ const ProfilePage = ({ serverHandle }: ProfilePageProps) => {
5160
const queryClient = useQueryClient();
5261
const [, setIsDataLoaded] = useState(false);
5362

54-
const user = fetchedUser as any;
63+
const user = (fetchedUser as any) || (serverUser as any);
5564
const links = (userLinks as any[]) || [];
5665
const sectionList = (sections as any[]) || [];
5766

@@ -120,9 +129,9 @@ const ProfilePage = ({ serverHandle }: ProfilePageProps) => {
120129
<>
121130
<ProfilePageMeta
122131
handle={effectiveHandle}
123-
name={undefined}
124-
bio={'Welcome to Lynkr'}
125-
user={undefined}
132+
name={serverUser?.name || undefined}
133+
bio={serverUser?.bio || 'Welcome to Lynkr'}
134+
user={serverUser || undefined}
126135
/>
127136
<Loader
128137
message={'Loading...'}
@@ -141,9 +150,9 @@ const ProfilePage = ({ serverHandle }: ProfilePageProps) => {
141150
<>
142151
<ProfilePageMeta
143152
handle={effectiveHandle}
144-
name={effectiveHandle ? `@${effectiveHandle}` : undefined}
145-
bio={'Welcome to Lynkr'}
146-
user={undefined}
153+
name={serverUser?.name || (effectiveHandle ? `@${effectiveHandle}` : undefined)}
154+
bio={serverUser?.bio || 'Welcome to Lynkr'}
155+
user={serverUser || undefined}
147156
/>
148157
<NotFound />
149158
</>
@@ -491,3 +500,39 @@ const ProfilePage = ({ serverHandle }: ProfilePageProps) => {
491500
};
492501

493502
export default ProfilePage;
503+
504+
export async function getServerSideProps(context) {
505+
const handleParam = context.params?.handle as string | undefined;
506+
507+
if (!handleParam) {
508+
return { props: { serverHandle: null, serverUser: null } };
509+
}
510+
511+
try {
512+
// Fetch minimal user data for meta tags on the server
513+
const { db } = await import('@/lib/db');
514+
const serverUser = await db.user.findUnique({
515+
where: { handle: handleParam },
516+
select: {
517+
id: true,
518+
handle: true,
519+
name: true,
520+
bio: true,
521+
image: true,
522+
themePalette: true,
523+
ogStyles: true,
524+
_count: { select: { pageViews: true } },
525+
links: { where: { archived: false }, select: { id: true, clicks: true } },
526+
},
527+
});
528+
529+
return {
530+
props: {
531+
serverHandle: handleParam,
532+
serverUser: serverUser || null,
533+
},
534+
};
535+
} catch (e) {
536+
return { props: { serverHandle: handleParam, serverUser: null } };
537+
}
538+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
"exclude": [
4141
"node_modules"
4242
]
43-
}
43+
}

utils/geo-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ export async function getLocationFromIp(ip?: string | null): Promise<GeoLocation
3434
}
3535
}
3636

37-

utils/helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,4 @@ export type OgStyles = {
104104
showAvatar?: boolean;
105105
showStats?: boolean;
106106
backgroundOpacity?: number;
107-
};
108-
109-
107+
};

0 commit comments

Comments
 (0)