Skip to content

Commit

Permalink
πŸ› fix: Fix SponsorKit
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 23, 2023
1 parent 43778ad commit d1e3ecb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Sponsor/demos/index.tsx
Expand Up @@ -4,7 +4,7 @@ import { useThemeMode } from 'antd-style';
import useSWR from 'swr';

import { DEFAULT_AVATAR_SIZE, DEFAULT_WIDTH } from '../const';
import { caleHeight, fechOpenCollectiveData } from '../utils';
import { caleHeight, fetchOpenCollectiveData } from '../utils';

export default () => {
const { isDarkMode } = useThemeMode();
Expand All @@ -23,7 +23,7 @@ export default () => {
},
{ store },
);
const { data, isLoading } = useSWR(id, fechOpenCollectiveData, { revalidateOnFocus: false });
const { data, isLoading } = useSWR(id, fetchOpenCollectiveData, { revalidateOnFocus: false });

return (
<StoryBook levaStore={store}>
Expand Down
4 changes: 2 additions & 2 deletions src/Sponsor/index.tsx
Expand Up @@ -38,7 +38,7 @@ const Sponsor: FC<SponsorProps> = ({
>
{data.map((item) => {
const tierConfig = getTier(item.tier);
const multiplier = item.totalAmountDonated / tierConfig.amount;
const multiplier = Math.floor(item.totalAmountDonated / tierConfig.amount);
return (
<div
key={item.MemberId}
Expand Down Expand Up @@ -103,7 +103,7 @@ const Sponsor: FC<SponsorProps> = ({
}}
>
<span>{tierConfig.emoji}</span>
<span>{item.name.length > 9 ? item.name.slice(0, 9) + '...' : item.name}</span>
<span>{item.name.length > 9 ? item.name.slice(0, 8) + '...' : item.name}</span>
</div>
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions src/Sponsor/utils.ts
Expand Up @@ -18,14 +18,18 @@ export const caleHeight = (
return Math.ceil(length / Math.ceil(col)) * avatarSize * 1.4;
};

export const fechOpenCollectiveData = async (
export const fetchOpenCollectiveData = async (
id = 'lobehub',
groupBy: TierItem[] = DEFAULT_GROUP,
fallbackTier: string = (DEFAULT_GROUP.at(-1) as TierItem).title,
): Promise<MemberProfile[]> => {
const res = await fetch(`https://opencollective.com/${id}/members/all.json`);
const json = await res.json();
const filteredData = json.filter((item: any) => item?.totalAmountDonated > 0);
const filteredData = json.filter((item: any) => {
const dump = json.filter((i: any) => item.name === i.name);
if (dump.length > 1 && !item.tier) return false;
return item?.totalAmountDonated > 0;
});
const tierSortMap = new Map(groupBy.map((item) => [item.title, item.sort]));
return [...filteredData].sort((a, b) => {
const sortA = tierSortMap.get(a.tier || fallbackTier) || 0;
Expand Down

0 comments on commit d1e3ecb

Please sign in to comment.