mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Move away from using toast in the plugin search (#6441)
This commit is contained in:
parent
8f3e6a4d8c
commit
a637921160
2 changed files with 34 additions and 34 deletions
|
@ -93,25 +93,20 @@ export const HomePage = () => {
|
||||||
if (!pluginsSocket) {
|
if (!pluginsSocket) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginsSocket?.emit('search', searchParams)
|
pluginsSocket?.emit('search', searchParams)
|
||||||
|
|
||||||
|
|
||||||
pluginsSocket!.on('results:search', (data: {
|
pluginsSocket!.on('results:search', (data: {
|
||||||
results: PluginDef[]
|
results: PluginDef[]
|
||||||
}) => {
|
}) => {
|
||||||
if (Array.isArray(data.results) && data.results.length > 0) {
|
|
||||||
setPlugins(data.results)
|
setPlugins(data.results)
|
||||||
} else {
|
})
|
||||||
|
pluginsSocket!.on('results:searcherror', (data: {error: string}) => {
|
||||||
|
console.log(data.error)
|
||||||
useStore.getState().setToastState({
|
useStore.getState().setToastState({
|
||||||
open: true,
|
open: true,
|
||||||
title: "Error retrieving plugins",
|
title: "Error retrieving plugins",
|
||||||
success: false
|
success: false
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}, [searchParams, pluginsSocket]);
|
}, [searchParams, pluginsSocket]);
|
||||||
|
|
||||||
const uninstallPlugin = (pluginName: string)=>{
|
const uninstallPlugin = (pluginName: string)=>{
|
||||||
|
@ -125,7 +120,6 @@ export const HomePage = () => {
|
||||||
setPlugins(plugins.filter(plugin=>plugin.name !== pluginName))
|
setPlugins(plugins.filter(plugin=>plugin.name !== pluginName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
useDebounce(()=>{
|
useDebounce(()=>{
|
||||||
setSearchParams({
|
setSearchParams({
|
||||||
...searchParams,
|
...searchParams,
|
||||||
|
@ -179,7 +173,8 @@ export const HomePage = () => {
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody style={{overflow: 'auto'}}>
|
<tbody style={{overflow: 'auto'}}>
|
||||||
{plugins.map((plugin) => {
|
{(plugins.length > 0) ?
|
||||||
|
plugins.map((plugin) => {
|
||||||
return <tr key={plugin.name}>
|
return <tr key={plugin.name}>
|
||||||
<td><a rel="noopener noreferrer" href={`https://npmjs.com/${plugin.name}`} target="_blank">{plugin.name}</a></td>
|
<td><a rel="noopener noreferrer" href={`https://npmjs.com/${plugin.name}`} target="_blank">{plugin.name}</a></td>
|
||||||
<td>{plugin.description}</td>
|
<td>{plugin.description}</td>
|
||||||
|
@ -189,7 +184,10 @@ export const HomePage = () => {
|
||||||
<IconButton icon={<Download/>} onClick={() => installPlugin(plugin.name)} title={<Trans i18nKey="admin_plugins.available_install.value"/>}/>
|
<IconButton icon={<Download/>} onClick={() => installPlugin(plugin.name)} title={<Trans i18nKey="admin_plugins.available_install.value"/>}/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
})}
|
})
|
||||||
|
:
|
||||||
|
<tr><td colSpan={5}>{searchTerm == '' ? <Trans i18nKey="pad.loading"/>: <Trans i18nKey="admin_plugins.available_not-found"/>}</td></tr>
|
||||||
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,6 +9,8 @@ import {PackageData} from "../../types/PackageInfo";
|
||||||
|
|
||||||
const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
|
const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
import log4js from 'log4js';
|
||||||
|
const logger = log4js.getLogger('adminPlugins');
|
||||||
|
|
||||||
|
|
||||||
exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
||||||
|
@ -61,6 +63,7 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
||||||
|
|
||||||
socket.on('search', async (query: QueryType) => {
|
socket.on('search', async (query: QueryType) => {
|
||||||
try {
|
try {
|
||||||
|
if (query.searchTerm) logger.info(`Plugin search: ${query.searchTerm}'`);
|
||||||
const results = await search(query.searchTerm, /* maxCacheAge:*/ 60 * 10);
|
const results = await search(query.searchTerm, /* maxCacheAge:*/ 60 * 10);
|
||||||
let res = Object.keys(results)
|
let res = Object.keys(results)
|
||||||
.map((pluginName) => results[pluginName])
|
.map((pluginName) => results[pluginName])
|
||||||
|
@ -68,10 +71,9 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
||||||
res = sortPluginList(res, query.sortBy, query.sortDir)
|
res = sortPluginList(res, query.sortBy, query.sortDir)
|
||||||
.slice(query.offset, query.offset + query.limit);
|
.slice(query.offset, query.offset + query.limit);
|
||||||
socket.emit('results:search', {results: res, query});
|
socket.emit('results:search', {results: res, query});
|
||||||
} catch (er) {
|
} catch (err: any) {
|
||||||
console.error(er);
|
logger.error(`Error searching plugins: ${err}`);
|
||||||
|
socket.emit('results:searcherror', {error: err.message, query});
|
||||||
socket.emit('results:search', {results: {}, query});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue