@@ -2,9 +2,9 @@ import './style.scss';
22import AdSense from 'components/adsense' ;
33import alert from 'components/dialogs/alert' ;
44import confirm from 'components/dialogs/confirm' ;
5- import prompt from 'components/dialogs/prompt' ;
65import select from 'components/dialogs/select' ;
7- import { calcRating , capitalize , getLoggedInUser , hideLoading , showLoading , since } from 'lib/helpers' ;
6+ import PluginStatus from 'components/pluginStatus' ;
7+ import { calcRating , getLoggedInUser , hideLoading , showLoading , since } from 'lib/helpers' ;
88import Router from 'lib/Router' ;
99
1010export default function Plugins ( { user, orderBy, status, name } ) {
@@ -75,11 +75,7 @@ function Plugin({
7575 < div title = 'Downloads counter' >
7676 { downloads . toLocaleString ( ) } < span className = 'icon download' />
7777 </ div >
78- { Boolean ( status ) && (
79- < span data-id = { id } onclick = { isAdmin ? changePluginStatus : undefined } title = 'Plugin status' className = { `status-indicator ${ status } ` } >
80- { status }
81- </ span >
82- ) }
78+ < PluginStatus status = { status } id = { id } />
8379 < div > { calcRating ( upVotes , downVotes ) } </ div >
8480 { comments > 0 && (
8581 < div >
@@ -154,49 +150,6 @@ async function deletePlugin(e, id) {
154150 }
155151}
156152
157- /**
158- *
159- * @param {MouseEvent } e
160- * @returns
161- */
162- async function changePluginStatus ( e ) {
163- e . preventDefault ( ) ;
164- e . stopPropagation ( ) ;
165- try {
166- const { target } = e ;
167- const { id } = target . dataset ;
168- const status = await select ( 'Change plugin status' , [ 'approve' , 'reject' ] ) ;
169- if ( ! status ) return ;
170-
171- let reason ;
172- if ( status === 'reject' ) {
173- reason = await prompt ( 'Reason' , { type : 'textarea' } ) ;
174- }
175- showLoading ( ) ;
176- const res = await fetch ( '/api/plugin' , {
177- method : 'PATCH' ,
178- headers : {
179- 'Content-Type' : 'application/json' ,
180- } ,
181- body : JSON . stringify ( { status, id, reason } ) ,
182- } ) ;
183- const data = await res . json ( ) ;
184- if ( data . error ) {
185- alert ( 'Error' , data . error ) ;
186- return ;
187- }
188-
189- const pluginRes = await fetch ( `/api/plugin/${ id } ` ) ;
190- const pluginData = await pluginRes . json ( ) ;
191- target . textContent = capitalize ( pluginData . status ) ;
192- target . className = pluginData . status ;
193- } catch ( error ) {
194- alert ( 'Error' , error . message ) ;
195- } finally {
196- hideLoading ( ) ;
197- }
198- }
199-
200153function Actions ( { user, pluginsUser, id, isAdmin } ) {
201154 const $el = < small className = 'icon-buttons' /> ;
202155 const $delete = < span title = 'delete plugin' className = 'link icon delete danger' onclick = { ( e ) => deletePlugin ( e , id ) } /> ;
0 commit comments