Skip to content

Commit afb05e6

Browse files
authored
fetch funding data on the client via proxy with cache, bump deps (#2333)
1 parent 80052d6 commit afb05e6

16 files changed

+153
-61
lines changed

.github/workflows/code-deploy-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: oven-sh/setup-bun@v2
1616
- name: Deploy
1717
shell: bash
18-
run: bunx vercel --force --token "$VERCEL_TOKEN" --build-env GITHUB_TOKEN="$GH_TOKEN"
18+
run: bunx vercel --force --token "$VERCEL_TOKEN"
1919
env:
2020
GH_TOKEN: ${{ secrets.GH_TOKEN_PREVIEW }}
2121
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

.github/workflows/code-deploy-producition-quick.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Deploy
2828
if: ${{ steps.filter.outputs.only_data_changed == 'true' }}
2929
shell: bash
30-
run: bunx vercel --force --token "$VERCEL_TOKEN" --prod --local-config ./vercel-quick.json --build-env GITHUB_TOKEN="$GH_TOKEN"
30+
run: bunx vercel --force --token "$VERCEL_TOKEN" --prod --local-config ./vercel-quick.json
3131
env:
3232
GH_TOKEN: ${{ secrets.GH_TOKEN }}
3333
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

.github/workflows/code-deploy-production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: oven-sh/setup-bun@v2
2626
- name: Deploy
2727
shell: bash
28-
run: bunx vercel --force --token "$VERCEL_TOKEN" --prod --build-env GITHUB_TOKEN="$GH_TOKEN"
28+
run: bunx vercel --force --token "$VERCEL_TOKEN" --prod
2929
env:
3030
GH_TOKEN: ${{ secrets.GH_TOKEN }}
3131
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

bun.lock

Lines changed: 51 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/Package/FundingSection.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
import { UL } from '@expo/html-elements';
22
import { useMemo } from 'react';
3+
import useSWR from 'swr';
34

45
import { H6Section, useLayout } from '~/common/styleguide';
56
import FundingRow from '~/components/Package/FoundingRow';
67
import { type LibraryFundingLink } from '~/types';
8+
import { TimeRange } from '~/util/datetime';
79
import tw from '~/util/tailwind';
810

911
type Props = {
10-
fundingLinks: LibraryFundingLink[];
12+
fullName: string;
1113
};
1214

13-
export default function FundingSection({ fundingLinks }: Props) {
15+
export default function FundingSection({ fullName }: Props) {
1416
const { isSmallScreen } = useLayout();
1517

16-
const links = useMemo(() => sortFundingLinks(fundingLinks), [fundingLinks]);
18+
const repoOwner = fullName.split('/')[0];
19+
const repoName = fullName.replace(`${repoOwner}/`, '');
1720

18-
if (links.length === 0) {
21+
const { data, isLoading } = useSWR(
22+
`/api/proxy/github-funding?owner=${repoOwner}&name=${repoName}`,
23+
(url: string) => fetch(url).then(res => res.json()),
24+
{
25+
dedupingInterval: TimeRange.HOUR * 1000,
26+
revalidateOnFocus: false,
27+
}
28+
);
29+
30+
const links = useMemo(() => sortFundingLinks(data?.fundingLinks ?? []), [data]);
31+
32+
if (isLoading || links.length === 0) {
1933
return null;
2034
}
2135

components/TopBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default function TopBar() {
103103
</View>
104104
</View>
105105
<ContentContainer style={[tw`flex-row gap-2.5 px-4`, !isSmallScreen && tw`hidden`]}>
106-
<NavigationTab title="Explore" path="/" />
106+
<NavigationTab title="Explore" path="/packages" />
107107
<NavigationTab title="Popular" />
108108
<NavigationTab title="Trending" />
109109
</ContentContainer>

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"@radix-ui/react-hover-card": "^1.1.15",
2828
"@radix-ui/react-tooltip": "^1.2.8",
2929
"@react-native-picker/picker": "^2.11.4",
30-
"@sentry/react": "^10.45.0",
30+
"@sentry/react": "^10.46.0",
3131
"@visx/gradient": "^3.12.0",
3232
"@visx/responsive": "^3.12.0",
3333
"@visx/xychart": "^3.12.0",
3434
"crypto-js": "^4.2.0",
3535
"es-toolkit": "^1.45.1",
36-
"expo": "55.0.8",
36+
"expo": "55.0.9",
3737
"expo-font": "^55.0.4",
3838
"next": "^16.2.1",
3939
"node-emoji": "^2.2.0",
@@ -55,7 +55,7 @@
5555
"swr": "^2.4.1",
5656
"tailwindcss": "^3.4.19",
5757
"twrnc": "^4.16.0",
58-
"use-debounce": "^10.1.0"
58+
"use-debounce": "^10.1.1"
5959
},
6060
"devDependencies": {
6161
"@expo/next-adapter": "^6.0.0",
@@ -76,10 +76,10 @@
7676
"next-images": "^1.8.5",
7777
"oxfmt": "^0.42.0",
7878
"oxlint": "^1.57.0",
79-
"oxlint-tsgolint": "^0.17.3",
79+
"oxlint-tsgolint": "^0.17.4",
8080
"simple-git-hooks": "^2.13.1",
8181
"typescript": "^6.0.2",
82-
"user-agent-data-types": "^0.4.2"
82+
"user-agent-data-types": "^0.4.3"
8383
},
8484
"simple-git-hooks": {
8585
"pre-commit": "bunx precommit"

pages/api/proxy/github-funding.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { type NextApiRequest, type NextApiResponse } from 'next';
2+
3+
import GitHubRepositoryFundingQuery from '~/scripts/queries/GitHubRepositoryFundingQuery';
4+
import { NEXT_1H_CACHE_HEADER } from '~/util/Constants';
5+
import { parseQueryParams } from '~/util/queryParams';
6+
7+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
8+
const { owner, name } = parseQueryParams(req.query);
9+
10+
const cleanOwner = owner ? owner.toString().toLowerCase().trim() : undefined;
11+
const cleanName = name ? name.toString().toLowerCase().trim() : undefined;
12+
13+
res.setHeader('Content-Type', 'application/json');
14+
res.setHeader('Cache-Control', 'public, s-maxage=3600, stale-while-revalidate=1800');
15+
16+
if (!cleanOwner || !cleanName) {
17+
res.statusCode = 500;
18+
res.json({
19+
error: `Invalid request. You need to specify repository owner and name via query params.`,
20+
});
21+
return;
22+
}
23+
24+
const result = await fetch('https://api.github.com/graphql', {
25+
method: 'POST',
26+
headers: {
27+
'Content-Type': 'application/json',
28+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
29+
},
30+
body: JSON.stringify({
31+
query: GitHubRepositoryFundingQuery,
32+
variables: { owner, name },
33+
}),
34+
...NEXT_1H_CACHE_HEADER,
35+
});
36+
37+
if ('status' in result && result.status !== 200) {
38+
res.statusCode = result.status;
39+
res.json({});
40+
return;
41+
}
42+
43+
const resultJson = await result.json();
44+
45+
res.statusCode = 200;
46+
res.json({ fundingLinks: resultJson.data.repository.fundingLinks });
47+
}

scenes/PackageOverviewScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default function PackageOverviewScene({
8383
</>
8484
)}
8585
{!isSmallScreen && <MorePackagesBox library={library} />}
86-
{!isSmallScreen && <FundingSection fundingLinks={library.github.fundingLinks} />}
86+
{!isSmallScreen && <FundingSection fullName={library.github.fullName} />}
8787
{!isSmallScreen && !!author && (
8888
<>
8989
<H6Section style={tw`mt-3`}>Author</H6Section>
@@ -192,7 +192,7 @@ export default function PackageOverviewScene({
192192
<DependenciesSection title="Development dependencies" data={devDependencies} />
193193
<DependenciesSection title="Engines" data={engines} />
194194
{isSmallScreen && <MorePackagesBox library={library} />}
195-
{isSmallScreen && <FundingSection fundingLinks={library.github.fundingLinks} />}
195+
{isSmallScreen && <FundingSection fullName={library.github.fullName} />}
196196
{isSmallScreen && !!author && (
197197
<>
198198
<H6Section>Author</H6Section>

scripts/fetch-github-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ function createRepoDataWithResponse(json: any, monorepo: boolean): LibraryType['
221221
hasTypes: json.types ?? false,
222222
newArchitecture: json.newArchitecture,
223223
isArchived: json.isArchived,
224-
fundingLinks: json.fundingLinks,
225224
hasReadme: hasReadmeFile(json.files),
226225
hasChangelog: hasChangelogFile(json.files),
227226
hasContributing: hasContributingFile(json.files),

0 commit comments

Comments
 (0)