Skip to content

Commit

Permalink
fix: PluginStoreDialog refactor: plugins (danny-avila#1047)
Browse files Browse the repository at this point in the history
* fix(PluginStoreDialog) can't search on page 2/3.. & reset to page 1 when install and unistall

* var fix

* removed plugins that aren't working

* remove prompt perfect beacuase it isn't working

* fix(PluginStoreItem) set page 1 and reset search when dialog is close
  • Loading branch information
berry-13 authored Oct 12, 2023
1 parent 2b79eaf commit bf9f8b3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 80 deletions.
17 changes: 0 additions & 17 deletions api/app/clients/tools/.well-known/BrowserOp.json

This file was deleted.

18 changes: 0 additions & 18 deletions api/app/clients/tools/.well-known/Diagrams.json

This file was deleted.

22 changes: 0 additions & 22 deletions api/app/clients/tools/.well-known/aitoolhunt.json

This file was deleted.

18 changes: 0 additions & 18 deletions api/app/clients/tools/.well-known/rephrase.json

This file was deleted.

31 changes: 26 additions & 5 deletions client/src/components/Plugins/Store/PluginStoreDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
const [showPluginAuthForm, setShowPluginAuthForm] = useState<boolean>(false);
const [error, setError] = useState<boolean>(false);
const [errorMessage, setErrorMessage] = useState<string>('');
const [searchChanged, setSearchChanged] = useState(false);

const handleInstallError = (error: TError) => {
setError(true);
Expand Down Expand Up @@ -127,23 +128,40 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
const filteredPlugins = availablePlugins?.filter((plugin) =>
plugin.name.toLowerCase().includes(searchValue.toLowerCase()),
);

const handleSearch = (e) => {
setSearchValue(e.target.value);
setSearchChanged(true);
};

useEffect(() => {
if (user && user.plugins) {
setUserPlugins(user.plugins);
}

if (filteredPlugins) {
setMaxPage(Math.ceil(filteredPlugins.length / itemsPerPage));
setCurrentPage(1); // Reset the current page to 1 whenever the filtered list changes
if (searchChanged) {
setCurrentPage(1);
setSearchChanged(false);
}
}
}, [availablePlugins, itemsPerPage, user, searchValue]); // Add searchValue to the dependency list
}, [availablePlugins, itemsPerPage, user, searchValue, filteredPlugins, searchChanged]);

const handleChangePage = (page: number) => {
setCurrentPage(page);
};

return (
<Dialog open={isOpen} onClose={() => setIsOpen(false)} className="relative z-[102]">
<Dialog
open={isOpen}
onClose={() => {
setIsOpen(false);
setCurrentPage(1);
setSearchValue('');
}}
className="relative z-[102]"
>
{/* The backdrop, rendered as a fixed sibling to the panel container */}
<div className="fixed inset-0 bg-gray-500/90 transition-opacity dark:bg-gray-800/90" />
{/* Full-screen container to center the panel */}
Expand All @@ -163,7 +181,10 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
<div>
<div className="sm:mt-0">
<button
onClick={() => setIsOpen(false)}
onClick={() => {
setIsOpen(false);
setCurrentPage(1);
}}
className="inline-block text-gray-500 hover:text-gray-100"
tabIndex={0}
>
Expand Down Expand Up @@ -194,7 +215,7 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
<input
type="text"
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
onChange={handleSearch}
placeholder={localize('com_nav_plugin_search')}
style={{
width: '100%',
Expand Down

0 comments on commit bf9f8b3

Please sign in to comment.