@@ -18,15 +18,15 @@ import {
1818 type PackageListingUpdateRequestData ,
1919 packageUnlist ,
2020} from "@thunderstore/thunderstore-api" ;
21- import { DapperTs } from "@thunderstore/dapper-ts" ;
2221import { type OutletContextShape } from "~/root" ;
23- import { getSessionTools } from "cyberstorm/security/publicEnvVariables" ;
2422import { PageHeader } from "~/commonComponents/PageHeader/PageHeader" ;
2523import { useStrongForm } from "cyberstorm/utils/StrongForm/useStrongForm" ;
2624import { useReducer } from "react" ;
2725import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
2826import { faBan , faCheck } from "@fortawesome/pro-solid-svg-icons" ;
2927import { ApiAction } from "@thunderstore/ts-api-react-actions" ;
28+ import { getDapperForRequest } from "cyberstorm/utils/dapperSingleton" ;
29+ import { getPrivateListing } from "app/p/listingUtils" ;
3030
3131export const meta : MetaFunction < typeof clientLoader > = ( { data } ) => {
3232 return [
@@ -44,28 +44,23 @@ export async function loader({ params }: LoaderFunctionArgs) {
4444 return undefined ;
4545}
4646
47- // TODO: Needs to check if package is available for the logged in user
48- export async function clientLoader ( { params } : LoaderFunctionArgs ) {
47+ export async function clientLoader ( { params, request } : LoaderFunctionArgs ) {
4948 const { communityId, namespaceId, packageId } = params ;
5049
5150 if ( ! communityId || ! namespaceId || ! packageId ) {
5251 throw package404 ;
5352 }
5453
5554 try {
56- const tools = getSessionTools ( ) ;
57- const dapper = new DapperTs ( ( ) => {
58- return {
59- apiHost : tools ?. getConfig ( ) . apiHost ,
60- sessionId : tools ?. getConfig ( ) . sessionId ,
61- } ;
62- } ) ;
55+ const dapper = getDapperForRequest ( request ) ;
6356
64- const permissions = await dapper . getPackagePermissions (
65- communityId ,
66- namespaceId ,
67- packageId
68- ) ;
57+ // Fetch everything at once for faster page load, even if we may
58+ // overfetch in case we lack authentication/authorization.
59+ const [ listing , permissions , filters ] = await Promise . all ( [
60+ getPrivateListing ( dapper , { communityId, namespaceId, packageId } ) ,
61+ dapper . getPackagePermissions ( communityId , namespaceId , packageId ) ,
62+ dapper . getCommunityFilters ( communityId ) ,
63+ ] ) ;
6964
7065 if ( ! permissions ) {
7166 throw new Response ( "Unauthenticated" , { status : 401 } ) ;
@@ -76,15 +71,7 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
7671 throw new Response ( "Unauthorized" , { status : 403 } ) ;
7772 }
7873
79- return {
80- listing : await dapper . getPackageListingDetails (
81- communityId ,
82- namespaceId ,
83- packageId
84- ) ,
85- filters : await dapper . getCommunityFilters ( communityId ) ,
86- permissions : permissions ,
87- } ;
74+ return { listing, permissions, filters } ;
8875 } catch ( error ) {
8976 throw error instanceof ApiError ? package404 : error ;
9077 }
0 commit comments