Skip to content

Commit 73e578e

Browse files
committed
update libraries. Fix user refetching logic
1 parent 1445984 commit 73e578e

File tree

3 files changed

+1448
-1157
lines changed

3 files changed

+1448
-1157
lines changed

app/profile/[login]/components/fetch-user-button.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type FetchUserButtonProps = {
4444
const REFRESH_INTERVAL = 1_000;
4545
const CHECK_STATUS_INTERVAL = 20_000;
4646
const REFRESH_TIMEOUT = 10 * 60 * 1_000;
47-
const FETCH_MESSAGES = ['Fetching…', 'Still fetching 😐', '👀 👀 👀', 'Ping! Still not ready…'];
47+
const FETCH_MESSAGES = ['Fetching…', '🚬 Still fetching', '👀 👀 👀', 'Ping! Still not ready…'];
4848

4949
export const FetchUserButton: FC<FetchUserButtonProps> = ({
5050
fetchingStatus,
@@ -71,10 +71,13 @@ export const FetchUserButton: FC<FetchUserButtonProps> = ({
7171
if (initialFetchingDuration >= REFRESH_TIMEOUT) {
7272
return;
7373
}
74-
// You can determine when and how often to update
75-
// the time here. In this example we update it only once
74+
75+
// invalidate the cache every time the page loads with fetching status
76+
// so the next time the user updates the profile, the latest data is fetched
77+
fetch(`/api/revalidate?tag=${encodeURIComponent(`profile:${login}`)}`);
78+
7679
setFetchingDuration(initialFetchingDuration);
77-
}, [fetchingStatus, fetchingUpdatedAt]);
80+
}, [fetchingStatus, fetchingUpdatedAt, login]);
7881

7982
const checkFetchingStatus = useCallback(async () => {
8083
setLoadingLabel('Checking…');
@@ -93,6 +96,11 @@ export const FetchUserButton: FC<FetchUserButtonProps> = ({
9396
fetchAttempt.current += 1;
9497
setLoadingLabel(FETCH_MESSAGES[fetchAttempt.current % FETCH_MESSAGES.length]);
9598
} else {
99+
if (timerRef.current) {
100+
clearTimeout(timerRef.current);
101+
}
102+
setLoadingLabel('Reloading…');
103+
96104
await fetch(`/api/revalidate?tag=${encodeURIComponent(`profile:${login}`)}`);
97105
window.location.reload();
98106
}
@@ -103,6 +111,9 @@ export const FetchUserButton: FC<FetchUserButtonProps> = ({
103111

104112
posthog.capture('profile.fetch', { login });
105113

114+
// immediately invalidate the cache, so if the user reloads the page, the latest data is fetched
115+
fetch(`/api/revalidate?tag=${encodeURIComponent(`profile:${login}`)}`);
116+
106117
const res = await fetch(`/api/profile/${login}`, { method: 'POST' });
107118

108119
if (!res.ok) {
@@ -184,7 +195,9 @@ export const FetchUserButton: FC<FetchUserButtonProps> = ({
184195
<div className={cn('flex flex-col gap-2', className)}>
185196
{attachDialogIfNeeded()}
186197
{fetchingDuration !== null && (
187-
<div className="text-xs text-muted-foreground">Time passed: {Math.floor(fetchingDuration / 1000)}s</div>
198+
<div className="text-xs text-muted-foreground">
199+
Next check in {Math.floor((CHECK_STATUS_INTERVAL - (fetchingDuration % CHECK_STATUS_INTERVAL)) / 1000)} s
200+
</div>
188201
)}
189202
</div>
190203
);

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"figma:icons": "tsc lib/figma/download-icons.ts --outDir dist && dotenv -e .env.local node dist/download-icons.js && pnpm run icons"
1515
},
1616
"dependencies": {
17-
"@auth/mongodb-adapter": "^3.9.1",
18-
"@hookform/resolvers": "^5.0.1",
17+
"@auth/mongodb-adapter": "^3.10.0",
18+
"@hookform/resolvers": "^5.2.0",
1919
"@radix-ui/react-aspect-ratio": "^1.1.7",
2020
"@radix-ui/react-avatar": "^1.1.10",
2121
"@radix-ui/react-dialog": "^1.1.14",
@@ -37,46 +37,46 @@
3737
"embla-carousel-fade": "^8.6.0",
3838
"embla-carousel-react": "^8.6.0",
3939
"jsonwebtoken": "^9.0.2",
40-
"lucide-react": "^0.525.0",
41-
"mongodb": "^6.16.0",
42-
"next": "15.4.0-canary.104",
40+
"lucide-react": "^0.527.0",
41+
"mongodb": "^6.18.0",
42+
"next": "15.4.2-canary.18",
4343
"next-auth": "5.0.0-beta.28",
4444
"next-themes": "^0.4.6",
4545
"nuqs": "^2.4.3",
4646
"posthog-js": "^1.246.0",
47-
"posthog-node": "^4.17.2",
47+
"posthog-node": "^5.6.0",
4848
"react": "^19.1.0",
4949
"react-dom": "^19.1.0",
50-
"react-hook-form": "^7.56.4",
50+
"react-hook-form": "^7.61.1",
5151
"react-icons": "^5.5.0",
5252
"react-spinners": "^0.17.0",
53-
"recharts": "^3.0.0",
54-
"satori": "^0.13.1",
55-
"sonner": "^2.0.3",
56-
"tailwind-merge": "^3.3.0",
53+
"recharts": "^3.1.0",
54+
"satori": "^0.16.1",
55+
"sonner": "^2.0.6",
56+
"tailwind-merge": "^3.3.1",
5757
"tailwindcss-animate": "^1.0.7",
5858
"usehooks-ts": "^3.1.1",
5959
"vaul": "^1.1.2",
60-
"zod": "^3.25.28"
60+
"zod": "^4.0.10"
6161
},
6262
"devDependencies": {
6363
"@eslint/eslintrc": "^3.3.1",
64-
"@graphql-codegen/cli": "^5.0.5",
65-
"@graphql-codegen/typed-document-node": "^5.1.1",
64+
"@graphql-codegen/cli": "^5.0.7",
65+
"@graphql-codegen/typed-document-node": "^5.1.2",
6666
"@svgr/cli": "^8.1.0",
67-
"@tailwindcss/postcss": "^4.1.7",
68-
"@types/jsonwebtoken": "^9.0.9",
69-
"@types/node": "^22.15.21",
70-
"@types/react": "^19.1.5",
71-
"@types/react-dom": "^19.1.5",
72-
"dotenv-cli": "^8.0.0",
73-
"eslint": "^9.27.0",
67+
"@tailwindcss/postcss": "^4.1.11",
68+
"@types/jsonwebtoken": "^9.0.10",
69+
"@types/node": "^24.1.0",
70+
"@types/react": "^19.1.8",
71+
"@types/react-dom": "^19.1.6",
72+
"dotenv-cli": "^9.0.0",
73+
"eslint": "^9.32.0",
7474
"eslint-config-next": "15.4.0-canary.51",
7575
"eslint-plugin-import": "^2.31.0",
7676
"eslint-plugin-react-hooks": "^5.2.0",
7777
"graphql": "^16.11.0",
78-
"postcss": "^8.5.3",
79-
"tailwindcss": "^4.1.7",
78+
"postcss": "^8.5.6",
79+
"tailwindcss": "^4.1.11",
8080
"typescript": "^5.8.3"
8181
},
8282
"packageManager": "[email protected]+sha512.398035c7bd696d0ba0b10a688ed558285329d27ea994804a52bad9167d8e3a72bcb993f9699585d3ca25779ac64949ef422757a6c31102c12ab932e5cbe5cc92"

0 commit comments

Comments
 (0)