Skip to content

Commit

Permalink
feat: Added search and sort plugins by names
Browse files Browse the repository at this point in the history
  • Loading branch information
YangfanZhangA authored and d4rkr00t committed Apr 2, 2024
1 parent b156e88 commit d988242
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
17 changes: 10 additions & 7 deletions src/components/search-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useCallback, useState } from "react";
import theme from "../theme";
import { css } from "@compiled/react";

Expand Down Expand Up @@ -35,14 +35,17 @@ const searchBarWrapperStyles = css({
const SearchBar: React.FC<SearchBarProps> = ({ onSearch }) => {
const [query, setQuery] = useState("");

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setQuery(event.target.value);
onSearch(event.target.value);
};
const handleInputChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setQuery(event.target.value);
onSearch(event.target.value);
},
[onSearch]
);

const handleSearch = () => {
const handleSearch = useCallback(() => {
onSearch(query);
};
}, [query, onSearch]);

return (
<div css={searchBarWrapperStyles}>
Expand Down
23 changes: 14 additions & 9 deletions src/tabs/plugins.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useCallback, useState } from "react";
import type { Plugin } from "prosemirror-state";
import { InfoPanel } from "../components/info-panel";
import { Heading } from "../components/heading";
Expand Down Expand Up @@ -46,14 +46,19 @@ export default function PluginsTab() {

const selectedPluginState = selectedPlugin.getState(state);

const handleSearch = (input: string) => {
const filteredPlugins = (state.plugins as any as Plugin<any>[]).filter(
(plugin) => {
return (plugin as any).key.toLowerCase().includes(input.toLowerCase());
}
);
setPluginsLocal(filteredPlugins);
};
const handleSearch = useCallback(
(input: string) => {
const filteredPlugins = (state.plugins as any as Plugin<any>[]).filter(
(plugin) => {
return (plugin as any).key
.toLowerCase()
.includes(input.toLowerCase());
}
);
setPluginsLocal(filteredPlugins);
},
[state.plugins]
);

const handleClickSort = () => {
setSortOrder(!sortAsc);
Expand Down

0 comments on commit d988242

Please sign in to comment.