Skip to content

Commit 5baa323

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Author to use useOvermind (codesandbox#2566)
* 🔨 Switch Author to use useOvermind * Use subscriptionSince * Fix types
1 parent d5f1897 commit 5baa323

File tree

3 files changed

+63
-55
lines changed

3 files changed

+63
-55
lines changed

‎packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Author.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
import React from 'react';
2-
import { profileUrl } from '@codesandbox/common/lib/utils/url-generator';
31
import { UserWithAvatar } from '@codesandbox/common/lib/components/UserWithAvatar';
2+
import { User } from '@codesandbox/common/lib/types';
3+
import { profileUrl } from '@codesandbox/common/lib/utils/url-generator';
4+
import React, { FunctionComponent } from 'react';
5+
46
import { Item, UserLink } from './elements';
57

6-
export const Author = ({ author: { username, avatarUrl, subscription } }) => (
8+
type Props = {
9+
author: User;
10+
};
11+
export const Author: FunctionComponent<Props> = ({
12+
author: { username, avatarUrl, subscriptionSince },
13+
}) => (
714
<Item>
815
<UserLink title={username} to={profileUrl(username)}>
916
<UserWithAvatar
1017
username={username}
1118
avatarUrl={avatarUrl}
12-
subscriptionSince={subscription && subscription.since}
19+
subscriptionSince={subscriptionSince}
1320
/>
1421
</UserLink>
1522
</Item>
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import React from 'react';
21
import { format } from 'date-fns';
2+
import React, { FunctionComponent } from 'react';
33
import StarIcon from 'react-icons/lib/go/star';
4+
45
import Tooltip from '../Tooltip';
56

67
import { Container } from './elements';
78

8-
interface PatronStarProps {
9-
subscriptionSince: number | Date;
9+
type Props = {
1010
style?: React.CSSProperties;
11-
}
11+
subscriptionSince: string | number | Date;
12+
};
1213

13-
export function PatronStar({ subscriptionSince, ...props }: PatronStarProps) {
14-
return (
15-
<Tooltip
16-
content={`Patron since ${format(
17-
new Date(subscriptionSince),
18-
'MMM yyyy'
19-
)}`}
20-
>
21-
<Container>
22-
<StarIcon {...props} />
23-
</Container>
24-
</Tooltip>
25-
);
26-
}
14+
export const PatronStar: FunctionComponent<Props> = ({
15+
subscriptionSince,
16+
...props
17+
}) => (
18+
<Tooltip
19+
content={`Patron since ${format(new Date(subscriptionSince), 'MMM yyyy')}`}
20+
>
21+
<Container>
22+
<StarIcon {...props} />
23+
</Container>
24+
</Tooltip>
25+
);
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
1-
import React from 'react';
1+
import React, { ComponentProps, FunctionComponent } from 'react';
22

33
import ContributorHelm from '../ContributorsBadge';
44
import { PatronStar } from '../PatronStar';
5+
56
import { CenteredText, AuthorName, Image, Names, Username } from './elements';
67

7-
export interface UserWithAvatarProps {
8+
type Props = ComponentProps<typeof CenteredText> & {
89
avatarUrl: string;
910
username: string;
1011
name?: string;
1112
hideBadge?: boolean;
12-
subscriptionSince?: number | Date;
1313
useBigName?: boolean;
14-
}
14+
} & Partial<Pick<ComponentProps<typeof PatronStar>, 'subscriptionSince'>>;
1515

16-
export function UserWithAvatar({
16+
export const UserWithAvatar: FunctionComponent<Props> = ({
1717
avatarUrl,
1818
username,
1919
name,
2020
hideBadge,
2121
subscriptionSince,
2222
useBigName,
2323
...props
24-
}: UserWithAvatarProps) {
25-
return (
26-
<CenteredText {...props}>
27-
{avatarUrl && <Image src={avatarUrl} alt={username} />}
28-
<AuthorName useBigName={useBigName}>
29-
<Names>
30-
{name && <div>{name}</div>}
31-
{username && (
32-
<Username hasTwoNames={name && Boolean(username)}>
33-
{username}
34-
</Username>
35-
)}
36-
</Names>
37-
{subscriptionSince && (
38-
<PatronStar
39-
style={{ fontSize: '1.125em', marginBottom: '0.1em' }}
40-
subscriptionSince={subscriptionSince}
41-
/>
42-
)}
43-
{!hideBadge && (
44-
<ContributorHelm
45-
style={{ margin: '0 .5rem', fontSize: '1.25em' }}
46-
username={username}
47-
/>
24+
}) => (
25+
<CenteredText {...props}>
26+
{avatarUrl && <Image src={avatarUrl} alt={username} />}
27+
28+
<AuthorName useBigName={useBigName}>
29+
<Names>
30+
{name && <div>{name}</div>}
31+
32+
{username && (
33+
<Username hasTwoNames={Boolean(name && username)}>
34+
{username}
35+
</Username>
4836
)}
49-
</AuthorName>
50-
</CenteredText>
51-
);
52-
}
37+
</Names>
38+
39+
{subscriptionSince && (
40+
<PatronStar
41+
style={{ fontSize: '1.125em', marginBottom: '0.1em' }}
42+
subscriptionSince={subscriptionSince}
43+
/>
44+
)}
45+
46+
{!hideBadge && (
47+
<ContributorHelm
48+
style={{ margin: '0 .5rem', fontSize: '1.25em' }}
49+
username={username}
50+
/>
51+
)}
52+
</AuthorName>
53+
</CenteredText>
54+
);

0 commit comments

Comments
 (0)