Skip to content

Commit

Permalink
Merge pull request #158 from ucsb-cs148-f21/profile-page-anonymous
Browse files Browse the repository at this point in the history
jv - fix profile page accessed anonymously
  • Loading branch information
jvoucsb authored Dec 4, 2021
2 parents 85e71b4 + 65bd4ef commit 8e1d309
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
5 changes: 1 addition & 4 deletions client/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export type ProfileQueryVariables = Exact<{
}>;


export type ProfileQuery = { __typename?: 'Query', me?: Maybe<{ __typename?: 'User', id: string }>, user?: Maybe<{ __typename?: 'User', id: string, username: string, userLists?: Maybe<Array<Maybe<{ __typename?: 'EmbeddedUserList', id: string, name: string }>>>, profilePageBlocks: Array<Array<{ __typename?: 'SpacerBlock', width: Width, type: BlockType } | { __typename?: 'StatisticsBlock', width: Width, type: BlockType, additionalData: { __typename?: 'StatisticsBlockAdditionalData', entries: number } } | { __typename?: 'TextBlock', width: Width, type: BlockType, textBlockInput: { __typename?: 'TextBlockSettings', text: string } } | { __typename?: 'UserListBlock', width: Width, type: BlockType, userListBlockInput: { __typename?: 'UserListBlockSettings', listId: string, maxEntries?: Maybe<number> }, additionalData: { __typename?: 'UserListBlockAdditionalData', userList: { __typename?: 'UserList', name: string, items?: Maybe<Array<Maybe<{ __typename?: 'UserListItem', mediaID: number, watchStatus: string, rating?: Maybe<{ __typename?: 'UserListRating', displayRating: string }> }>>> } } }>> }> };
export type ProfileQuery = { __typename?: 'Query', user?: Maybe<{ __typename?: 'User', id: string, username: string, userLists?: Maybe<Array<Maybe<{ __typename?: 'EmbeddedUserList', id: string, name: string }>>>, profilePageBlocks: Array<Array<{ __typename?: 'SpacerBlock', width: Width, type: BlockType } | { __typename?: 'StatisticsBlock', width: Width, type: BlockType, additionalData: { __typename?: 'StatisticsBlockAdditionalData', entries: number } } | { __typename?: 'TextBlock', width: Width, type: BlockType, textBlockInput: { __typename?: 'TextBlockSettings', text: string } } | { __typename?: 'UserListBlock', width: Width, type: BlockType, userListBlockInput: { __typename?: 'UserListBlockSettings', listId: string, maxEntries?: Maybe<number> }, additionalData: { __typename?: 'UserListBlockAdditionalData', userList: { __typename?: 'UserList', name: string, items?: Maybe<Array<Maybe<{ __typename?: 'UserListItem', mediaID: number, watchStatus: string, rating?: Maybe<{ __typename?: 'UserListRating', displayRating: string }> }>>> } } }>> }> };

export type UserListBlockFieldsFragment = { __typename?: 'UserListBlock', userListBlockInput: { __typename?: 'UserListBlockSettings', listId: string, maxEntries?: Maybe<number> }, additionalData: { __typename?: 'UserListBlockAdditionalData', userList: { __typename?: 'UserList', name: string, items?: Maybe<Array<Maybe<{ __typename?: 'UserListItem', mediaID: number, watchStatus: string, rating?: Maybe<{ __typename?: 'UserListRating', displayRating: string }> }>>> } } };

Expand Down Expand Up @@ -1180,9 +1180,6 @@ export type MeLazyQueryHookResult = ReturnType<typeof useMeLazyQuery>;
export type MeQueryResult = Apollo.QueryResult<MeQuery, MeQueryVariables>;
export const ProfileDocument = gql`
query Profile($userId: String!) {
me {
id
}
user(userId: $userId) {
id
username
Expand Down
4 changes: 0 additions & 4 deletions client/src/graphql/queries/profile.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
query Profile($userId: String!) {
me {
id
}

user(userId: $userId) {
id
username
Expand Down
17 changes: 9 additions & 8 deletions client/src/pages/profile/[userId].tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Center, Spinner } from "@chakra-ui/react";
import * as React from 'react';
import { useRouter } from "next/router";
import { useProfileQuery } from '../../generated/graphql';
import { useMeQuery, useProfileQuery } from '../../generated/graphql';
import ProfilePage from "../../components/profiles/ProfilePage";

const Profile: React.FC<{}> = () => {
const router = useRouter();
const { userId } = router.query;
const { data, loading } = useProfileQuery({
const { data: meData, loading: meLoading } = useMeQuery();
const { data: profileData, loading: profileLoading } = useProfileQuery({
variables: {
userId: userId as string
}
});

if (loading) {
if (meLoading || profileLoading) {
return (
<Center
flexGrow={1}
Expand All @@ -23,16 +24,16 @@ const Profile: React.FC<{}> = () => {
);
}

if (!data || !data.user) {
if (!profileData || !profileData.user) {
router.push("/");

return (<div />);
}

return <ProfilePage username={data.user.username}
userLists={data.user.userLists}
profilePageBlocks={data.user.profilePageBlocks}
isOwn={data.me.id === data.user.id} />;
return <ProfilePage username={profileData.user.username}
userLists={profileData.user.userLists}
profilePageBlocks={profileData.user.profilePageBlocks}
isOwn={meData && meData.me && meData.me.id === profileData.user.id} />;
};

export default Profile;

0 comments on commit 8e1d309

Please sign in to comment.