@@ -7,47 +7,58 @@ import PluginStatus from 'components/pluginStatus';
77import { calcRating , getLoggedInUser , hideLoading , showLoading , since } from 'lib/helpers' ;
88import Router from 'lib/Router' ;
99
10- export default function Plugins ( { user, orderBy, status, name } ) {
10+ export default async function Plugins ( { user, orderBy, status, name, editor } ) {
1111 const el = < div className = 'plugins' data-msg = 'loading...' /> ;
1212
13- ( async ( ) => {
14- try {
15- showLoading ( ) ;
16- let url = '/api/plugin' ;
17-
18- if ( user ) {
19- url += `?user=${ user } ` ;
20- } else if ( status !== undefined ) {
21- url += `?status=${ status } ` ;
22- } else if ( name ) {
23- url += `?name=${ name } ` ;
24- } else if ( orderBy ) {
25- url += `?orderBy=${ orderBy } ` ;
26- }
13+ try {
14+ showLoading ( ) ;
15+ const params = new URLSearchParams ( ) ;
16+
17+ if ( user ) {
18+ params . set ( 'user' , user ) ;
19+ }
20+
21+ if ( status !== undefined ) {
22+ params . set ( 'status' , status ) ;
23+ }
24+
25+ if ( name ) {
26+ params . set ( 'name' , name ) ;
27+ }
28+
29+ if ( editor ) {
30+ params . set ( 'supported_editor' , editor ) ;
31+ }
2732
28- const res = await fetch ( url ) ;
29- const { isAdmin, id : userId } = ( await getLoggedInUser ( ) ) || { } ;
30- const plugins = await res . json ( ) ;
31- const adsPosition = [ 2 , 15 , 28 ] ;
32-
33- el . setAttribute ( 'data-msg' , 'No plugins found. :(' ) ;
34- for ( let i = 0 ; i < plugins . length ; i ++ ) {
35- const plugin = plugins [ i ] ;
36- if ( adsPosition . includes ( i ) || ( i > 33 && Math . random ( ) < 0.1 ) ) {
37- el . append ( < AdSense className = 'plugin' style = { { position : 'relative' } } /> ) ;
38- }
39- el . append ( < Plugin { ...plugin } isAdmin = { isAdmin } userId = { userId } /> ) ;
33+ if ( orderBy ) {
34+ params . set ( 'orderBy' , orderBy ) ;
35+ }
36+
37+ const query = params . toString ( ) ;
38+ const url = `/api/plugin${ query ? `?${ query } ` : '' } ` ;
39+
40+ const res = await fetch ( url ) ;
41+ const { isAdmin, id : userId } = ( await getLoggedInUser ( ) ) || { } ;
42+ const plugins = await res . json ( ) ;
43+ const adsPosition = [ 2 , 15 , 28 ] ;
44+
45+ el . setAttribute ( 'data-msg' , 'No plugins found. :(' ) ;
46+ for ( let i = 0 ; i < plugins . length ; i ++ ) {
47+ const plugin = plugins [ i ] ;
48+ if ( adsPosition . includes ( i ) || ( i > 33 && Math . random ( ) < 0.1 ) ) {
49+ el . append ( < AdSense className = 'plugin' style = { { position : 'relative' } } /> ) ;
4050 }
41- } catch ( error ) {
42- el . append (
43- < div className = 'error' >
44- < h2 > { error . error } </ h2 >
45- </ div > ,
46- ) ;
47- } finally {
48- hideLoading ( ) ;
51+ el . append ( < Plugin { ...plugin } isAdmin = { isAdmin } userId = { userId } /> ) ;
4952 }
50- } ) ( ) ;
53+ } catch ( error ) {
54+ el . append (
55+ < div className = 'error' >
56+ < h2 > { error . error } </ h2 >
57+ </ div > ,
58+ ) ;
59+ } finally {
60+ hideLoading ( ) ;
61+ }
5162
5263 return el ;
5364}
@@ -62,12 +73,14 @@ function Plugin({
6273 downloads,
6374 votes_up : upVotes ,
6475 user_id : pluginUser ,
65- package_updated_at : updatedAt ,
6676 votes_down : downVotes ,
6777 comment_count : comments ,
78+ supported_editor : editorType ,
79+ package_updated_at : updatedAt ,
6880} ) {
6981 return (
7082 < a href = { `/plugin/${ id } ` } className = 'plugin' >
83+ < span className = { `badge editor-type ${ editorType } ` } />
7184 < div className = 'plugin-icon' style = { { backgroundImage : `url(/plugin-icon/${ id } )` } } />
7285 < div className = 'plugin-info' >
7386 < h2 style = { { whiteSpace : 'nowrap' , overflow : 'hidden' , textOverflow : 'ellipsis' } } > { name } </ h2 >
0 commit comments