1
1
import type { LoaderFunctionArgs , MetaFunction } from "@remix-run/node" ;
2
- import { useLoaderData } from "@remix-run/react" ;
2
+ import { useLoaderData , useOutletContext } from "@remix-run/react" ;
3
3
import {
4
4
CyberstormLink ,
5
5
NewBreadCrumbs ,
@@ -9,6 +9,8 @@ import "./Dependants.css";
9
9
import { PackageSearch } from "~/commonComponents/PackageSearch/PackageSearch" ;
10
10
import { ApiError } from "@thunderstore/thunderstore-api" ;
11
11
import { DapperTs } from "@thunderstore/dapper-ts" ;
12
+ import { PackageOrderOptions } from "../../commonComponents/PackageSearch/components/PackageOrder" ;
13
+ import { OutletContextShape } from "../../root" ;
12
14
13
15
export const meta : MetaFunction < typeof loader > = ( { data } ) => {
14
16
return [
@@ -27,17 +29,23 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
27
29
} ;
28
30
} ) ;
29
31
const searchParams = new URL ( request . url ) . searchParams ;
30
- const order = searchParams . get ( "order" ) ;
32
+ const ordering =
33
+ searchParams . get ( "ordering" ) ?? PackageOrderOptions . Updated ;
31
34
const page = searchParams . get ( "page" ) ;
32
35
const search = searchParams . get ( "search" ) ;
33
36
const includedCategories = searchParams . get ( "includedCategories" ) ;
34
37
const excludedCategories = searchParams . get ( "excludedCategories" ) ;
35
38
const section = searchParams . get ( "section" ) ;
36
39
const nsfw = searchParams . get ( "nsfw" ) ;
37
40
const deprecated = searchParams . get ( "deprecated" ) ;
41
+ const community = await dapper . getCommunity ( params . communityId ) ;
42
+ const filters = await dapper . getCommunityFilters ( params . communityId ) ;
43
+ const sortedSections = filters . sections . sort (
44
+ ( a , b ) => b . priority - a . priority
45
+ ) ;
38
46
return {
39
- community : await dapper . getCommunity ( params . communityId ) ,
40
- filters : await dapper . getCommunityFilters ( params . communityId ) ,
47
+ community : community ,
48
+ filters : filters ,
41
49
listing : await dapper . getPackageListingDetails (
42
50
params . communityId ,
43
51
params . namespaceId ,
@@ -50,21 +58,27 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
50
58
namespaceId : params . namespaceId ,
51
59
packageName : params . packageId ,
52
60
} ,
53
- order ?? "" ,
61
+ ordering ?? "" ,
54
62
page === null ? undefined : Number ( page ) ,
55
63
search ?? "" ,
56
64
includedCategories ?. split ( "," ) ?? undefined ,
57
65
excludedCategories ?. split ( "," ) ?? undefined ,
58
- section ?? "" ,
66
+ section
67
+ ? section === "all"
68
+ ? ""
69
+ : section
70
+ : sortedSections && sortedSections [ 0 ]
71
+ ? sortedSections [ 0 ] . uuid
72
+ : "" ,
59
73
nsfw === "true" ? true : false ,
60
74
deprecated === "true" ? true : false
61
75
) ,
76
+ sortedSections : sortedSections ,
62
77
} ;
63
78
} catch ( error ) {
64
79
if ( error instanceof ApiError ) {
65
80
throw new Response ( "Package not found" , { status : 404 } ) ;
66
81
} else {
67
- // REMIX TODO: Add sentry
68
82
throw error ;
69
83
}
70
84
}
@@ -77,17 +91,23 @@ export async function clientLoader({ request, params }: LoaderFunctionArgs) {
77
91
try {
78
92
const dapper = window . Dapper ;
79
93
const searchParams = new URL ( request . url ) . searchParams ;
80
- const order = searchParams . get ( "order" ) ;
94
+ const ordering =
95
+ searchParams . get ( "ordering" ) ?? PackageOrderOptions . Updated ;
81
96
const page = searchParams . get ( "page" ) ;
82
97
const search = searchParams . get ( "search" ) ;
83
98
const includedCategories = searchParams . get ( "includedCategories" ) ;
84
99
const excludedCategories = searchParams . get ( "excludedCategories" ) ;
85
100
const section = searchParams . get ( "section" ) ;
86
101
const nsfw = searchParams . get ( "nsfw" ) ;
87
102
const deprecated = searchParams . get ( "deprecated" ) ;
103
+ const community = await dapper . getCommunity ( params . communityId ) ;
104
+ const filters = await dapper . getCommunityFilters ( params . communityId ) ;
105
+ const sortedSections = filters . sections . sort (
106
+ ( a , b ) => b . priority - a . priority
107
+ ) ;
88
108
return {
89
- community : await dapper . getCommunity ( params . communityId ) ,
90
- filters : await dapper . getCommunityFilters ( params . communityId ) ,
109
+ community : community ,
110
+ filters : filters ,
91
111
listing : await dapper . getPackageListingDetails (
92
112
params . communityId ,
93
113
params . namespaceId ,
@@ -100,32 +120,39 @@ export async function clientLoader({ request, params }: LoaderFunctionArgs) {
100
120
namespaceId : params . namespaceId ,
101
121
packageName : params . packageId ,
102
122
} ,
103
- order ?? "" ,
123
+ ordering ?? "" ,
104
124
page === null ? undefined : Number ( page ) ,
105
125
search ?? "" ,
106
126
includedCategories ?. split ( "," ) ?? undefined ,
107
127
excludedCategories ?. split ( "," ) ?? undefined ,
108
- section ?? "" ,
128
+ section
129
+ ? section === "all"
130
+ ? ""
131
+ : section
132
+ : sortedSections && sortedSections [ 0 ]
133
+ ? sortedSections [ 0 ] . uuid
134
+ : "" ,
109
135
nsfw === "true" ? true : false ,
110
136
deprecated === "true" ? true : false
111
137
) ,
138
+ sortedSections : sortedSections ,
112
139
} ;
113
140
} catch ( error ) {
114
141
if ( error instanceof ApiError ) {
115
- throw new Response ( "Community not found" , { status : 404 } ) ;
142
+ throw new Response ( "Package not found" , { status : 404 } ) ;
116
143
} else {
117
- // REMIX TODO: Add sentry
118
144
throw error ;
119
145
}
120
146
}
121
147
}
122
- throw new Response ( "Community not found" , { status : 404 } ) ;
148
+ throw new Response ( "Package not found" , { status : 404 } ) ;
123
149
}
124
150
125
151
export default function Dependants ( ) {
126
- const { community, filters, listing, listings } = useLoaderData <
127
- typeof loader | typeof clientLoader
128
- > ( ) ;
152
+ const { community, filters, listing, listings, sortedSections } =
153
+ useLoaderData < typeof loader | typeof clientLoader > ( ) ;
154
+
155
+ const outletContext = useOutletContext ( ) as OutletContextShape ;
129
156
130
157
return (
131
158
< div className = "container container--y container--full layout__content" >
@@ -178,7 +205,9 @@ export default function Dependants() {
178
205
< PackageSearch
179
206
listings = { listings }
180
207
packageCategories = { filters . package_categories }
181
- sections = { filters . sections }
208
+ sections = { sortedSections }
209
+ config = { outletContext . requestConfig }
210
+ currentUser = { outletContext . currentUser }
182
211
/>
183
212
</ section >
184
213
</ div >
0 commit comments