/* * Copyright (c) 2023 AccelByte Inc. All Rights Reserved * This is licensed software from AccelByte Inc, for limitations * and restrictions contact your company contract manager. */ import { AppStore, AppStoreDetail, BundleStore, BundleStoreDetail, CodeStore, DlcStoreDetail, IngameItemStoreDetail, MultipleGameStore, OptionboxStore, OptionboxStoreDetail, SingleGameAppStore, SingleGameOptionboxStore, SingleGameStore, SingleGameStoreWrapper, SingleInGameItemsStore, StoreEntry, StoreWidget, storeFetcher } from '@accelbyte/widgets-v2/widgets/store' import { Outlet, RouteObject, json, useLoaderData, useOutletContext } from 'react-router' import { sdk } from '../appConfig' import { AppWrapper } from '../AppWrapper' import React from 'react' import { useParams } from 'react-router-dom' import { BundleIcon } from '@accelbyte/widgets-v2/packages/od-components/components/Icons/BundleIcon' import { GameIcon } from '@accelbyte/widgets-v2/packages/od-components/components/Icons/GameIcon' import { OptionboxIcon } from '@accelbyte/widgets-v2/packages/od-components/components/Icons/OptionboxIcon' import { ProductKeyIcon } from '@accelbyte/widgets-v2/packages/od-components/components/Icons/ProductKeyIcon' import { Trans } from 'react-i18next' import { storeAppsIndexFetcher, storeBundlesIndexFetcher, storeCodesIndexFetcher, storeDetailFetcher, storeDlcsIndexFetcher, storeInGameItemsIndexFetcher, storeItemsFetcher, storeOptionBoxesIndexFetcher } from '@accelbyte/widgets-v2/widgets/store/storeFetcher' import { ItemInfo } from '@accelbyte/sdk-platform' const baseAppId = 'lightfantastic' export const StoreRoute: RouteObject = { path: '/store', loader: async () => { const initialData = await storeFetcher({ sdk, appId: baseAppId, isSingleGame: false }) return json(initialData) }, Component: () => { const params = useParams() const initialData = useLoaderData() as Awaited> return ( {({ isSingleGame }) => { // Item detail. // We render the outlet right away. if (params.itemId) { return } let storeEntryContent: JSX.Element if (isSingleGame) { // Single game stuff. storeEntryContent = ( {({ baseItem }) => { return ( , label: Expansions, link: '/store/dlcs' }, { icon: , label: Game Store, link: '/store/in-game-items' }, { icon: , label: Optionbox, link: '/store/optionboxes' } ]}> ) }} ) } else { // Multiple game stuff. storeEntryContent = ( , link: '/store/apps', label: Games }, { icon: , link: '/store/bundles', label: Bundles }, { icon: , link: '/store/codes', label: Product Keys }, { icon: , link: '/store/optionboxes', label: Optionbox } ]}> ) } return {storeEntryContent} }} ) // }, children: [ { path: '/store/dlcs', loader: async () => { const initialData = await storeDlcsIndexFetcher({ sdk, baseAppId }) return json(initialData) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as Awaited> if (!props) return null if (props.isSingleGame) { return } return
Not found
} }, { path: '/store/in-game-items', loader: async () => { const initialData = await storeInGameItemsIndexFetcher({ sdk, baseAppId }) return json(initialData) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as Awaited> if (!props) return null if (props.isSingleGame) { return } return
Not found
} }, { path: '/store/optionboxes', loader: async ({ request }) => { const url = new URL(request.url) const page = parseInt(url.searchParams.get('page') ?? '1') const isSingleGame = false const initialData = await storeOptionBoxesIndexFetcher({ sdk, isSingleGame, baseAppId, page }) return json({ initialData, page }) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as { initialData: Awaited>; page: number } if (!props) return null if (props.isSingleGame) { return } return } }, { path: '/store/apps', loader: async ({ request }) => { const url = new URL(request.url) const page = parseInt(url.searchParams.get('page') ?? '1') const initialData = await storeAppsIndexFetcher({ sdk, page }) return json({ initialData, page }) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as { initialData: Awaited>; page: number } if (!props) return null if (props.isSingleGame) { return null } return } }, { path: '/store/codes', loader: async ({ request }) => { const url = new URL(request.url) const page = parseInt(url.searchParams.get('page') ?? '1') const initialData = await storeCodesIndexFetcher({ sdk, page }) return json({ initialData, page }) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as { initialData: Awaited>; page: number } if (!props) return null if (props.isSingleGame) { return null } return } }, { path: '/store/bundles', loader: async ({ request }) => { const url = new URL(request.url) const page = parseInt(url.searchParams.get('page') ?? '1') const initialData = await storeBundlesIndexFetcher({ sdk, page }) return json({ initialData, page }) }, Component: () => { const props = useOutletContext() as { isSingleGame: boolean; storeProps?: { baseItem?: ItemInfo } } const loaderData = useLoaderData() as { initialData: Awaited>; page: number } if (!props) return null if (props.isSingleGame) { return null } return } }, // store details { path: '/store/dlcs/:itemId', loader: async ({ params }) => { const itemId = params.itemId ?? '' const { itemLocale, baseApp } = await storeDetailFetcher({ sdk, itemId, baseAppId }) return json({ itemLocale, baseApp, itemId }) }, Component: () => { const loaderData = useLoaderData() as any return ( ) } }, { path: '/store/in-game-items/:itemId', loader: async ({ params }) => { const itemId = params.itemId ?? '' const { itemLocale, baseApp } = await storeDetailFetcher({ sdk, itemId, baseAppId }) return json({ itemLocale, baseApp, itemId }) }, Component: () => { const loaderData = useLoaderData() as any return ( ) } }, { path: '/store/optionboxes/:itemId', loader: async ({ params }) => { const itemId = params.itemId ?? '' const { itemLocale, baseApp } = await storeDetailFetcher({ sdk, itemId }) return json({ itemLocale, baseApp, itemId }) }, Component: () => { const loaderData = useLoaderData() as any return } }, { path: '/store/apps/:itemId', loader: async ({ params }) => { const itemId = params.itemId ?? '' const { itemLocale } = await storeDetailFetcher({ sdk, itemId }) return json({ itemId, itemLocale }) }, Component: () => { const loaderData = useLoaderData() as any return } }, { path: '/store/bundles/:itemId', loader: async ({ params }) => { const itemId = params.itemId ?? '' const { itemLocale, baseApp } = await storeDetailFetcher({ sdk, itemId, baseAppId }) return json({ itemId, itemLocale, baseApp }) }, Component: () => { const loaderData = useLoaderData() as any return ( ) } } ] }