Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan-cp committed Apr 2, 2024
1 parent 80328bb commit 5ea4db5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 49 deletions.
1 change: 0 additions & 1 deletion apps/web/src/components/Feed/SuggestedProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ const StyledSuggestedProfileCard = styled(GalleryLink)`
@media only screen and ${breakpoints.desktop} {
min-width: 200px;
min-height: 183px;
}
`;

Expand Down
44 changes: 3 additions & 41 deletions apps/web/src/components/Search/SearchDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { useMemo } from 'react';
import { graphql, useLazyLoadQuery } from 'react-relay';

import { SearchDefaultQuery } from '~/generated/SearchDefaultQuery.graphql';
import { CmsTypes } from '~/scenes/ContentPages/cms_types';

import { HStack, VStack } from '../core/Spacer/Stack';
import { VStack } from '../core/Spacer/Stack';
import SearchFeaturedCollectionSection from './SearchFeaturedCollectionSection';
import SearchSuggestedUsersSection from './SearchSuggestedUsersSection';
import SearchResultsHeader from './SearchResultsHeader';
import { SearchItemType } from './types';
import UserSearchResult from './User/UserSearchResult';
import SearchDefaultTrendingCuratorsSection from './SearchDefaultTrendingCurators';

type Props = {
Expand All @@ -23,55 +20,20 @@ export default function SearchDefault({ variant = 'default', onSelect, pageConte
const query = useLazyLoadQuery<SearchDefaultQuery>(
graphql`
query SearchDefaultQuery {
viewer @required(action: THROW) {
... on Viewer {
suggestedUsers(first: 2) @required(action: THROW) {
__typename
edges {
node {
__typename
... on GalleryUser {
id
__typename
}
...SuggestedProfileCardFragment
}
}
}
}
}
...SearchSuggestedUsersSectionFollowFragment
...SearchSuggestedUsersSectionFragment
...SearchDefaultTrendingCuratorsSectionFragment
}
`,
{}
);

// map edge nodes to an array of GalleryUsers
const nonNullProfiles = useMemo(() => {
const users = [];

for (const edge of query.viewer?.suggestedUsers?.edges ?? []) {
if (edge?.node) {
users.push(edge.node);
}
}

return users;
}, [query.viewer?.suggestedUsers?.edges]);

if (query.viewer?.suggestedUsers?.__typename !== 'UsersConnection') {
return null;
}

const { featuredProfiles } = pageContent ?? [];

const featuredProfilesData = featuredProfiles?.slice(0, 2);

return (
<VStack>
<SearchFeaturedCollectionSection profiles={featuredProfilesData} variant={variant} />
<SearchSuggestedUsersSection profiles={nonNullProfiles} variant={variant} />
<SearchSuggestedUsersSection queryRef={query} variant={variant} />
<SearchDefaultTrendingCuratorsSection
queryRef={query}
variant={variant}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { CmsTypes } from '~/scenes/ContentPages/cms_types';

import { HStack } from '../core/Spacer/Stack';
import SearchFeaturedProfile from './SearchFeaturedProfile';
import SearchResultsHeader from './SearchResultsHeader';

type Props = {
profiles: [];
profiles: CmsTypes.FeaturedProfile[];
variant?: 'default' | 'compact';
};

Expand Down
46 changes: 40 additions & 6 deletions apps/web/src/components/Search/SearchSuggestedUsersSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { graphql, useFragment } from 'react-relay';
import { useMemo } from 'react';

import { SearchSuggestedUsersSectionFragment$key } from '~/generated/SearchSuggestedUsersSectionFragment.graphql';
import { HStack } from '../core/Spacer/Stack';
Expand All @@ -7,29 +8,62 @@ import SuggestedProfileCard from '../Feed/SuggestedProfileCard';

type Props = {
queryRef: SearchSuggestedUsersSectionFragment$key;
profiles: any[];
variant?: 'default' | 'compact';
};

export default function SearchSuggestedUsersSection({ queryRef, profiles, variant }: Props) {
export default function SearchSuggestedUsersSection({ queryRef, variant }: Props) {
const query = useFragment(
graphql`
fragment SearchSuggestedUsersSectionFollowFragment on Query {
fragment SearchSuggestedUsersSectionFragment on Query {
viewer @required(action: THROW) {
... on Viewer {
suggestedUsers(first: 2) @required(action: THROW) {
__typename
edges {
node {
__typename
... on GalleryUser {
id
__typename
}
...SuggestedProfileCardFragment
}
}
}
}
}
...SuggestedProfileCardFollowFragment
}
`,
queryRef
);

if (!profiles) {
return;
// map edge nodes to an array of GalleryUsers
const nonNullProfiles = useMemo(() => {
const users = [];

for (const edge of query.viewer?.suggestedUsers?.edges ?? []) {
if (edge?.node) {
users.push(edge.node);
}
}

return users;
}, [query.viewer?.suggestedUsers?.edges]);

if (query.viewer?.suggestedUsers?.__typename !== 'UsersConnection') {
return null;
}
if (!nonNullProfiles) {
return null;
}

return (
<>
<SearchResultsHeader variant={variant}>Suggested Collectors and Creators</SearchResultsHeader>
<HStack justify="space-between" style={{ paddingBottom: '12px' }}>
{profiles?.map((profile) => (
{nonNullProfiles?.map((profile) => (
<SuggestedProfileCard
key={profile.id}
userRef={profile}
Expand Down

0 comments on commit 5ea4db5

Please sign in to comment.