diff --git a/apps/scoutgame/app/(general)/home/page.tsx b/apps/scoutgame/app/(general)/home/page.tsx index d94276a4ba..5b8c2ee014 100644 --- a/apps/scoutgame/app/(general)/home/page.tsx +++ b/apps/scoutgame/app/(general)/home/page.tsx @@ -1,5 +1,4 @@ import { HomePage } from 'components/home/HomePage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; export default async function Home({ searchParams @@ -7,7 +6,6 @@ export default async function Home({ searchParams: { [key: string]: string | string[] | undefined }; }) { const tab = searchParams.tab as string; - const user = await getUserFromSession(); - return ; + return ; } diff --git a/apps/scoutgame/app/(general)/notifications/page.tsx b/apps/scoutgame/app/(general)/notifications/page.tsx index 3a2eeeeee1..fc9903bffe 100644 --- a/apps/scoutgame/app/(general)/notifications/page.tsx +++ b/apps/scoutgame/app/(general)/notifications/page.tsx @@ -1,14 +1,14 @@ +import { getSession } from '@connect-shared/lib/session/getSession'; import { getNotifications } from '@packages/scoutgame/notifications/getNotifications'; import { NotificationsPage } from 'components/notifications/NotificationsPage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; export default async function Page() { - const user = await getUserFromSession(); + const { scoutId } = await getSession(); - const notifications = user + const notifications = scoutId ? await getNotifications({ - userId: user.id + userId: scoutId }) : []; diff --git a/apps/scoutgame/app/(general)/profile/page.tsx b/apps/scoutgame/app/(general)/profile/page.tsx index 9f65763ef6..1a960904af 100644 --- a/apps/scoutgame/app/(general)/profile/page.tsx +++ b/apps/scoutgame/app/(general)/profile/page.tsx @@ -4,7 +4,7 @@ import { redirect } from 'next/navigation'; import type { ProfileTab } from 'components/profile/ProfilePage'; import { ProfilePage } from 'components/profile/ProfilePage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; +import { getCachedUserFromSession as getUserFromSession } from 'lib/session/getUserFromSession'; import { getUserStats } from 'lib/users/getUserStats'; export const dynamic = 'force-dynamic'; diff --git a/apps/scoutgame/app/(general)/scout/page.tsx b/apps/scoutgame/app/(general)/scout/page.tsx index e6b36b780b..92c2e6b186 100644 --- a/apps/scoutgame/app/(general)/scout/page.tsx +++ b/apps/scoutgame/app/(general)/scout/page.tsx @@ -1,6 +1,5 @@ import { ScoutPage } from 'components/scout/ScoutPage'; import type { BuildersSort } from 'lib/builders/getSortedBuilders'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; export default async function Scout({ searchParams @@ -9,7 +8,6 @@ export default async function Scout({ }) { const sortParam = searchParams.tab; const sort = (sortParam && typeof sortParam === 'string' ? sortParam : 'top') as BuildersSort; - const user = await getUserFromSession(); - return ; + return ; } diff --git a/apps/scoutgame/app/(info)/welcome/how-it-works/page.tsx b/apps/scoutgame/app/(info)/welcome/how-it-works/page.tsx index c5bf1d3d61..edbd76f025 100644 --- a/apps/scoutgame/app/(info)/welcome/how-it-works/page.tsx +++ b/apps/scoutgame/app/(info)/welcome/how-it-works/page.tsx @@ -1,7 +1,6 @@ import type { Metadata } from 'next'; import { HowItWorksPage } from 'components/welcome/how-it-works/HowItWorksPage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; export const dynamic = 'force-dynamic'; @@ -13,8 +12,6 @@ export const metadata: Metadata = { }; export default async function HowItWorks() { - const user = await getUserFromSession(); - // logic in middleware.ts ensures that user is logged in - return ; + return ; } diff --git a/apps/scoutgame/app/(info)/welcome/page.tsx b/apps/scoutgame/app/(info)/welcome/page.tsx index d9195c0f25..9820e353fb 100644 --- a/apps/scoutgame/app/(info)/welcome/page.tsx +++ b/apps/scoutgame/app/(info)/welcome/page.tsx @@ -3,7 +3,7 @@ import type { Metadata } from 'next'; import { redirect } from 'next/navigation'; import { WelcomePage } from 'components/welcome/WelcomePage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; +import { getCachedUserFromSession as getUserFromSession } from 'lib/session/getUserFromSession'; export const dynamic = 'force-dynamic'; diff --git a/apps/scoutgame/app/(info)/welcome/spam-policy/page.tsx b/apps/scoutgame/app/(info)/welcome/spam-policy/page.tsx index 95d925961a..cca2efdc49 100644 --- a/apps/scoutgame/app/(info)/welcome/spam-policy/page.tsx +++ b/apps/scoutgame/app/(info)/welcome/spam-policy/page.tsx @@ -1,9 +1,6 @@ import type { Metadata } from 'next'; import { SpamPolicyPage } from 'components/welcome/spam-policy/SpamPolicyPage'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; - -export const dynamic = 'force-dynamic'; export const metadata: Metadata = { other: { @@ -13,7 +10,5 @@ export const metadata: Metadata = { }; export default async function SpamPolicy({ searchParams }: { searchParams: { 'profile-redirect': string } }) { - const user = await getUserFromSession(); - - return ; + return ; } diff --git a/apps/scoutgame/app/layout.tsx b/apps/scoutgame/app/layout.tsx index 49fe029f5c..633ef8eb75 100644 --- a/apps/scoutgame/app/layout.tsx +++ b/apps/scoutgame/app/layout.tsx @@ -4,7 +4,7 @@ import Script from 'next/script'; import type { ReactNode } from 'react'; import { AppProviders } from 'components/layout/AppProviders'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; +import { getCachedUserFromSession as getUserFromSession } from 'lib/session/getUserFromSession'; import 'theme/styles.scss'; const ClientGlobals = dynamic(() => import('components/common/ClientGlobals').then((comp) => comp.ClientGlobals), { diff --git a/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfile.tsx b/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfile.tsx index 085dec7a74..a830ffb4bc 100644 --- a/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfile.tsx +++ b/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfile.tsx @@ -6,7 +6,6 @@ import { currentSeason } from '@packages/scoutgame/dates'; import { getBuilderActivities } from 'lib/builders/getBuilderActivities'; import { getBuilderScouts } from 'lib/builders/getBuilderScouts'; import { getBuilderStats } from 'lib/builders/getBuilderStats'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; import type { BasicUserInfo } from 'lib/users/interfaces'; import { PublicBuilderProfileContainer } from './PublicBuilderProfileContainer'; @@ -19,8 +18,7 @@ export async function PublicBuilderProfile({ publicUser }: { publicUser: BasicUs builderNft, { allTimePoints = 0, seasonPoints = 0, rank = 0, gemsCollected = 0 } = {}, builderActivities = [], - { scouts = [], totalNftsSold = 0, totalScouts = 0 } = {}, - user + { scouts = [], totalNftsSold = 0, totalScouts = 0 } = {} ] = isApprovedBuilder ? await Promise.all([ prisma.builderNft.findUnique({ @@ -37,8 +35,7 @@ export async function PublicBuilderProfile({ publicUser }: { publicUser: BasicUs }), getBuilderStats(builderId), getBuilderActivities({ builderId, limit: 200 }), - getBuilderScouts(builderId), - getUserFromSession() + getBuilderScouts(builderId) ]) : []; @@ -57,7 +54,6 @@ export async function PublicBuilderProfile({ publicUser }: { publicUser: BasicUs builderActivities={builderActivities} gemsCollected={gemsCollected} rank={rank} - user={user} /> ); } diff --git a/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfileContainer.tsx b/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfileContainer.tsx index 5e1bc5470b..a2eadb6a9a 100644 --- a/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfileContainer.tsx +++ b/apps/scoutgame/components/[username]/components/PublicBuilderProfile/PublicBuilderProfileContainer.tsx @@ -28,10 +28,6 @@ type BuilderProfileProps = { builderActivities: BuilderActivity[]; gemsCollected?: number; rank?: number | null; - user?: { - id: string; - username: string; - } | null; }; const PaperContainer = styled(Paper)(({ theme }) => ({ @@ -58,8 +54,7 @@ export function PublicBuilderProfileContainer({ totalNftsSold, builderActivities, gemsCollected, - rank, - user + rank }: BuilderProfileProps) { const isDesktop = useMdScreen(); @@ -89,7 +84,6 @@ export function PublicBuilderProfileContainer({ hideDetails showPurchaseButton size='small' - userId={user?.id} /> @@ -140,7 +134,6 @@ export function PublicBuilderProfileContainer({ gemsCollected: 0, builderPoints: 0 }} - userId={user?.id} hideDetails showPurchaseButton /> diff --git a/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfile.tsx b/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfile.tsx index d90af882fd..62d30112f5 100644 --- a/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfile.tsx +++ b/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfile.tsx @@ -2,14 +2,13 @@ import { prisma } from '@charmverse/core/prisma-client'; import { getScoutedBuilders } from 'lib/scouts/getScoutedBuilders'; import { getScoutStats } from 'lib/scouts/getScoutStats'; -import { getUserFromSession } from 'lib/session/getUserFromSession'; import type { BasicUserInfo } from 'lib/users/interfaces'; import { BasicUserInfoSelect } from 'lib/users/queries'; import { PublicScoutProfileContainer } from './PublicScoutProfileContainer'; export async function PublicScoutProfile({ publicUser }: { publicUser: BasicUserInfo }) { - const [scout, { allTimePoints, seasonPoints, nftsPurchased }, scoutedBuilders, user] = await Promise.all([ + const [scout, { allTimePoints, seasonPoints, nftsPurchased }, scoutedBuilders] = await Promise.all([ prisma.scout.findUniqueOrThrow({ where: { id: publicUser.id @@ -17,8 +16,7 @@ export async function PublicScoutProfile({ publicUser }: { publicUser: BasicUser select: BasicUserInfoSelect }), getScoutStats(publicUser.id), - getScoutedBuilders({ scoutId: publicUser.id }), - getUserFromSession() + getScoutedBuilders({ scoutId: publicUser.id }) ]); return ( @@ -31,7 +29,6 @@ export async function PublicScoutProfile({ publicUser }: { publicUser: BasicUser seasonPoints={seasonPoints} nftsPurchased={nftsPurchased} scoutedBuilders={scoutedBuilders} - userId={user?.id} /> ); } diff --git a/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfileContainer.tsx b/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfileContainer.tsx index c22e47f307..a2f3cb177e 100644 --- a/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfileContainer.tsx +++ b/apps/scoutgame/components/[username]/components/PublicScoutProfile/PublicScoutProfileContainer.tsx @@ -20,7 +20,6 @@ export type ScoutProfileProps = { seasonPoints: number; nftsPurchased: number; scoutedBuilders: BuilderInfo[]; - userId?: string; }; export function PublicScoutProfileContainer({ @@ -28,8 +27,7 @@ export function PublicScoutProfileContainer({ allTimePoints, seasonPoints, nftsPurchased, - scoutedBuilders, - userId + scoutedBuilders }: ScoutProfileProps) { const isDesktop = useMdScreen(); return ( @@ -68,12 +66,7 @@ export function PublicScoutProfileContainer({ Scouted Builders {scoutedBuilders.length > 0 ? ( - + ) : ( This Scout hasn't discovered any Builders yet. Check back to see who they find! )} diff --git a/apps/scoutgame/components/common/Card/BuilderCard/BuilderCard.tsx b/apps/scoutgame/components/common/Card/BuilderCard/BuilderCard.tsx index ebe22665f2..38c284d160 100644 --- a/apps/scoutgame/components/common/Card/BuilderCard/BuilderCard.tsx +++ b/apps/scoutgame/components/common/Card/BuilderCard/BuilderCard.tsx @@ -14,15 +14,13 @@ export function BuilderCard({ showPurchaseButton = false, hideDetails = false, showHotIcon = false, - size = 'medium', - userId + size = 'medium' }: { size?: 'x-small' | 'small' | 'medium' | 'large'; builder: BuilderInfo; hideDetails?: boolean; showPurchaseButton?: boolean; showHotIcon?: boolean; - userId?: string; }) { return ( {typeof builder.price !== 'undefined' && showPurchaseButton && ( - + )} diff --git a/apps/scoutgame/components/common/Gallery/BuildersGallery.tsx b/apps/scoutgame/components/common/Gallery/BuildersGallery.tsx index ba21f36bd7..fb3ecf706e 100644 --- a/apps/scoutgame/components/common/Gallery/BuildersGallery.tsx +++ b/apps/scoutgame/components/common/Gallery/BuildersGallery.tsx @@ -8,14 +8,12 @@ export function BuildersGallery({ builders, columns = 6, showHotIcon = false, - size = 'medium', - userId + size = 'medium' }: { builders: BuilderInfo[]; columns?: number; showHotIcon?: boolean; size?: 'small' | 'medium' | 'large'; - userId?: string; }) { return ( @@ -32,7 +30,7 @@ export function BuildersGallery({ X {builder.nftsSoldToScout ?? 0} )} - + ))} diff --git a/apps/scoutgame/components/common/Header/Header.tsx b/apps/scoutgame/components/common/Header/Header.tsx index 2234deea34..b6500725e2 100644 --- a/apps/scoutgame/components/common/Header/Header.tsx +++ b/apps/scoutgame/components/common/Header/Header.tsx @@ -20,11 +20,12 @@ import { InstallAppMenuItem } from './components/InstallAppMenuItem'; export function Header() { const router = useRouter(); - const { user } = useUser(); + const { user, refreshUser } = useUser(); const [anchorElUser, setAnchorElUser] = useState(null); const { execute: logoutUser, isExecuting: isExecutingLogout } = useAction(logoutAction, { onSuccess: async () => { + await refreshUser(); revalidatePathAction(); router.push('/'); }, diff --git a/apps/scoutgame/components/common/NFTPurchaseDialog/components/NFTPurchaseForm.tsx b/apps/scoutgame/components/common/NFTPurchaseDialog/components/NFTPurchaseForm.tsx index f253caf1ce..c569a408e2 100644 --- a/apps/scoutgame/components/common/NFTPurchaseDialog/components/NFTPurchaseForm.tsx +++ b/apps/scoutgame/components/common/NFTPurchaseDialog/components/NFTPurchaseForm.tsx @@ -74,7 +74,7 @@ export function NFTPurchaseForm(props: NFTPurchaseProps) { } export function NFTPurchaseFormContent({ builder }: NFTPurchaseProps) { - const { user } = useUser(); + const { user, refreshUser } = useUser(); const builderId = builder.id; const initialQuantities = [1, 11, 111]; const pricePerNft = builder.price ? convertCostToPoints(builder.price).toLocaleString() : ''; @@ -147,6 +147,7 @@ export function NFTPurchaseFormContent({ builder }: NFTPurchaseProps) { async onSuccess(res) { if (res.data?.id) { await checkDecentTransaction({ pendingTransactionId: res.data.id }); + await refreshUser(); log.info('NFT minted', { chainId, builderTokenId, purchaseCost }); } else { log.warn('NFT minted but no transaction id returned', { diff --git a/apps/scoutgame/components/common/ScoutButton/ScoutButton.tsx b/apps/scoutgame/components/common/ScoutButton/ScoutButton.tsx index c5f3150977..6d36045392 100644 --- a/apps/scoutgame/components/common/ScoutButton/ScoutButton.tsx +++ b/apps/scoutgame/components/common/ScoutButton/ScoutButton.tsx @@ -7,7 +7,7 @@ import Image from 'next/image'; import { useState } from 'react'; import type { NFTPurchaseProps } from 'components/common/NFTPurchaseDialog/components/NFTPurchaseForm'; -import type { MinimalUserInfo } from 'lib/users/interfaces'; +import { useUser } from 'components/layout/UserProvider'; import { DynamicLoadingContext, LoadingComponent } from '../DynamicLoading'; @@ -21,16 +21,12 @@ const NFTPurchaseDialog = dynamic( } ); -export function ScoutButton({ - builder, - isAuthenticated = true -}: { - builder: NFTPurchaseProps['builder']; - isAuthenticated?: boolean; -}) { +export function ScoutButton({ builder }: { builder: NFTPurchaseProps['builder'] }) { const [isPurchasing, setIsPurchasing] = useState(false); const [authPopup, setAuthPopup] = useState(false); const [dialogLoadingStatus, setDialogLoadingStatus] = useState(false); + const { user } = useUser(); + const isAuthenticated = Boolean(user?.id); const handleClick = () => { if (isAuthenticated) { diff --git a/apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx b/apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx index 6cef022b13..0efa26653e 100644 --- a/apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx +++ b/apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx @@ -22,7 +22,7 @@ import { WarpcastIcon } from './WarpcastIcon'; export function WarpcastLoginButton({ children, ...props }: ButtonProps) { const popupState = usePopupState({ variant: 'popover', popupId: 'warpcast-login' }); const router = useRouter(); - const { setUser } = useUser(); + const { refreshUser } = useUser(); const { isAuthenticated } = useProfile(); const searchParams = useSearchParams(); const redirectUrlEncoded = searchParams.get('redirectUrl'); @@ -44,7 +44,7 @@ export function WarpcastLoginButton({ children, ...props }: ButtonProps) { return; } - setUser(data.user); + await refreshUser(data.user); await revalidatePath(); router.push(nextPage); diff --git a/apps/scoutgame/components/home/HomePage.tsx b/apps/scoutgame/components/home/HomePage.tsx index 77557063fb..445615e533 100644 --- a/apps/scoutgame/components/home/HomePage.tsx +++ b/apps/scoutgame/components/home/HomePage.tsx @@ -7,12 +7,11 @@ import { LoadingCards } from 'components/common/Loading/LoadingCards'; import { LoadingTable } from 'components/common/Loading/LoadingTable'; import { TodaysHotBuildersCarousel } from 'components/home/components/BuildersCarousel/TodaysHotBuildersCarousel'; import { HomeTabsMenu } from 'components/home/components/HomePageTable/components/HomeTabsMenu'; -import type { SessionUser } from 'lib/session/getUserFromSession'; import { homeTabs } from './components/HomePageTable/components/HomeTabsMenu'; import { HomeTab } from './components/HomePageTable/HomePageTable'; -export function HomePage({ user, tab }: { user: SessionUser | null; tab: string }) { +export function HomePage({ tab }: { tab: string }) { const currentTab = homeTabs.some((t) => t.value === tab) ? tab : 'leaderboard'; return ( <> @@ -24,13 +23,13 @@ export function HomePage({ user, tab }: { user: SessionUser | null; tab: string Scout Today's HOT Builders - }> - + }> + }> - + diff --git a/apps/scoutgame/components/home/components/BuildersCarousel/BuildersCarousel.tsx b/apps/scoutgame/components/home/components/BuildersCarousel/BuildersCarousel.tsx index 2c8adc8399..40470ce575 100644 --- a/apps/scoutgame/components/home/components/BuildersCarousel/BuildersCarousel.tsx +++ b/apps/scoutgame/components/home/components/BuildersCarousel/BuildersCarousel.tsx @@ -7,7 +7,7 @@ import type { BuilderInfo } from 'lib/builders/interfaces'; import { BuilderCard } from '../../../common/Card/BuilderCard/BuilderCard'; -export function BuildersCarousel({ builders, userId }: { builders: BuilderInfo[]; userId?: string }) { +export function BuildersCarousel({ builders }: { builders: BuilderInfo[] }) { const isMdScreen = useMdScreen(); const isLgScreen = useLgScreen(); const size = isLgScreen ? 'large' : isMdScreen ? 'small' : 'x-small'; @@ -20,7 +20,7 @@ export function BuildersCarousel({ builders, userId }: { builders: BuilderInfo[] return ( {builders.map((builder) => ( - + ))} ); diff --git a/apps/scoutgame/components/home/components/BuildersCarousel/TodaysHotBuildersCarousel.tsx b/apps/scoutgame/components/home/components/BuildersCarousel/TodaysHotBuildersCarousel.tsx index d397bf24b1..ed8bac2cb5 100644 --- a/apps/scoutgame/components/home/components/BuildersCarousel/TodaysHotBuildersCarousel.tsx +++ b/apps/scoutgame/components/home/components/BuildersCarousel/TodaysHotBuildersCarousel.tsx @@ -4,7 +4,7 @@ import { getTodaysHotBuilders } from 'lib/builders/getTodaysHotBuilders'; import { BuildersCarousel } from './BuildersCarousel'; -export async function TodaysHotBuildersCarousel({ userId }: { userId?: string }) { +export async function TodaysHotBuildersCarousel() { const builders = await getTodaysHotBuilders(); - return ; + return ; } diff --git a/apps/scoutgame/components/home/components/HomePageTable/HomePageTable.tsx b/apps/scoutgame/components/home/components/HomePageTable/HomePageTable.tsx index d82d87d804..82474b9f50 100644 --- a/apps/scoutgame/components/home/components/HomePageTable/HomePageTable.tsx +++ b/apps/scoutgame/components/home/components/HomePageTable/HomePageTable.tsx @@ -10,7 +10,7 @@ import { LeaderboardTable } from './components/LeaderboardTable'; import { TopBuildersTable } from './components/TopBuildersTable'; import { TopScoutsTable } from './components/TopScoutsTable'; -export async function HomeTab({ tab, userId }: { tab: string; userId?: string }) { +export async function HomeTab({ tab }: { tab: string }) { if (tab === 'activity') { const activities = await getBuilderActivities({ limit: 100 }); return ; @@ -23,12 +23,12 @@ export async function HomeTab({ tab, userId }: { tab: string; userId?: string }) if (tab === 'top-builders') { const topBuilders = await getTopBuilders({ limit: 200 }); - return ; + return ; } if (tab === 'leaderboard') { const data = await getLeaderboard({ limit: 200 }); - return ; + return ; } return null; } diff --git a/apps/scoutgame/components/home/components/HomePageTable/components/LeaderboardTable.tsx b/apps/scoutgame/components/home/components/HomePageTable/components/LeaderboardTable.tsx index 9f8ec9b6d0..0a63081067 100644 --- a/apps/scoutgame/components/home/components/HomePageTable/components/LeaderboardTable.tsx +++ b/apps/scoutgame/components/home/components/HomePageTable/components/LeaderboardTable.tsx @@ -18,7 +18,7 @@ import type { LeaderBoardRow } from 'lib/builders/getLeaderboard'; import { TableCellText } from './TableCellText'; -export function LeaderboardTable({ data, userId }: { data: LeaderBoardRow[]; userId?: string }) { +export function LeaderboardTable({ data }: { data: LeaderBoardRow[] }) { const sorted = data.sort((a, b) => b.progress - a.progress); return ( @@ -90,7 +90,7 @@ export function LeaderboardTable({ data, userId }: { data: LeaderBoardRow[]; use - + ))} diff --git a/apps/scoutgame/components/home/components/HomePageTable/components/TopBuildersTable.tsx b/apps/scoutgame/components/home/components/HomePageTable/components/TopBuildersTable.tsx index 9dc0011eed..f13d1b34c4 100644 --- a/apps/scoutgame/components/home/components/HomePageTable/components/TopBuildersTable.tsx +++ b/apps/scoutgame/components/home/components/HomePageTable/components/TopBuildersTable.tsx @@ -19,7 +19,7 @@ import type { TopBuilderInfo } from 'lib/builders/getTopBuilders'; import { TableCellText } from './TableCellText'; -export function TopBuildersTable({ builders, userId }: { builders: TopBuilderInfo[]; userId?: string }) { +export function TopBuildersTable({ builders }: { builders: TopBuilderInfo[] }) { return ( @@ -105,7 +105,7 @@ export function TopBuildersTable({ builders, userId }: { builders: TopBuilderInf - + ))} diff --git a/apps/scoutgame/components/layout/AppProviders.tsx b/apps/scoutgame/components/layout/AppProviders.tsx index 40a61bf0d2..be2dfa7b41 100644 --- a/apps/scoutgame/components/layout/AppProviders.tsx +++ b/apps/scoutgame/components/layout/AppProviders.tsx @@ -9,6 +9,7 @@ import { WagmiProvider } from 'components/common/WalletLogin/WagmiProvider'; import type { SessionUser } from 'lib/session/getUserFromSession'; import theme from 'theme/theme'; +import { SWRProvider } from './SwrProvider'; import { UserProvider } from './UserProvider'; export function AppProviders({ children, user }: { children: ReactNode; user: SessionUser | null }) { @@ -17,7 +18,9 @@ export function AppProviders({ children, user }: { children: ReactNode; user: Se - {children} + + {children} + diff --git a/apps/scoutgame/components/layout/SwrProvider.tsx b/apps/scoutgame/components/layout/SwrProvider.tsx new file mode 100644 index 0000000000..5320ebdd90 --- /dev/null +++ b/apps/scoutgame/components/layout/SwrProvider.tsx @@ -0,0 +1,18 @@ +'use client'; + +import type { ReactNode } from 'react'; +import { SWRConfig } from 'swr'; + +export function SWRProvider({ children }: { children: ReactNode }) { + return ( + = 500; + } + }} + > + {children} + + ); +} diff --git a/apps/scoutgame/components/layout/UserProvider.tsx b/apps/scoutgame/components/layout/UserProvider.tsx index 8319dfa504..1e5b7d936b 100644 --- a/apps/scoutgame/components/layout/UserProvider.tsx +++ b/apps/scoutgame/components/layout/UserProvider.tsx @@ -1,29 +1,29 @@ 'use client'; import type { ReactNode } from 'react'; -import { createContext, useCallback, useContext, useMemo, useState } from 'react'; +import { createContext, useCallback, useContext, useMemo } from 'react'; -import { useGetUserTrigger } from 'hooks/api/session'; +import { useGetUser } from 'hooks/api/session'; import type { SessionUser } from 'lib/session/getUserFromSession'; type UserContext = { user: SessionUser | null; - setUser: (user: SessionUser | null) => void; - reloadUser: () => Promise; + refreshUser: (_user?: SessionUser | null) => Promise; }; export const UserContext = createContext>(null); export function UserProvider({ children, userSession }: { children: ReactNode; userSession: SessionUser | null }) { - const [user, setUser] = useState(userSession); - const { trigger: triggerReload } = useGetUserTrigger(); + const { data: user = userSession, mutate: mutateUser } = useGetUser(); - const reloadUser = useCallback(async () => { - const updated = await triggerReload(); - setUser(updated); - }, [triggerReload]); + const refreshUser = useCallback( + async (_user?: SessionUser | null) => { + return mutateUser(_user); + }, + [mutateUser] + ); - const value = useMemo(() => ({ user, reloadUser, setUser }), [user, reloadUser, setUser]); + const value = useMemo(() => ({ user, refreshUser }), [user, refreshUser]); return {children}; } diff --git a/apps/scoutgame/components/profile/ProfilePage.tsx b/apps/scoutgame/components/profile/ProfilePage.tsx index 490cea93f8..dd55d44c24 100644 --- a/apps/scoutgame/components/profile/ProfilePage.tsx +++ b/apps/scoutgame/components/profile/ProfilePage.tsx @@ -1,6 +1,7 @@ import { Box, Paper, Stack, Typography } from '@mui/material'; import { Suspense } from 'react'; +import { LoadingComponent } from 'components/common/Loading/LoadingComponent'; import { UserProfile } from 'components/common/Profile/UserProfile'; import type { UserStats } from 'lib/users/getUserStats'; import type { BasicUserInfo } from 'lib/users/interfaces'; @@ -77,11 +78,11 @@ export function ProfilePage({ user, tab }: ProfilePageProps) { - : null}> + : }> {tab === 'win' ? ( ) : tab === 'scout' ? ( - + ) : tab === 'build' ? ( ) : ( @@ -96,7 +97,7 @@ export function ProfilePage({ user, tab }: ProfilePageProps) { Scout - + { - await execute(); + await executeAsync(); setShowModal(true); - await reloadUser(); + await refreshUser(); }; const handleCloseModal = () => { diff --git a/apps/scoutgame/components/profile/components/ProfileTabsMenu.tsx b/apps/scoutgame/components/profile/components/ProfileTabsMenu.tsx index 88171f44ea..b5dff258b0 100644 --- a/apps/scoutgame/components/profile/components/ProfileTabsMenu.tsx +++ b/apps/scoutgame/components/profile/components/ProfileTabsMenu.tsx @@ -16,7 +16,7 @@ const mobileTabs = ['scout', 'build', 'win']; export function ProfileTabsMenu({ tab }: { tab: ProfileTab }) { const { data: claimablePoints } = useGetClaimablePoints(); - const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm')); + const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'), { noSsr: true }); const isDesktop = useMdScreen(); const router = useRouter(); diff --git a/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx b/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx index 956774c9f1..4108db0b30 100644 --- a/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx +++ b/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx @@ -9,7 +9,7 @@ import { getScoutedBuilders } from 'lib/scouts/getScoutedBuilders'; import { ScoutStats } from './ScoutStats'; -export async function ScoutProfile({ userId, isMobile }: { userId: string; isMobile?: boolean }) { +export async function ScoutProfile({ userId }: { userId: string }) { const [seasonStats, scoutedBuilders] = await Promise.all([ prisma.userSeasonStats.findUnique({ where: { @@ -39,7 +39,7 @@ export async function ScoutProfile({ userId, isMobile }: { userId: string; isMob Scouted Builders {scoutedBuilders.length > 0 ? ( - + ) : ( You haven't scouted any Builders yet. Start exploring and discover talent! )} diff --git a/apps/scoutgame/components/scout/ScoutPage.tsx b/apps/scoutgame/components/scout/ScoutPage.tsx index af7fd51b6d..08661794fc 100644 --- a/apps/scoutgame/components/scout/ScoutPage.tsx +++ b/apps/scoutgame/components/scout/ScoutPage.tsx @@ -9,7 +9,7 @@ import { ScoutPageBuildersGallery } from './components/ScoutPageBuildersGallery' import { SearchBuildersInput } from './components/SearchBuildersInput'; import { SortOptionTabs, sortOptions } from './components/SortOptionTabs'; -export function ScoutPage({ sort, user }: { sort: BuildersSort; user?: { username: string; id: string } | null }) { +export function ScoutPage({ sort }: { sort: BuildersSort }) { const currentSort = sortOptions.some((t) => t.value === sort) ? sort : 'top'; return ( @@ -17,7 +17,7 @@ export function ScoutPage({ sort, user }: { sort: BuildersSort; user?: { usernam }> - + ); diff --git a/apps/scoutgame/components/scout/components/BuildersGalleryContainer.tsx b/apps/scoutgame/components/scout/components/BuildersGalleryContainer.tsx index d34d66d4d6..7b9e9e1921 100644 --- a/apps/scoutgame/components/scout/components/BuildersGalleryContainer.tsx +++ b/apps/scoutgame/components/scout/components/BuildersGalleryContainer.tsx @@ -14,14 +14,12 @@ import type { BuilderInfo } from 'lib/builders/interfaces'; export function BuildersGalleryContainer({ initialBuilders, showHotIcon, - userId, sort, initialCursor }: { initialCursor: CompositeCursor | null; initialBuilders: BuilderInfo[]; showHotIcon: boolean; - userId?: string; sort: BuildersSort; }) { const [error, setError] = useState(null); @@ -86,7 +84,6 @@ export function BuildersGalleryContainer({ showHotIcon={showHotIcon} size={isDesktop ? 'medium' : 'small'} columns={5} - userId={userId} /> {nextCursor &&
} {isLoading && ( diff --git a/apps/scoutgame/components/scout/components/ScoutPageBuildersGallery.tsx b/apps/scoutgame/components/scout/components/ScoutPageBuildersGallery.tsx index a2db8caf14..4bdb3d5e01 100644 --- a/apps/scoutgame/components/scout/components/ScoutPageBuildersGallery.tsx +++ b/apps/scoutgame/components/scout/components/ScoutPageBuildersGallery.tsx @@ -7,15 +7,7 @@ import { BuildersGalleryContainer } from './BuildersGalleryContainer'; export const dynamic = 'force-dynamic'; -export async function ScoutPageBuildersGallery({ - sort, - showHotIcon, - userId -}: { - sort: BuildersSort; - showHotIcon: boolean; - userId?: string; -}) { +export async function ScoutPageBuildersGallery({ sort, showHotIcon }: { sort: BuildersSort; showHotIcon: boolean }) { const { builders, nextCursor } = await getSortedBuilders({ sort: sort as BuildersSort, limit: 15, @@ -29,7 +21,6 @@ export async function ScoutPageBuildersGallery({ initialCursor={nextCursor} initialBuilders={builders} showHotIcon={showHotIcon} - userId={userId} /> ); } diff --git a/apps/scoutgame/components/welcome/how-it-works/HowItWorksPage.tsx b/apps/scoutgame/components/welcome/how-it-works/HowItWorksPage.tsx index edfa29154e..6a355d9d02 100644 --- a/apps/scoutgame/components/welcome/how-it-works/HowItWorksPage.tsx +++ b/apps/scoutgame/components/welcome/how-it-works/HowItWorksPage.tsx @@ -1,12 +1,11 @@ -import { Button, List, ListItem, Stack, Typography } from '@mui/material'; -import Image from 'next/image'; +import { Button, List, ListItem, Typography } from '@mui/material'; import Link from 'next/link'; import { SinglePageLayout } from 'components/common/Layout'; import { SinglePageWrapper } from 'components/common/SinglePageWrapper'; import { InfoBackgroundImage } from 'components/layout/InfoBackgroundImage'; -export function HowItWorksPage({ username }: { username: string }) { +export function HowItWorksPage() { return ( diff --git a/apps/scoutgame/components/welcome/spam-policy/SpamPolicyPage.tsx b/apps/scoutgame/components/welcome/spam-policy/SpamPolicyPage.tsx index e51015c8cd..96acf9112c 100644 --- a/apps/scoutgame/components/welcome/spam-policy/SpamPolicyPage.tsx +++ b/apps/scoutgame/components/welcome/spam-policy/SpamPolicyPage.tsx @@ -1,16 +1,18 @@ 'use client'; import { Button, Typography } from '@mui/material'; +import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { useAction } from 'next-safe-action/hooks'; import { SinglePageLayout } from 'components/common/Layout'; import { SinglePageWrapper } from 'components/common/SinglePageWrapper'; import { InfoBackgroundImage } from 'components/layout/InfoBackgroundImage'; -import type { SessionUser } from 'lib/session/getUserFromSession'; +import { useUser } from 'components/layout/UserProvider'; import { saveOnboardedAction } from 'lib/users/saveOnboardedAction'; -export function SpamPolicyPage({ user, redirectToProfile }: { user: SessionUser | null; redirectToProfile: boolean }) { +export function SpamPolicyPage({ redirectToProfile }: { redirectToProfile: boolean }) { + const { user } = useUser(); const router = useRouter(); // programmatically added builders will land here skipping the /welcome/builder page // we set the onboardedAt flag on that page, so make sure we set it here too if the user hasn't been onboarded yet @@ -40,6 +42,7 @@ export function SpamPolicyPage({ user, redirectToProfile }: { user: SessionUser {user ? ( user.onboardedAt ? (