From 08c8dc065c1c84d49685d8fbbce5d39b933ba9e9 Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Tue, 4 Oct 2022 15:29:52 +0300 Subject: [PATCH] feat: add projects card to user profile --- api/functions/graphql/nexus-typegen.ts | 6 +++ api/functions/graphql/schema.graphql | 3 ++ api/functions/graphql/types/users.js | 13 +++++++ .../pages/ProfilePage/AboutCard/AboutCard.tsx | 2 +- .../MakerProjectsCard.stories.tsx | 20 ++++++++++ .../MakerProjectsCard/MakerProjectsCard.tsx | 39 +++++++++++++++++++ .../pages/ProfilePage/ProfilePage.tsx | 3 ++ .../pages/ProfilePage/profile.graphql | 11 ++++++ .../pages/ProjectPage/ProjectPage.tsx | 2 +- src/graphql/index.tsx | 16 +++++++- src/mocks/data/users.ts | 13 +++++-- 11 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 src/features/Profiles/pages/ProfilePage/MakerProjectsCard/MakerProjectsCard.stories.tsx create mode 100644 src/features/Profiles/pages/ProfilePage/MakerProjectsCard/MakerProjectsCard.tsx diff --git a/api/functions/graphql/nexus-typegen.ts b/api/functions/graphql/nexus-typegen.ts index 8310857..55275ea 100644 --- a/api/functions/graphql/nexus-typegen.ts +++ b/api/functions/graphql/nexus-typegen.ts @@ -548,6 +548,7 @@ export interface NexusGenFieldTypes { name: string; // String! nostr_prv_key: string | null; // String nostr_pub_key: string | null; // String + projects: NexusGenRootTypes['Project'][]; // [Project!]! role: string | null; // String roles: NexusGenRootTypes['MakerRole'][]; // [MakerRole!]! similar_makers: NexusGenRootTypes['User'][]; // [User!]! @@ -744,6 +745,7 @@ export interface NexusGenFieldTypes { linkedin: string | null; // String location: string | null; // String name: string; // String! + projects: NexusGenRootTypes['Project'][]; // [Project!]! role: string | null; // String roles: NexusGenRootTypes['MakerRole'][]; // [MakerRole!]! similar_makers: NexusGenRootTypes['User'][]; // [User!]! @@ -781,6 +783,7 @@ export interface NexusGenFieldTypes { linkedin: string | null; // String location: string | null; // String name: string; // String! + projects: NexusGenRootTypes['Project'][]; // [Project!]! role: string | null; // String roles: NexusGenRootTypes['MakerRole'][]; // [MakerRole!]! similar_makers: NexusGenRootTypes['User'][]; // [User!]! @@ -937,6 +940,7 @@ export interface NexusGenFieldTypeNames { name: 'String' nostr_prv_key: 'String' nostr_pub_key: 'String' + projects: 'Project' role: 'String' roles: 'MakerRole' similar_makers: 'User' @@ -1133,6 +1137,7 @@ export interface NexusGenFieldTypeNames { linkedin: 'String' location: 'String' name: 'String' + projects: 'Project' role: 'String' roles: 'MakerRole' similar_makers: 'User' @@ -1170,6 +1175,7 @@ export interface NexusGenFieldTypeNames { linkedin: 'String' location: 'String' name: 'String' + projects: 'Project' role: 'String' roles: 'MakerRole' similar_makers: 'User' diff --git a/api/functions/graphql/schema.graphql b/api/functions/graphql/schema.graphql index 6f64e81..c1276fe 100644 --- a/api/functions/graphql/schema.graphql +++ b/api/functions/graphql/schema.graphql @@ -31,6 +31,7 @@ interface BaseUser { linkedin: String location: String name: String! + projects: [Project!]! role: String roles: [MakerRole!]! similar_makers: [User!]! @@ -216,6 +217,7 @@ type MyProfile implements BaseUser { name: String! nostr_prv_key: String nostr_pub_key: String + projects: [Project!]! role: String roles: [MakerRole!]! similar_makers: [User!]! @@ -554,6 +556,7 @@ type User implements BaseUser { linkedin: String location: String name: String! + projects: [Project!]! role: String roles: [MakerRole!]! similar_makers: [User!]! diff --git a/api/functions/graphql/types/users.js b/api/functions/graphql/types/users.js index b67b64c..3ec0a8a 100644 --- a/api/functions/graphql/types/users.js +++ b/api/functions/graphql/types/users.js @@ -72,6 +72,19 @@ const BaseUser = interfaceType({ }).then(d => d.map(item => item.tournament)) } }) + t.nonNull.list.nonNull.field('projects', { + type: "Project", + resolve: async (parent) => { + return prisma.projectMember.findMany({ + where: { + userId: parent.id + }, + include: { + project: true + } + }).then(d => d.map(item => item.project)) + } + }) t.nonNull.list.nonNull.field('similar_makers', { type: "User", resolve(parent,) { diff --git a/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx b/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx index d1efa14..daf76c6 100644 --- a/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx +++ b/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx @@ -100,11 +100,11 @@ export default function AboutCard({ user, isOwner }: Props) { : NotificationsService.info(" Copied to clipboard", { icon: "📋" })} > } + } + + + ) +} diff --git a/src/features/Profiles/pages/ProfilePage/ProfilePage.tsx b/src/features/Profiles/pages/ProfilePage/ProfilePage.tsx index d722052..f4fdac1 100644 --- a/src/features/Profiles/pages/ProfilePage/ProfilePage.tsx +++ b/src/features/Profiles/pages/ProfilePage/ProfilePage.tsx @@ -12,6 +12,7 @@ import SkillsCard from "./SkillsCard/SkillsCard" import TournamentsCard from "./TournamentsCard/TournamentsCard" import { MEDIA_QUERIES } from "src/utils/theme" import SimilarMakersCard from "./SimilarMakersCard/SimilarMakersCard" +import MakerProjectsCard from "./MakerProjectsCard/MakerProjectsCard" export default function ProfilePage() { @@ -65,6 +66,7 @@ export default function ProfilePage() { @@ -74,6 +76,7 @@ export default function ProfilePage() { + diff --git a/src/features/Profiles/pages/ProfilePage/profile.graphql b/src/features/Profiles/pages/ProfilePage/profile.graphql index 76829c8..dfa428e 100644 --- a/src/features/Profiles/pages/ProfilePage/profile.graphql +++ b/src/features/Profiles/pages/ProfilePage/profile.graphql @@ -17,6 +17,17 @@ query profile($profileId: Int!) { start_date end_date } + projects { + id + hashtag + title + thumbnail_image + category { + id + icon + title + } + } similar_makers { id name diff --git a/src/features/Projects/pages/ProjectPage/ProjectPage.tsx b/src/features/Projects/pages/ProjectPage/ProjectPage.tsx index 2f22c69..453933d 100644 --- a/src/features/Projects/pages/ProjectPage/ProjectPage.tsx +++ b/src/features/Projects/pages/ProjectPage/ProjectPage.tsx @@ -70,7 +70,7 @@ export default function ProjectPage() { -
{isMediumScreen ? diff --git a/src/graphql/index.tsx b/src/graphql/index.tsx index 29d3326..b90cf9f 100644 --- a/src/graphql/index.tsx +++ b/src/graphql/index.tsx @@ -48,6 +48,7 @@ export type BaseUser = { linkedin: Maybe; location: Maybe; name: Scalars['String']; + projects: Array; role: Maybe; roles: Array; similar_makers: Array; @@ -325,6 +326,7 @@ export type MyProfile = BaseUser & { name: Scalars['String']; nostr_prv_key: Maybe; nostr_pub_key: Maybe; + projects: Array; role: Maybe; roles: Array; similar_makers: Array; @@ -813,6 +815,7 @@ export type User = BaseUser & { linkedin: Maybe; location: Maybe; name: Scalars['String']; + projects: Array; role: Maybe; roles: Array; similar_makers: Array; @@ -1020,7 +1023,7 @@ export type ProfileQueryVariables = Exact<{ }>; -export type ProfileQuery = { __typename?: 'Query', profile: { __typename?: 'User', id: number, name: string, avatar: string, join_date: any, role: string | null, jobTitle: string | null, lightning_address: string | null, website: string | null, twitter: string | null, discord: string | null, github: string | null, linkedin: string | null, bio: string | null, location: string | null, stories: Array<{ __typename?: 'Story', id: number, title: string, createdAt: any, tags: Array<{ __typename?: 'Tag', id: number, title: string, icon: string | null }> }>, tournaments: Array<{ __typename?: 'Tournament', id: number, title: string, thumbnail_image: string, start_date: any, end_date: any }>, similar_makers: Array<{ __typename?: 'User', id: number, name: string, avatar: string, jobTitle: string | null }>, skills: Array<{ __typename?: 'MakerSkill', id: number, title: string }>, roles: Array<{ __typename?: 'MakerRole', id: number, title: string, icon: string, level: RoleLevelEnum }> } | null }; +export type ProfileQuery = { __typename?: 'Query', profile: { __typename?: 'User', id: number, name: string, avatar: string, join_date: any, role: string | null, jobTitle: string | null, lightning_address: string | null, website: string | null, twitter: string | null, discord: string | null, github: string | null, linkedin: string | null, bio: string | null, location: string | null, stories: Array<{ __typename?: 'Story', id: number, title: string, createdAt: any, tags: Array<{ __typename?: 'Tag', id: number, title: string, icon: string | null }> }>, tournaments: Array<{ __typename?: 'Tournament', id: number, title: string, thumbnail_image: string, start_date: any, end_date: any }>, projects: Array<{ __typename?: 'Project', id: number, hashtag: string, title: string, thumbnail_image: string, category: { __typename?: 'Category', id: number, icon: string | null, title: string } }>, similar_makers: Array<{ __typename?: 'User', id: number, name: string, avatar: string, jobTitle: string | null }>, skills: Array<{ __typename?: 'MakerSkill', id: number, title: string }>, roles: Array<{ __typename?: 'MakerRole', id: number, title: string, icon: string, level: RoleLevelEnum }> } | null }; export type CategoryPageQueryVariables = Exact<{ categoryId: Scalars['Int']; @@ -2283,6 +2286,17 @@ export const ProfileDocument = gql` start_date end_date } + projects { + id + hashtag + title + thumbnail_image + category { + id + icon + title + } + } similar_makers { id name diff --git a/src/mocks/data/users.ts b/src/mocks/data/users.ts index 97229f5..8177b82 100644 --- a/src/mocks/data/users.ts +++ b/src/mocks/data/users.ts @@ -2,6 +2,7 @@ import { Chance } from "chance"; import { GenericMakerRole, MakerSkill, MyProfile, RoleLevelEnum, Tournament, User } from "src/graphql"; import { randomItem, randomItems } from "src/utils/helperFunctions"; import { posts } from "./posts"; +import { projects } from "./projects"; import { getCoverImage, getAvatarImage } from "./utils"; const chance = new Chance(); @@ -177,7 +178,8 @@ export const users: (User & MyProfile)[] = [{ roles: randomItems(3, ...allMakersRoles).map(role => ({ ...role, level: randomItem(...Object.values(RoleLevelEnum)) })), skills: randomItems(7, ...allMakersSkills), tournaments, - similar_makers + similar_makers, + projects: projects.slice(0, 3), }, { id: 441, @@ -216,7 +218,8 @@ export const users: (User & MyProfile)[] = [{ roles: randomItems(3, ...allMakersRoles).map(role => ({ ...role, level: randomItem(...Object.values(RoleLevelEnum)) })), skills: randomItems(7, ...allMakersSkills), tournaments, - similar_makers + similar_makers, + projects: projects.slice(0, 3), }, { id: 422, @@ -254,7 +257,8 @@ export const users: (User & MyProfile)[] = [{ roles: randomItems(3, ...allMakersRoles).map(role => ({ ...role, level: randomItem(...Object.values(RoleLevelEnum)) })), skills: randomItems(7, ...allMakersSkills), tournaments, - similar_makers + similar_makers, + projects: projects.slice(0, 3), }, { id: 511, @@ -292,7 +296,8 @@ export const users: (User & MyProfile)[] = [{ roles: randomItems(3, ...allMakersRoles).map(role => ({ ...role, level: randomItem(...Object.values(RoleLevelEnum)) })), skills: randomItems(7, ...allMakersSkills), tournaments, - similar_makers + similar_makers, + projects: projects.slice(0, 3), }]