Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redesign the community card in home page #10040

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

.CommunityPreviewCard.Card {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px;
flex-direction: row;
gap: 12px;
padding: 8px;
width: 392px;
border-radius: 6px;
border-radius: 12px;
min-height: 78px;
position: relative;
flex-wrap: wrap;

@include smallInclusive {
min-height: 144px;
min-height: 100px;
max-width: 200px;
min-width: 200px;
}
.CommunityAvatar {
margin-top: 12px !important;
}

.card-top {
align-items: center;
Expand All @@ -21,6 +27,7 @@

.CommunityAvatar {
margin-right: 8px;
flex-direction: row;
}
}

Expand All @@ -29,6 +36,7 @@
justify-content: center;
align-content: center;
border: 1px solid $neutral-700;
flex-direction: column;

.explore-label {
width: 100%;
Expand All @@ -45,10 +53,24 @@

.thread-counts {
margin-top: auto;
padding-top: 12px;
padding-top: 4px;
display: flex;
gap: 8px;
gap: 2px;
align-items: center;
color: $neutral-500;
}

.community-name {
display: flex;
flex-direction: column;
}

.join-community {
position: absolute;
right: 0;

@include smallInclusive {
position: relative;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { ChainBase } from '@hicommonwealth/shared';
import useUserStore from 'client/scripts/state/ui/user';
import Permissions from 'client/scripts/utils/Permissions';
import useJoinCommunity from 'client/scripts/views/components/SublayoutHeader/useJoinCommunity';
import { CWButton } from 'client/scripts/views/components/component_kit/new_designs/CWButton';
import clsx from 'clsx';
import React from 'react';
import { CWIcon } from 'views/components/component_kit/cw_icons/cw_icon';
Expand All @@ -6,15 +11,30 @@ import { CWCard } from '../../../../components/component_kit/cw_card';
import { CWCommunityAvatar } from '../../../../components/component_kit/cw_community_avatar';
import { CWText } from '../../../../components/component_kit/cw_text';
import './CommunityPreviewCard.scss';

type CommunityPreviewCardProps = {
community?: { name: string; icon_url: string };
community?: {
name: string;
icon_url: string;
id: string;
base: ChainBase;
};
monthlyThreadCount?: number;
isCommunityMember?: boolean;
hasNewContent?: boolean;
onClick?: () => any;
isExploreMode?: boolean;
};
} & (
| { isExploreMode: true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz move community?: from above here

| {
isExploreMode?: false;
community: NonNullable<{
name: string;
icon_url: string;
id: string;
base: ChainBase;
}>;
}
);

const CommunityPreviewCard = ({
community,
Expand All @@ -24,46 +44,97 @@ const CommunityPreviewCard = ({
onClick,
isExploreMode,
}: CommunityPreviewCardProps) => {
const user = useUserStore();
const userAddress = user.addresses?.[0];
const isJoined = Permissions.isCommunityMember(community?.id);
const { linkSpecificAddressToSpecificCommunity } = useJoinCommunity();

const handleJoinButtonClick = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();

void (async () => {
try {
if (community) {
await linkSpecificAddressToSpecificCommunity({
address: userAddress?.address,
community: {
id: community.id,
base: community.base,
iconUrl: community.icon_url,
name: community.name,
},
});
}
} catch (error) {
console.error('Failed to join community:', error);
}
})();
};

return (
<CWCard
className={clsx('CommunityPreviewCard', { isExploreMode })}
elevation="elevation-1"
interactive
onClick={(e) => {
e.preventDefault();
onClick?.();
}}
>
{isExploreMode ? (
<CWText type="h4" className="explore-label">
Explore communities <CWIcon iconName="arrowRightPhosphor" />
</CWText>
) : (
<>
<CWCommunityAvatar
community={{
name: community?.name || '',
iconUrl: community?.icon_url || '',
}}
size="large"
/>
{community?.name && (
<CWText type="h4" fontWeight="medium">
{community?.name}
</CWText>
)}
<div className="thread-counts">
<CWIcon iconName="notepad" weight="light" />
<CWText className="card-subtext" type="b2" fontWeight="medium">
{monthlyThreadCount || 0}
</CWText>
{isCommunityMember && hasNewContent && (
<CWTag type="new" label="New" />
)}
</div>
</>
)}
</CWCard>
<>
<CWCard
className={clsx('CommunityPreviewCard', { isExploreMode })}
elevation="elevation-1"
interactive
onClick={(e) => {
e.preventDefault();
onClick?.();
}}
>
{isExploreMode ? (
<CWText type="h4" className="explore-label">
Explore communities <CWIcon iconName="arrowRightPhosphor" />
</CWText>
) : (
<>
<CWCommunityAvatar
community={{
name: community?.name || '',
iconUrl: community?.icon_url || '',
}}
size="large"
/>
<div className="community-name">
{community?.name && (
<CWText type="h4" fontWeight="medium">
{community?.name}
</CWText>
)}

<div className="thread-counts">
<CWIcon iconName="notepad" weight="light" />
<CWText className="card-subtext" type="b2" fontWeight="medium">
{`${monthlyThreadCount || 0}/m`}
</CWText>
{isCommunityMember && hasNewContent && (
<CWTag type="new" label="New" />
)}
</div>
</div>

<div className="join-community">
<CWButton
containerClassName={clsx('join-btn', {
isJoined,
})}
buttonWidth="narrow"
buttonHeight="sm"
buttonType="tertiary"
label={!isJoined ? 'Join Community' : 'Joined'}
{...(isJoined && {
iconLeft: 'checkCircleFilled',
iconLeftWeight: 'fill',
})}
disabled={isJoined}
onClick={handleJoinButtonClick}
/>
</div>
</>
)}
</CWCard>
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const TrendingCommunitiesPreview = () => {
community={{
name: sortedCommunity.community.name || '',
icon_url: sortedCommunity.community.icon_url || '',
id: sortedCommunity.community.id || '',
base: sortedCommunity.community.base || '',
}}
monthlyThreadCount={
sortedCommunity.community.last_30_day_thread_count || 0
Expand Down
Loading