From 3eb08cb4d13ecb1aaefd4587fcbd932cceecf87c Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Tue, 23 May 2023 21:39:42 -0700 Subject: [PATCH 01/12] Profiles are sorted via image and introductory text --- .../space-homepage/SpaceLandingPage.tsx | 144 +++++++++++++++++- 1 file changed, 140 insertions(+), 4 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index cf34369..424e572 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -8,6 +8,11 @@ import { useAtom } from "jotai"; import Link from "next/link"; import { useRouter } from "next/router"; +import { useProfileByIdQuery } from "../../generated/graphql"; +import { useAllProfilesOfUserQuery } from "../../generated/graphql"; +import { useUserData } from "../../hooks/useUserData"; +import { useIsLoggedIn } from "../hooks/useIsLoggedIn"; + import { Profile_Role_Enum, useProfileListingsInSpaceQuery, @@ -27,6 +32,8 @@ import { Button, Text } from "../atomic"; import { ProfileCard } from "../ProfileCard"; import { FilterBar } from "./FilterBar"; +import { boolean } from "zod"; +import { GetProfileDocument } from "../../server/generated/serverGraphql"; const FUSE_OPTIONS = { // isCaseSensitive: false, @@ -75,7 +82,7 @@ export function SpaceLandingPage() { }, [selectedTagIds]); const [{ data: profileListingData, fetching: fetchingProfileListings }] = - useProfileListingsInSpaceQuery({ + useProfileListingsInSpaceQuery({ pause: !currentSpace, variables: { where: { @@ -109,17 +116,133 @@ export function SpaceLandingPage() { () => profileListingData?.profile_listing ?? [], [profileListingData?.profile_listing] ); - + console.log(allProfileListings) + console.log(profileListingData) const filteredProfileListings = useMemo(() => { if (searchQuery === "") return shuffleProfiles(allProfileListings, getDayOfYear(new Date())); const searchQueryLower = searchQuery.toLowerCase(); const fuse = new Fuse(allProfileListings, FUSE_OPTIONS); - return fuse.search(searchQueryLower).map((result) => result.item); }, [allProfileListings, searchQuery]); + // loop through filteredProfileListings! + + // idToProfileScore (user's id : how "filled out" their profile is!) + const ids = []; + const profileScores = []; + const idsToProfileScores = new Map(); + + const { userData } = useUserData(); + const [{ data: profileData }] = useAllProfilesOfUserQuery({ + variables: { user_id: userData?.id ?? "" }, + }); + console.log(userData?.id); + + console.log(profileData); + + + + for(let i = 0; i < filteredProfileListings.length; i++){ + idsToProfileScores.set(filteredProfileListings[i].id, 0); + } + + + + + // const [ + // { data: profileData, fetching: fetchingProfileData }, + // refetchProfileById, + // ] = useProfileByIdQuery({ + // variables: { profile_id: profileId ?? "", is_logged_in: isLoggedIn }, + // }); + + {/* Find some way to sort filteredProfileListings here? That way, we can sort the profiles before we sort the tags of each profile? */} + const sortedProfileListings = filteredProfileListings.sort((a, b) => + { + // return -1 IF A should go before B + // return 1 IF A should go after B + // return 0 if NO PREFERENCE + console.log(a.profile.id); + console.log(b.profile.id); + + // make use of filteredProfileListings so we can sort by number of fields filled!? + + console.log(getFullNameOfUser(a.profile.user)); + console.log(getFullNameOfUser(b.profile.user)); + + + console.log("A information:") + console.log(a.__typename); + console.log(a.profile.__typename); + console.log(a.profile_listing_image?.__typename); + console.log(a.profile_listing_image == null); + + console.log("B information:") + console.log(b.profile_listing_image?.__typename); + console.log(b.profile_listing_image == null); + + + console.log("Headlines") + console.log(a.headline); + console.log(b.headline); + + console.log(); + + if(a.profile_listing_image != null && b.profile_listing_image != null){ + // refer to a's and b's headlines for next sort + console.log("Referring to headline length"); + console.log(a.headline.length); + console.log(b.headline.length); + + if(a.headline.length < b.headline.length){ + console.log("A is smaller!"); + return 1; + } else { + console.log("B is smaller!"); + return -1; + } + + } else if(a.profile_listing_image != null){ + console.log("A has a profile listing image, let's prioritize it"); + return -1; + } else { + console.log("B has profile listing image"); + return 1; + } + + + + // const [{ data: profileListingData, fetching }] = useProfileListingQuery({ + // variables: { profile_listing_id: profileListingId }, + // }); + + // const listing = profileData?.profile_by_pk?.profile_listing; + + /* + {listing?.profile_listing_responses.map((response) => { + return ( + + + {response.space_listing_question.title} + + + + ); + })} + */ + + /* + const myProfile = data?.profile.find((p) => p.id === currentProfile.id); + */ + + + // return 1; // for now + } + ) + + const [adminBypass, setAdminBypass] = useAtom(adminBypassAtom); return ( @@ -180,20 +303,33 @@ export function SpaceLandingPage() { items={filteredProfileListings} strategy={rectSortingStrategy} > + {filteredProfileListings.map((listing, idx) => { const fullName = getFullNameOfUser(listing.profile.user); + console.log(fullName); + + // this sorts the tags for each user! const sortedTags = listing.profile_listing_to_space_tags .map((tag) => tag.space_tag) .sort((a, b) => { const aSelected = selectedTagIdsSet.has(a.id); const bSelected = selectedTagIdsSet.has(b.id); + + // const aHasResponses = selectedTagIdsSet.has(a.profileListingImage); if (aSelected && !bSelected) return -1; if (!aSelected && bSelected) return 1; return 0; }); const tagNames = sortedTags?.map((tag) => tag.label) ?? []; + + console.log("Sorted Tags: " , sortedTags); + console.log("PLTST: " , listing.profile_listing_to_space_tags); + console.log("Tag Names: " , tagNames); + + + // console.log(listing.headline); return ( (array: T[], seed: number) { function random(seed: number) { const x = Math.sin(seed++) * 10000; return x - Math.floor(x); -} +} \ No newline at end of file From 41a7ac24dcddb0ceb4a2caa222d63439021d8650 Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Tue, 23 May 2023 23:23:58 -0700 Subject: [PATCH 02/12] Simplified source code --- .../space-homepage/SpaceLandingPage.tsx | 83 +++---------------- 1 file changed, 13 insertions(+), 70 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 424e572..febef51 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -11,7 +11,6 @@ import { useRouter } from "next/router"; import { useProfileByIdQuery } from "../../generated/graphql"; import { useAllProfilesOfUserQuery } from "../../generated/graphql"; import { useUserData } from "../../hooks/useUserData"; -import { useIsLoggedIn } from "../hooks/useIsLoggedIn"; import { Profile_Role_Enum, @@ -116,8 +115,8 @@ export function SpaceLandingPage() { () => profileListingData?.profile_listing ?? [], [profileListingData?.profile_listing] ); - console.log(allProfileListings) - console.log(profileListingData) + + const filteredProfileListings = useMemo(() => { if (searchQuery === "") return shuffleProfiles(allProfileListings, getDayOfYear(new Date())); @@ -138,9 +137,7 @@ export function SpaceLandingPage() { const [{ data: profileData }] = useAllProfilesOfUserQuery({ variables: { user_id: userData?.id ?? "" }, }); - console.log(userData?.id); - - console.log(profileData); + @@ -164,81 +161,32 @@ export function SpaceLandingPage() { // return -1 IF A should go before B // return 1 IF A should go after B // return 0 if NO PREFERENCE - console.log(a.profile.id); - console.log(b.profile.id); - - // make use of filteredProfileListings so we can sort by number of fields filled!? - console.log(getFullNameOfUser(a.profile.user)); - console.log(getFullNameOfUser(b.profile.user)); + // make use of filteredProfileListings so we can sort by number of fields filled!? - console.log("A information:") - console.log(a.__typename); - console.log(a.profile.__typename); - console.log(a.profile_listing_image?.__typename); - console.log(a.profile_listing_image == null); - - console.log("B information:") - console.log(b.profile_listing_image?.__typename); - console.log(b.profile_listing_image == null); - - - console.log("Headlines") - console.log(a.headline); - console.log(b.headline); - console.log(); if(a.profile_listing_image != null && b.profile_listing_image != null){ // refer to a's and b's headlines for next sort - console.log("Referring to headline length"); - console.log(a.headline.length); - console.log(b.headline.length); + - if(a.headline.length < b.headline.length){ - console.log("A is smaller!"); + if(a.headline!.length < b.headline!.length){ + return 1; } else { - console.log("B is smaller!"); + return -1; } } else if(a.profile_listing_image != null){ - console.log("A has a profile listing image, let's prioritize it"); + return -1; } else { - console.log("B has profile listing image"); + return 1; } - - - - // const [{ data: profileListingData, fetching }] = useProfileListingQuery({ - // variables: { profile_listing_id: profileListingId }, - // }); - - // const listing = profileData?.profile_by_pk?.profile_listing; - - /* - {listing?.profile_listing_responses.map((response) => { - return ( - - - {response.space_listing_question.title} - - - - ); - })} - */ - - /* - const myProfile = data?.profile.find((p) => p.id === currentProfile.id); - */ - - - // return 1; // for now + } ) @@ -307,7 +255,7 @@ export function SpaceLandingPage() { {filteredProfileListings.map((listing, idx) => { const fullName = getFullNameOfUser(listing.profile.user); - console.log(fullName); + // this sorts the tags for each user! const sortedTags = listing.profile_listing_to_space_tags @@ -324,12 +272,7 @@ export function SpaceLandingPage() { const tagNames = sortedTags?.map((tag) => tag.label) ?? []; - console.log("Sorted Tags: " , sortedTags); - console.log("PLTST: " , listing.profile_listing_to_space_tags); - console.log("Tag Names: " , tagNames); - - - // console.log(listing.headline); + return ( Date: Mon, 19 Jun 2023 02:32:39 -0700 Subject: [PATCH 03/12] Modified GraphQL queries, changed profile sort algorithm --- mobile/src/lib/gql/from-shared/hasura.graphql | 5 ++ shared/graphql/hasura.graphql | 5 ++ .../space-homepage/SpaceLandingPage.tsx | 77 +++++++++---------- web/lib/gql/from-shared/hasura.graphql | 5 ++ 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/mobile/src/lib/gql/from-shared/hasura.graphql b/mobile/src/lib/gql/from-shared/hasura.graphql index 2352f5b..b7569a8 100644 --- a/mobile/src/lib/gql/from-shared/hasura.graphql +++ b/mobile/src/lib/gql/from-shared/hasura.graphql @@ -289,6 +289,11 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { first_name email } + profile_listing { + profile_listing_responses { + response_html + } + } } } } diff --git a/shared/graphql/hasura.graphql b/shared/graphql/hasura.graphql index 2352f5b..b7569a8 100644 --- a/shared/graphql/hasura.graphql +++ b/shared/graphql/hasura.graphql @@ -289,6 +289,11 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { first_name email } + profile_listing { + profile_listing_responses { + response_html + } + } } } } diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index febef51..92efe80 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -31,7 +31,7 @@ import { Button, Text } from "../atomic"; import { ProfileCard } from "../ProfileCard"; import { FilterBar } from "./FilterBar"; -import { boolean } from "zod"; + import { GetProfileDocument } from "../../server/generated/serverGraphql"; const FUSE_OPTIONS = { @@ -126,65 +126,64 @@ export function SpaceLandingPage() { return fuse.search(searchQueryLower).map((result) => result.item); }, [allProfileListings, searchQuery]); - // loop through filteredProfileListings! - - // idToProfileScore (user's id : how "filled out" their profile is!) + const ids = []; const profileScores = []; - const idsToProfileScores = new Map(); + const { userData } = useUserData(); const [{ data: profileData }] = useAllProfilesOfUserQuery({ variables: { user_id: userData?.id ?? "" }, }); - - - - for(let i = 0; i < filteredProfileListings.length; i++){ - idsToProfileScores.set(filteredProfileListings[i].id, 0); - } - + const idsToProfileScores = useMemo(() => { + let tempCounter = 0; + let tempIdsToProfileScores = new Map(); + + // loop through all profiles in directory + for(let i = 0; i < filteredProfileListings.length; i++){ - // const [ - // { data: profileData, fetching: fetchingProfileData }, - // refetchProfileById, - // ] = useProfileByIdQuery({ - // variables: { profile_id: profileId ?? "", is_logged_in: isLoggedIn }, - // }); + const profileListing = filteredProfileListings[i]?.profile?.profile_listing; - {/* Find some way to sort filteredProfileListings here? That way, we can sort the profiles before we sort the tags of each profile? */} - const sortedProfileListings = filteredProfileListings.sort((a, b) => - { - // return -1 IF A should go before B - // return 1 IF A should go after B - // return 0 if NO PREFERENCE - + if(profileListing && profileListing.profile_listing_responses){ + for (let j = 0; j < profileListing.profile_listing_responses?.length; j++) { + const response = profileListing.profile_listing_responses[j]; + if (response && response.response_html) { + tempCounter += response.response_html.length; + } + } + } - // make use of filteredProfileListings so we can sort by number of fields filled!? - - + const profileHeadline = filteredProfileListings[i]?.headline; + if(profileHeadline && profileHeadline.length > 0){ + console.log(profileHeadline.length); + tempCounter += profileHeadline.length; + } + + tempIdsToProfileScores.set(filteredProfileListings[i].id, tempCounter); + tempCounter = 0; + } + return tempIdsToProfileScores; + }, [filteredProfileListings]); - if(a.profile_listing_image != null && b.profile_listing_image != null){ - // refer to a's and b's headlines for next sort - - if(a.headline!.length < b.headline!.length){ + + const sortedProfileListings = filteredProfileListings.sort((a, b) => + { + if(a.profile_listing_image != null && b.profile_listing_image != null){ - return 1; - } else { - + if(idsToProfileScores.get(a.id) > idsToProfileScores.get(b.id)){ return -1; + } else { + return 1; } } else if(a.profile_listing_image != null){ - - return -1; + return -1; } else { - - return 1; + return 1; } } diff --git a/web/lib/gql/from-shared/hasura.graphql b/web/lib/gql/from-shared/hasura.graphql index 2352f5b..b7569a8 100644 --- a/web/lib/gql/from-shared/hasura.graphql +++ b/web/lib/gql/from-shared/hasura.graphql @@ -289,6 +289,11 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { first_name email } + profile_listing { + profile_listing_responses { + response_html + } + } } } } From 211eafe292da78d414e56bf7ca2e64f063c3d156 Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Mon, 19 Jun 2023 17:00:15 -0700 Subject: [PATCH 04/12] Deleted unused variables --- web/components/space-homepage/SpaceLandingPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 92efe80..d879b77 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -127,8 +127,7 @@ export function SpaceLandingPage() { }, [allProfileListings, searchQuery]); - const ids = []; - const profileScores = []; + const { userData } = useUserData(); From 4a41e92f17478573dde2ca6be671eef7b553dd71 Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Mon, 19 Jun 2023 17:07:45 -0700 Subject: [PATCH 05/12] Modified graphql queries --- mobile/src/lib/gql/from-shared/hasura.graphql | 2 ++ shared/graphql/hasura.graphql | 2 ++ web/components/space-homepage/SpaceLandingPage.tsx | 2 +- web/lib/gql/from-shared/hasura.graphql | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/src/lib/gql/from-shared/hasura.graphql b/mobile/src/lib/gql/from-shared/hasura.graphql index b7569a8..61f691a 100644 --- a/mobile/src/lib/gql/from-shared/hasura.graphql +++ b/mobile/src/lib/gql/from-shared/hasura.graphql @@ -290,7 +290,9 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { email } profile_listing { + id profile_listing_responses { + id response_html } } diff --git a/shared/graphql/hasura.graphql b/shared/graphql/hasura.graphql index b7569a8..61f691a 100644 --- a/shared/graphql/hasura.graphql +++ b/shared/graphql/hasura.graphql @@ -290,7 +290,9 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { email } profile_listing { + id profile_listing_responses { + id response_html } } diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index d879b77..f4c23ee 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -157,7 +157,7 @@ export function SpaceLandingPage() { const profileHeadline = filteredProfileListings[i]?.headline; if(profileHeadline && profileHeadline.length > 0){ - console.log(profileHeadline.length); + tempCounter += profileHeadline.length; } diff --git a/web/lib/gql/from-shared/hasura.graphql b/web/lib/gql/from-shared/hasura.graphql index b7569a8..61f691a 100644 --- a/web/lib/gql/from-shared/hasura.graphql +++ b/web/lib/gql/from-shared/hasura.graphql @@ -290,7 +290,9 @@ query ProfileListingsInSpace($where: profile_listing_bool_exp) { email } profile_listing { + id profile_listing_responses { + id response_html } } From 5f22f14b0bced6a1467fd0a56e957334d33556fd Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Mon, 19 Jun 2023 19:49:38 -0700 Subject: [PATCH 06/12] Resolved ESLint errors --- web/components/space-homepage/SpaceLandingPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index f4c23ee..0b73db4 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -10,7 +10,6 @@ import { useRouter } from "next/router"; import { useProfileByIdQuery } from "../../generated/graphql"; import { useAllProfilesOfUserQuery } from "../../generated/graphql"; -import { useUserData } from "../../hooks/useUserData"; import { Profile_Role_Enum, @@ -20,6 +19,7 @@ import { useCurrentProfile } from "../../hooks/useCurrentProfile"; import { useCurrentSpace } from "../../hooks/useCurrentSpace"; import { usePrivacySettings } from "../../hooks/usePrivacySettings"; import { useQueryParam } from "../../hooks/useQueryParam"; +import { useUserData } from "../../hooks/useUserData"; import { adminBypassAtom, searchQueryAtom, @@ -32,8 +32,6 @@ import { ProfileCard } from "../ProfileCard"; import { FilterBar } from "./FilterBar"; -import { GetProfileDocument } from "../../server/generated/serverGraphql"; - const FUSE_OPTIONS = { // isCaseSensitive: false, // includeScore: false, @@ -139,7 +137,7 @@ export function SpaceLandingPage() { const idsToProfileScores = useMemo(() => { let tempCounter = 0; - let tempIdsToProfileScores = new Map(); + const tempIdsToProfileScores = new Map(); // loop through all profiles in directory for(let i = 0; i < filteredProfileListings.length; i++){ From ad7cfb59d95f16fc052050abd2c9c6181861878b Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Tue, 25 Jul 2023 22:43:02 -0700 Subject: [PATCH 07/12] Optimizations for profile scoring --- .../space-homepage/SpaceLandingPage.tsx | 93 +++++++++---------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 0b73db4..8b61400 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -79,7 +79,7 @@ export function SpaceLandingPage() { }, [selectedTagIds]); const [{ data: profileListingData, fetching: fetchingProfileListings }] = - useProfileListingsInSpaceQuery({ + useProfileListingsInSpaceQuery({ pause: !currentSpace, variables: { where: { @@ -114,7 +114,6 @@ export function SpaceLandingPage() { [profileListingData?.profile_listing] ); - const filteredProfileListings = useMemo(() => { if (searchQuery === "") return shuffleProfiles(allProfileListings, getDayOfYear(new Date())); @@ -124,39 +123,56 @@ export function SpaceLandingPage() { return fuse.search(searchQueryLower).map((result) => result.item); }, [allProfileListings, searchQuery]); - - - - const { userData } = useUserData(); const [{ data: profileData }] = useAllProfilesOfUserQuery({ variables: { user_id: userData?.id ?? "" }, }); - - const idsToProfileScores = useMemo(() => { let tempCounter = 0; const tempIdsToProfileScores = new Map(); - - // loop through all profiles in directory - for(let i = 0; i < filteredProfileListings.length; i++){ - - const profileListing = filteredProfileListings[i]?.profile?.profile_listing; - if(profileListing && profileListing.profile_listing_responses){ - for (let j = 0; j < profileListing.profile_listing_responses?.length; j++) { + + for (let i = 0; i < filteredProfileListings.length; i++) { + const profileListing = + filteredProfileListings[i]?.profile?.profile_listing; + + if (profileListing && profileListing.profile_listing_responses) { + for ( + let j = 0; + j < profileListing.profile_listing_responses?.length; + j++ + ) { const response = profileListing.profile_listing_responses[j]; if (response && response.response_html) { - tempCounter += response.response_html.length; + + + let responseArray = response.response_html.split(" "); + + if (responseArray.length >= 10) { + tempCounter += 4; + } else if (responseArray.length >= 1) { + tempCounter += 2; + } } } } + const profileHeadline = filteredProfileListings[i]?.headline; - if(profileHeadline && profileHeadline.length > 0){ - - tempCounter += profileHeadline.length; + if (profileHeadline && profileHeadline.length > 0) { + let headlineArray = profileHeadline.split(" "); + + if (headlineArray.length >= 3) { + tempCounter += 5; + } else if (headlineArray.length >= 1) { + tempCounter += 3; + } + } + + + if (filteredProfileListings[i].profile_listing_image != null) { + tempCounter += 10; } tempIdsToProfileScores.set(filteredProfileListings[i].id, tempCounter); @@ -165,27 +181,15 @@ export function SpaceLandingPage() { return tempIdsToProfileScores; }, [filteredProfileListings]); - - - const sortedProfileListings = filteredProfileListings.sort((a, b) => - { - if(a.profile_listing_image != null && b.profile_listing_image != null){ - - if(idsToProfileScores.get(a.id) > idsToProfileScores.get(b.id)){ - return -1; - } else { - return 1; - } - - } else if(a.profile_listing_image != null){ - return -1; - } else { - return 1; - } - + const sortedProfileListings = filteredProfileListings.sort((a, b) => { + if (idsToProfileScores.get(a.id) > idsToProfileScores.get(b.id)) { + return -1; + } else { + return 1; } - ) + }); + console.log(idsToProfileScores); const [adminBypass, setAdminBypass] = useAtom(adminBypassAtom); @@ -244,31 +248,26 @@ export function SpaceLandingPage() { }} > - - {filteredProfileListings.map((listing, idx) => { + {sortedProfileListings.map((listing, idx) => { const fullName = getFullNameOfUser(listing.profile.user); - - // this sorts the tags for each user! const sortedTags = listing.profile_listing_to_space_tags .map((tag) => tag.space_tag) .sort((a, b) => { const aSelected = selectedTagIdsSet.has(a.id); const bSelected = selectedTagIdsSet.has(b.id); + - // const aHasResponses = selectedTagIdsSet.has(a.profileListingImage); if (aSelected && !bSelected) return -1; if (!aSelected && bSelected) return 1; return 0; }); const tagNames = sortedTags?.map((tag) => tag.label) ?? []; - - return ( (array: T[], seed: number) { function random(seed: number) { const x = Math.sin(seed++) * 10000; return x - Math.floor(x); -} \ No newline at end of file +} From 0f5eb25781ac28b7112c4c23feabd49c3f3362e7 Mon Sep 17 00:00:00 2001 From: pravirchugh Date: Tue, 25 Jul 2023 23:03:02 -0700 Subject: [PATCH 08/12] Fixed additional ESLint errors --- web/components/space-homepage/SpaceLandingPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 8b61400..1292d29 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -147,7 +147,7 @@ export function SpaceLandingPage() { if (response && response.response_html) { - let responseArray = response.response_html.split(" "); + const responseArray = response.response_html.split(" "); if (responseArray.length >= 10) { tempCounter += 4; @@ -161,7 +161,7 @@ export function SpaceLandingPage() { const profileHeadline = filteredProfileListings[i]?.headline; if (profileHeadline && profileHeadline.length > 0) { - let headlineArray = profileHeadline.split(" "); + const headlineArray = profileHeadline.split(" "); if (headlineArray.length >= 3) { tempCounter += 5; From 68ee0fd2823abf36e423141838098738798a0777 Mon Sep 17 00:00:00 2001 From: Max Wu Date: Wed, 2 Aug 2023 00:40:16 -0700 Subject: [PATCH 09/12] Add seeded random shuffling --- .../space-homepage/SpaceLandingPage.tsx | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 1292d29..77800e0 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -2,7 +2,7 @@ import { useMemo, useState } from "react"; import { closestCenter, DndContext, MeasuringStrategy } from "@dnd-kit/core"; import { rectSortingStrategy, SortableContext } from "@dnd-kit/sortable"; -import { getDayOfYear } from "date-fns"; +import { addDays, format, getDayOfYear } from "date-fns"; import Fuse from "fuse.js"; import { useAtom } from "jotai"; import Link from "next/link"; @@ -10,7 +10,6 @@ import { useRouter } from "next/router"; import { useProfileByIdQuery } from "../../generated/graphql"; import { useAllProfilesOfUserQuery } from "../../generated/graphql"; - import { Profile_Role_Enum, useProfileListingsInSpaceQuery, @@ -32,6 +31,39 @@ import { ProfileCard } from "../ProfileCard"; import { FilterBar } from "./FilterBar"; +const todayDateString = format(addDays(new Date(), 4), "yyyy-MM-dd"); +console.log(todayDateString); + +class SeededRNG { + seed: number; + constructor(seed = 123456789) { + this.seed = seed; + } + + nextFloat() { + this.seed = (this.seed * 16807) % 2147483647; + return (this.seed - 1) / 2147483646; + } +} + +// Convert an array of strings to a number +function arrayToSeed(arr: string[]) { + let hash = 0; + const string = arr.join(","); + for (let i = 0; i < string.length; i++) { + const char = string.charCodeAt(i); + hash = (hash << 5) - hash + char; + hash |= 0; // Convert to 32bit integer + } + return Math.abs(hash); +} + +function generateRandomVal(arr: string[]) { + const seed = arrayToSeed(arr); + const rng = new SeededRNG(seed); + return rng.nextFloat(); +} + const FUSE_OPTIONS = { // isCaseSensitive: false, // includeScore: false, @@ -110,7 +142,7 @@ export function SpaceLandingPage() { }); const allProfileListings = useMemo( - () => profileListingData?.profile_listing ?? [], + () => [...(profileListingData?.profile_listing ?? [])], [profileListingData?.profile_listing] ); @@ -132,7 +164,6 @@ export function SpaceLandingPage() { let tempCounter = 0; const tempIdsToProfileScores = new Map(); - for (let i = 0; i < filteredProfileListings.length; i++) { const profileListing = filteredProfileListings[i]?.profile?.profile_listing; @@ -145,8 +176,6 @@ export function SpaceLandingPage() { ) { const response = profileListing.profile_listing_responses[j]; if (response && response.response_html) { - - const responseArray = response.response_html.split(" "); if (responseArray.length >= 10) { @@ -158,7 +187,6 @@ export function SpaceLandingPage() { } } - const profileHeadline = filteredProfileListings[i]?.headline; if (profileHeadline && profileHeadline.length > 0) { const headlineArray = profileHeadline.split(" "); @@ -170,11 +198,16 @@ export function SpaceLandingPage() { } } - if (filteredProfileListings[i].profile_listing_image != null) { tempCounter += 10; } + tempCounter += + 15 * + generateRandomVal([ + todayDateString, + filteredProfileListings[i]?.id ?? "", + ]); tempIdsToProfileScores.set(filteredProfileListings[i].id, tempCounter); tempCounter = 0; } @@ -254,14 +287,12 @@ export function SpaceLandingPage() { {sortedProfileListings.map((listing, idx) => { const fullName = getFullNameOfUser(listing.profile.user); - const sortedTags = listing.profile_listing_to_space_tags .map((tag) => tag.space_tag) .sort((a, b) => { const aSelected = selectedTagIdsSet.has(a.id); const bSelected = selectedTagIdsSet.has(b.id); - if (aSelected && !bSelected) return -1; if (!aSelected && bSelected) return 1; return 0; From 39cb73d50445b189d4e2278fe8a41c2f580e521a Mon Sep 17 00:00:00 2001 From: Max Wu Date: Wed, 2 Aug 2023 00:42:06 -0700 Subject: [PATCH 10/12] Remove console logs --- web/components/space-homepage/SpaceLandingPage.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/web/components/space-homepage/SpaceLandingPage.tsx b/web/components/space-homepage/SpaceLandingPage.tsx index 77800e0..0bd1b58 100644 --- a/web/components/space-homepage/SpaceLandingPage.tsx +++ b/web/components/space-homepage/SpaceLandingPage.tsx @@ -32,7 +32,6 @@ import { ProfileCard } from "../ProfileCard"; import { FilterBar } from "./FilterBar"; const todayDateString = format(addDays(new Date(), 4), "yyyy-MM-dd"); -console.log(todayDateString); class SeededRNG { seed: number; @@ -222,8 +221,6 @@ export function SpaceLandingPage() { } }); - console.log(idsToProfileScores); - const [adminBypass, setAdminBypass] = useAtom(adminBypassAtom); return ( From 63c9d67b5457b7e22a44e34b27d0a3503e6083e1 Mon Sep 17 00:00:00 2001 From: Max Wu Date: Tue, 22 Aug 2023 00:57:04 -0700 Subject: [PATCH 11/12] Add email domain whitelist functionality --- hasura/.gitignore | 3 +- .../tables/public_public_space.yaml | 14 +- .../down.sql | 11 ++ .../up.sql | 9 ++ mobile/src/lib/gql/from-shared/hasura.graphql | 1 + shared/graphql/hasura.graphql | 1 + web/components/admin/SetPrivacySettings.tsx | 1 + .../space-homepage/SpaceLandingPage.tsx | 123 +++++++++--------- web/graphql-admin.schema.json | 102 +++++++++++++++ web/graphql.schema.json | 108 +++++++++++++++ web/hooks/usePrivacySettings.ts | 3 +- web/lib/gql/from-shared/hasura.graphql | 1 + web/lib/spaceAttributes.ts | 2 + web/pages/api/invite/joinProgram.ts | 23 ++++ .../space/[slug]/join/[inviteLinkId].tsx | 21 +++ .../space/[slug]/profile/[profileId].tsx | 2 + web/pages/space/[slug]/report/[profileId].tsx | 6 - web/server/adminHasura.graphql | 12 ++ 18 files changed, 367 insertions(+), 76 deletions(-) create mode 100644 hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/down.sql create mode 100644 hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/up.sql diff --git a/hasura/.gitignore b/hasura/.gitignore index 2eea525..7748252 100644 --- a/hasura/.gitignore +++ b/hasura/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +.env +/db_data \ No newline at end of file diff --git a/hasura/metadata/databases/mentorcenter/tables/public_public_space.yaml b/hasura/metadata/databases/mentorcenter/tables/public_public_space.yaml index 09c31bd..258f712 100644 --- a/hasura/metadata/databases/mentorcenter/tables/public_public_space.yaml +++ b/hasura/metadata/databases/mentorcenter/tables/public_public_space.yaml @@ -5,18 +5,18 @@ select_permissions: - role: public permission: columns: + - deleted + - domainWhitelist - name - slug - id - filter: - deleted: - _eq: false + filter: {} - role: user permission: columns: + - id - name - slug - - id - filter: - deleted: - _eq: false + - deleted + - domainWhitelist + filter: {} diff --git a/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/down.sql b/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/down.sql new file mode 100644 index 0000000..7167b14 --- /dev/null +++ b/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/down.sql @@ -0,0 +1,11 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- DROP VIEW "public"."public_space"; +-- +-- CREATE OR REPLACE VIEW "public"."public_space" AS +-- SELECT space.id, +-- space.name, +-- space.slug, +-- space.deleted, +-- space.attributes->>'domainWhitelist' as "domainWhitelist" +-- FROM space; diff --git a/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/up.sql b/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/up.sql new file mode 100644 index 0000000..25a1263 --- /dev/null +++ b/hasura/migrations/mentorcenter/1692689421764_add_domain_whitelist_to_public_view/up.sql @@ -0,0 +1,9 @@ +DROP VIEW "public"."public_space"; + +CREATE OR REPLACE VIEW "public"."public_space" AS + SELECT space.id, + space.name, + space.slug, + space.deleted, + space.attributes->>'domainWhitelist' as "domainWhitelist" + FROM space; diff --git a/mobile/src/lib/gql/from-shared/hasura.graphql b/mobile/src/lib/gql/from-shared/hasura.graphql index 61f691a..015b466 100644 --- a/mobile/src/lib/gql/from-shared/hasura.graphql +++ b/mobile/src/lib/gql/from-shared/hasura.graphql @@ -663,6 +663,7 @@ query PublicSpaceBySlug($slug: String!) { public_space(where: { slug: { _eq: $slug } }) { id name + domainWhitelist slug } } diff --git a/shared/graphql/hasura.graphql b/shared/graphql/hasura.graphql index 61f691a..015b466 100644 --- a/shared/graphql/hasura.graphql +++ b/shared/graphql/hasura.graphql @@ -663,6 +663,7 @@ query PublicSpaceBySlug($slug: String!) { public_space(where: { slug: { _eq: $slug } }) { id name + domainWhitelist slug } } diff --git a/web/components/admin/SetPrivacySettings.tsx b/web/components/admin/SetPrivacySettings.tsx index e914359..00ddbbc 100644 --- a/web/components/admin/SetPrivacySettings.tsx +++ b/web/components/admin/SetPrivacySettings.tsx @@ -67,6 +67,7 @@ export function SetPrivacySettings() { }); }} /> +