Skip to content

Commit

Permalink
feat: add activity log
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Aug 12, 2024
1 parent 71b4ad0 commit c3509a1
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 37 deletions.
17 changes: 13 additions & 4 deletions src/app/(marketing)/profile/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SWRProvider } from "@/components/SWRProvider"
import { Anchor } from "@/components/ui/Anchor"
import { Guild, Role, Schemas } from "@guildxyz/types"
import { ArrowRight } from "@phosphor-icons/react/dist/ssr"
import { ActivityLogAction } from "components/[guild]/activity/constants"
import { notFound, redirect } from "next/navigation"
import { Profile } from "../_components/Profile"

Expand All @@ -22,12 +23,13 @@ async function ssrFetcher<T>(...args: Parameters<typeof fetch>) {
}

const fetchPublicProfileData = async ({ username }: { username: string }) => {
const activitiesRequest = new URL(`v2/profiles/${username}/activity`, api)
const contributionsRequest = new URL(`v2/profiles/${username}/contributions`, api)
const profileRequest = new URL(`v2/profiles/${username}`, api)
const profileResponse = await fetch(profileRequest, {
next: {
tags: ["profile"],
revalidate: 600,
revalidate: 3600,
},
})

Expand All @@ -40,10 +42,16 @@ const fetchPublicProfileData = async ({ username }: { username: string }) => {
{
next: {
tags: ["contributions"],
revalidate: 600,
revalidate: 3600,
},
}
)
const activities = await ssrFetcher<ActivityLogAction[]>(activitiesRequest, {
next: {
tags: ["contributions"],
revalidate: 60,
},
})
const roleRequests = contributions.map(
({ roleId, guildId }) => new URL(`v2/guilds/${guildId}/roles/${roleId}`, api)
)
Expand All @@ -54,7 +62,7 @@ const fetchPublicProfileData = async ({ username }: { username: string }) => {
guildRequests.map((req) =>
ssrFetcher<Guild>(req, {
next: {
revalidate: 3600,
revalidate: 3 * 3600,
},
})
)
Expand All @@ -63,7 +71,7 @@ const fetchPublicProfileData = async ({ username }: { username: string }) => {
roleRequests.map((req) =>
ssrFetcher<Role>(req, {
next: {
revalidate: 3600,
revalidate: 3 * 3600,
},
})
)
Expand All @@ -76,6 +84,7 @@ const fetchPublicProfileData = async ({ username }: { username: string }) => {
)
return {
fallback: {
[activitiesRequest.pathname]: activities,
[profileRequest.pathname]: profile,
[contributionsRequest.pathname]: contributions,
...guildsZipped,
Expand Down
Loading

0 comments on commit c3509a1

Please sign in to comment.