Skip to content

Commit

Permalink
Merge pull request #4 from deepsingh132/development
Browse files Browse the repository at this point in the history
Fixes the bug in case if a user is not found in the database
  • Loading branch information
deepsingh132 committed Jul 2, 2024
2 parents aa640b4 + 05ce71b commit 667b356
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
27 changes: 20 additions & 7 deletions app/(root)/profile/[profileId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { useQuery } from "convex/react";

import EmptyState from "@/components/EmptyState";
Expand All @@ -8,22 +9,34 @@ import PodcastCard from "@/components/PodcastCard";
import ProfileCard from "@/components/ProfileCard";
import { api } from "@/convex/_generated/api";
import { ProfilePodcastProps } from "@/types";

const ProfilePage = ({
params,
}: {
params: {
profileId: string;
};
}) => {
const user = useQuery(api.users.getUserById, {
clerkId: params.profileId,
});
}) => {

const [isFetching, setIsFetching] = useState(true);
const user = useQuery(api.users.getUserById, { clerkId: params.profileId });
const podcastsData = useQuery(api.podcasts.getPodcastByAuthorId, {
authorId: params.profileId,
}) as ProfilePodcastProps;

if (!user || !podcastsData) return <LoaderSpinner />;
useEffect(() => {
if (user || user === null) {
setIsFetching(false);
}
}, [user]);

if (isFetching) return <LoaderSpinner />;

if (!isFetching && !user)
return (
<div className="flex min-h-screen justify-center items-center">
<EmptyState title="User not found" />
</div>
);

return (
<section className="mt-9 flex flex-col">
Expand All @@ -33,7 +46,7 @@ const ProfilePage = ({
<div className="mt-6 flex flex-col gap-6 max-md:items-center md:flex-row">
<ProfileCard
profileId={params.profileId}
podcastData={podcastsData}
podcastData={podcastsData!}
imageUrl={user?.imageUrl!}
userFirstName={user?.name!}
/>
Expand Down
6 changes: 4 additions & 2 deletions convex/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const getUserById = query({
.unique();

if (!user) {
throw new ConvexError("User not found");
// throw new ConvexError("User not found");
return null;
}

return user;
Expand Down Expand Up @@ -76,7 +77,8 @@ export const getSubscriptionByClerkId = query({
.first();

if (!user) {
throw new ConvexError("User not found");
// throw new ConvexError("User not found");
return null;
}

return {
Expand Down

0 comments on commit 667b356

Please sign in to comment.