2
2
import { HttpError } from "fresh" ;
3
3
import { define } from "../../util.ts" ;
4
4
import { path } from "../../utils/api.ts" ;
5
- import { FullUser , Scope , User } from "../../utils/api_types.ts" ;
5
+ import { FullUser , Package , Scope , User } from "../../utils/api_types.ts" ;
6
6
import { ListPanel } from "../../components/ListPanel.tsx" ;
7
7
import { AccountLayout } from "../account/(_components)/AccountLayout.tsx" ;
8
8
@@ -32,25 +32,39 @@ export default define.page<typeof handler>(function UserPage({ data, state }) {
32
32
</ div >
33
33
) }
34
34
35
- {
36
- /*<div>
37
- <span class="font-semibold">Recently published</span>
38
- <div class="text-tertiary text-base"
39
- TODO: all packages recently published by this user
40
- </div>
41
- </div>*/
42
- }
35
+ { data . packages . length > 0
36
+ ? (
37
+ < ListPanel
38
+ title = "Recently published"
39
+ subtitle = { state . user ?. id === data . user . id
40
+ ? "Packages you have published."
41
+ : "Packages this user has published." }
42
+ // deno-lint-ignore jsx-no-children-prop
43
+ children = { data . packages . map ( ( pkg ) => ( {
44
+ value : `@${ pkg . scope } /${ pkg . name } ` ,
45
+ href : `/@${ pkg . scope } /${ pkg . name } ` ,
46
+ } ) ) }
47
+ />
48
+ )
49
+ : (
50
+ < div class = "p-3 text-jsr-gray-500 text-center italic" >
51
+ { state . user ?. id === data . user . id ? "You have" : "This user has" }
52
+ { " " }
53
+ not published any packages recently.
54
+ </ div >
55
+ ) }
43
56
</ div >
44
57
</ AccountLayout >
45
58
) ;
46
59
} ) ;
47
60
48
61
export const handler = define . handlers ( {
49
62
async GET ( ctx ) {
50
- const [ currentUser , userRes , scopesRes ] = await Promise . all ( [
63
+ const [ currentUser , userRes , scopesRes , packagesRes ] = await Promise . all ( [
51
64
ctx . state . userPromise ,
52
65
ctx . state . api . get < User > ( path `/users/${ ctx . params . id } ` ) ,
53
66
ctx . state . api . get < Scope [ ] > ( path `/users/${ ctx . params . id } /scopes` ) ,
67
+ ctx . state . api . get < Package [ ] > ( path `/users/${ ctx . params . id } /packages` ) ,
54
68
] ) ;
55
69
if ( currentUser instanceof Response ) return currentUser ;
56
70
@@ -62,6 +76,7 @@ export const handler = define.handlers({
62
76
throw userRes ; // gracefully handle errors
63
77
}
64
78
if ( ! scopesRes . ok ) throw scopesRes ; // gracefully handle errors
79
+ if ( ! packagesRes . ok ) throw packagesRes ; // gracefully handle errors
65
80
66
81
let user : User | FullUser = userRes . data ;
67
82
if ( ctx . params . id === currentUser ?. id ) {
@@ -75,6 +90,7 @@ export const handler = define.handlers({
75
90
data : {
76
91
user,
77
92
scopes : scopesRes . data ,
93
+ packages : packagesRes . data ,
78
94
} ,
79
95
} ;
80
96
} ,
0 commit comments