Skip to content

Commit 912d47d

Browse files
committed
refactor: review update
1 parent 7c8f95e commit 912d47d

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

apps/site/components/withAvatarGroup.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
import type { ComponentProps, FC } from 'react';
44

55
import AvatarGroup from '@/components/Common/AvatarGroup';
6-
import { getAuthorWithId, getAuthorWithName } from '@/util/authorUtils';
6+
import type { AuthorProps } from '@/types';
7+
import { getAuthors } from '@/util/authorUtils';
78

89
type WithAvatarGroupProps = Omit<
910
ComponentProps<typeof AvatarGroup>,
1011
'avatars'
1112
> &
12-
(
13-
| { usernames: Array<string>; names?: never }
14-
| { names: Array<string>; usernames?: never }
15-
) & {
16-
clickable?: boolean;
17-
container?: HTMLElement | null;
18-
};
13+
AuthorProps;
1914

2015
const WithAvatarGroup: FC<WithAvatarGroupProps> = ({
2116
usernames,
@@ -24,11 +19,11 @@ const WithAvatarGroup: FC<WithAvatarGroupProps> = ({
2419
...props
2520
}) => (
2621
<AvatarGroup
27-
avatars={
28-
usernames
29-
? getAuthorWithId(usernames, clickable)
30-
: getAuthorWithName(names, clickable)
31-
}
22+
avatars={getAuthors({
23+
usernames: usernames,
24+
names: names,
25+
clickable: clickable,
26+
})}
3227
{...props}
3328
/>
3429
);

apps/site/types/author.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export interface AuthorProps {
2+
names?: Array<string>;
3+
usernames?: Array<string>;
4+
clickable?: boolean;
5+
container?: HTMLElement | null;
6+
}
7+
8+
export interface Author {
9+
id: string;
10+
name: string;
11+
website?: string;
12+
}

apps/site/types/config.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ export interface SiteConfig {
2929
websiteBanners: Record<string, WebsiteBanner>;
3030
websiteBadges: Record<string, WebsiteBadge>;
3131
}
32-
33-
export interface Author {
34-
id: string;
35-
name: string;
36-
website?: string;
37-
}

apps/site/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './server';
1111
export * from './github';
1212
export * from './calendar';
1313
export * from './search';
14+
export * from './author';

apps/site/util/authorUtils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { authors } from '@/next.json.mjs';
2-
3-
import { getGitHubAvatarUrl } from './gitHubUtils';
4-
import { getAcronymFromString } from './stringUtils';
2+
import type { AuthorProps } from '@/types';
3+
import { getGitHubAvatarUrl } from '@/util/gitHubUtils';
4+
import { getAcronymFromString } from '@/util/stringUtils';
55

66
export const mapAuthorToCardAuthors = (author: string) => {
77
// Clears text in parentheses
@@ -69,3 +69,11 @@ export const getAuthorWithName = (names: Array<string>, hasUrl: boolean) => {
6969

7070
return names.map(mapNameToAuthor);
7171
};
72+
73+
export const getAuthors = ({ usernames, names, clickable }: AuthorProps) => {
74+
if (usernames) {
75+
return getAuthorWithId(usernames, clickable ?? true);
76+
}
77+
78+
return getAuthorWithName(names || [], clickable ?? true);
79+
};

0 commit comments

Comments
 (0)