mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix(useProjectPicker): ensure project selection resets correctly when project picker is opened
This commit is contained in:
@@ -29,14 +29,16 @@ export function useProjectPicker({
|
|||||||
return projects.filter((project) => project.name.toLowerCase().includes(query));
|
return projects.filter((project) => project.name.toLowerCase().includes(query));
|
||||||
}, [projects, projectSearchQuery]);
|
}, [projects, projectSearchQuery]);
|
||||||
|
|
||||||
const getCurrentProjectIndex = () => {
|
// Reset selection when filtered results change and project picker is open
|
||||||
return currentProject ? filteredProjects.findIndex((p) => p.id === currentProject.id) : -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Reset selection when filtered results change
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isProjectPickerOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!projectSearchQuery.trim()) {
|
if (!projectSearchQuery.trim()) {
|
||||||
const currentIndex = getCurrentProjectIndex();
|
const currentIndex = currentProject
|
||||||
|
? filteredProjects.findIndex((p) => p.id === currentProject.id)
|
||||||
|
: -1;
|
||||||
if (currentIndex !== -1) {
|
if (currentIndex !== -1) {
|
||||||
setSelectedProjectIndex(currentIndex);
|
setSelectedProjectIndex(currentIndex);
|
||||||
return;
|
return;
|
||||||
@@ -44,7 +46,7 @@ export function useProjectPicker({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSelectedProjectIndex(0);
|
setSelectedProjectIndex(0);
|
||||||
}, [filteredProjects.length, projectSearchQuery, currentProject]);
|
}, [isProjectPickerOpen, filteredProjects.length, projectSearchQuery, currentProject]);
|
||||||
|
|
||||||
// Reset search query when dropdown closes, set to current project index when it opens
|
// Reset search query when dropdown closes, set to current project index when it opens
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -52,12 +54,6 @@ export function useProjectPicker({
|
|||||||
setProjectSearchQuery('');
|
setProjectSearchQuery('');
|
||||||
setSelectedProjectIndex(0);
|
setSelectedProjectIndex(0);
|
||||||
} else {
|
} else {
|
||||||
// Set the selected project index to the current project index
|
|
||||||
const currentIndex = getCurrentProjectIndex();
|
|
||||||
if (currentIndex !== -1) {
|
|
||||||
setSelectedProjectIndex(currentIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Focus the search input when dropdown opens
|
// Focus the search input when dropdown opens
|
||||||
// Small delay to ensure the dropdown is rendered
|
// Small delay to ensure the dropdown is rendered
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user