From 44a1cd878242a2e3b83ec67de8ff8941ce2802ad Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 3 Apr 2023 17:09:05 +0200 Subject: [PATCH] Refactor plugin-index plugin for docs (#1694) - delete NewPluginPanel as it's not used - useRef for fuse --- .../src/theme/WoodpeckerPluginList.tsx | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/docs/plugins/woodpecker-plugins/src/theme/WoodpeckerPluginList.tsx b/docs/plugins/woodpecker-plugins/src/theme/WoodpeckerPluginList.tsx index c1b5cb335..8b6df2600 100644 --- a/docs/plugins/woodpecker-plugins/src/theme/WoodpeckerPluginList.tsx +++ b/docs/plugins/woodpecker-plugins/src/theme/WoodpeckerPluginList.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useRef } from 'react'; import Fuse from 'fuse.js'; import Layout from '@theme/Layout'; import './style.css'; @@ -35,33 +35,14 @@ export function WoodpeckerPluginList({ plugins }: { plugins: WoodpeckerPlugin[] const applyForIndexUrl = 'https://github.com/woodpecker-ci/woodpecker/edit/master/docs/plugins/woodpecker-plugins/plugins.json'; - const NewPluginPanel = () => ( - -
-
- - - -
-
-

Add your own plugin

-

You can simply add your own plugin to this index.

-
-
-
- ); - - const fuse = new Fuse(plugins, { - keys: ['name', 'description'], - threshold: 0.3, - }); - const [query, setQuery] = useState(''); - const searchedPlugins = query.length >= 1 ? fuse.search(query) : plugins.map((p) => ({ item: p })); + const fuse = useRef(new Fuse(plugins, { + keys: ['name', 'description'], + threshold: 0.3, + })); + + const searchedPlugins = query.length >= 1 ? fuse.current.search(query).map((p) => ( p.item )) : plugins; return ( @@ -84,9 +65,8 @@ export function WoodpeckerPluginList({ plugins }: { plugins: WoodpeckerPlugin[] className="wp-plugin-search" />
- {/* {query.length == 0 && } */} - {searchedPlugins.map((plugin, idx) => ( - + {searchedPlugins.map((plugin) => ( + ))}