2021-05-27 11:20:34 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Styles from "~/common/styles";
|
|
|
|
import * as Typography from "~/components/system/components/Typography";
|
|
|
|
import * as Strings from "~/common/strings";
|
2021-07-15 19:32:18 +03:00
|
|
|
import * as Constants from "~/common/constants";
|
2021-07-26 19:42:53 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2021-05-27 11:20:34 +03:00
|
|
|
|
|
|
|
import { ButtonPrimary, ButtonTertiary } from "~/components/system/components/Buttons";
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
import { useFollowProfileHandler } from "~/common/hooks";
|
|
|
|
|
|
|
|
const STYLES_CONTAINER = (theme) => css`
|
2021-07-26 19:42:53 +03:00
|
|
|
width: 100%;
|
|
|
|
position: relative;
|
|
|
|
background-color: ${theme.semantic.bgLight};
|
|
|
|
box-shadow: 0 0 0 0.5px ${theme.semantic.bgGrayLight}, ${theme.shadow.lightSmall};
|
|
|
|
border-radius: 16px;
|
|
|
|
padding: 24px 16px 16px;
|
|
|
|
${Styles.VERTICAL_CONTAINER_CENTERED}
|
2021-05-27 11:20:34 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_PROFILE_PREVIEW = (theme) => css`
|
|
|
|
height: 120px;
|
|
|
|
width: 120px;
|
|
|
|
border-radius: 8px;
|
|
|
|
object-fit: cover;
|
|
|
|
@media (max-width: ${theme.sizes.mobile}px) {
|
|
|
|
height: 104px;
|
|
|
|
width: 104px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default function ProfilePreviewBlock({ onAction, viewer, profile }) {
|
|
|
|
const { handleFollow, isFollowing } = useFollowProfileHandler({
|
|
|
|
onAction,
|
|
|
|
viewer,
|
|
|
|
user: profile,
|
|
|
|
});
|
|
|
|
|
|
|
|
const isOwner = viewer?.id === profile.id;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div css={STYLES_CONTAINER}>
|
2021-07-26 19:42:53 +03:00
|
|
|
<img
|
|
|
|
css={STYLES_PROFILE_PREVIEW}
|
|
|
|
src={profile.data.photo}
|
|
|
|
alt={`${profile.username}`}
|
|
|
|
onError={(e) => (e.target.src = Constants.profileDefaultPicture)}
|
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<Typography.H5 style={{ marginTop: 17 }}>{profile.username}</Typography.H5>
|
|
|
|
</div>
|
2021-05-27 11:20:34 +03:00
|
|
|
|
2021-07-26 19:42:53 +03:00
|
|
|
<div
|
|
|
|
css={Styles.HORIZONTAL_CONTAINER}
|
|
|
|
style={{ marginTop: 6, color: Constants.semantic.textGray }}
|
|
|
|
>
|
|
|
|
<div css={Styles.HORIZONTAL_CONTAINER} style={{ marginLeft: 16 }}>
|
|
|
|
<SVG.Layers height={16} width={16} />
|
|
|
|
<Typography.P3 color="textGray" style={{ marginLeft: 4 }}>
|
|
|
|
{profile.slateCount} {Strings.pluralize("collection", profile.slateCount)}
|
|
|
|
</Typography.P3>
|
2021-05-27 11:20:34 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-26 19:42:53 +03:00
|
|
|
|
|
|
|
<Typography.P2
|
|
|
|
color="gray"
|
|
|
|
nbrOflines={1}
|
2021-08-29 04:36:48 +03:00
|
|
|
style={{ marginTop: 8, textIndent: 8, opacity: profile?.body ? 1 : 0 }}
|
2021-07-26 19:42:53 +03:00
|
|
|
>
|
2021-08-29 04:36:48 +03:00
|
|
|
{profile?.body || "No Description"}
|
2021-07-26 19:42:53 +03:00
|
|
|
</Typography.P2>
|
|
|
|
|
|
|
|
{!isOwner &&
|
|
|
|
(isFollowing ? (
|
|
|
|
<ButtonTertiary
|
|
|
|
style={{ marginTop: 16 }}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
handleFollow(profile.id);
|
|
|
|
}}
|
|
|
|
full
|
|
|
|
>
|
|
|
|
Following
|
|
|
|
</ButtonTertiary>
|
|
|
|
) : (
|
|
|
|
<ButtonPrimary
|
|
|
|
style={{ marginTop: 16 }}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
handleFollow(profile.id);
|
|
|
|
}}
|
|
|
|
full
|
|
|
|
>
|
|
|
|
Follow
|
|
|
|
</ButtonPrimary>
|
|
|
|
))}
|
2021-05-27 11:20:34 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|