Skip to content

Commit

Permalink
fix: fixing bugs related to project select component
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerKaiser committed Dec 13, 2023
1 parent 24622aa commit 9260000
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/web/src/components/ProjectsSelect/ProjectsSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const ProjectsSelect: React.FC<ProjectsSelectProps> = ({ onChange, isInva
[selectedProjects],
);

// eslint-disable-next-line react/no-array-index-key
const skeletons = Array(10).map((val, i) => <Skeleton key={i} flexShrink={0} height={'50px'} />);
const skeletons = Array(10)
.fill('')
.map((val, i) => <Skeleton key={i} flexShrink={0} height={'30px'} />); // eslint-disable-line react/no-array-index-key

React.useEffect(() => {
const makeInitialFetch = async () => {
Expand All @@ -31,9 +32,10 @@ export const ProjectsSelect: React.FC<ProjectsSelectProps> = ({ onChange, isInva
void makeInitialFetch();
}, []);

React.useEffect(() => {
onChange(selectedProjects);
}, [onChange, selectedProjects]);
const updatedSelectedProjects = (updatedProjects: Project[]) => {
setSelectedProjects(updatedProjects);
onChange(updatedProjects);
};

return (
<ProjectsSelectStyleContext.Provider
Expand All @@ -50,12 +52,13 @@ export const ProjectsSelect: React.FC<ProjectsSelectProps> = ({ onChange, isInva
projects={projects}
selectedProjects={selectedProjects}
onSelectAll={() => {
setSelectedProjects(projects ?? []);
updatedSelectedProjects(projects ?? []);
}}
onDeselectAll={() => {
setSelectedProjects([]);
updatedSelectedProjects([]);
}}
/>

<Flex direction="column" w="full" maxH={'300px'} overflow="scroll" gap={3} pb="5">
{projects?.length
? projects.map((project) => (
Expand All @@ -65,9 +68,9 @@ export const ProjectsSelect: React.FC<ProjectsSelectProps> = ({ onChange, isInva
isSelected={selectedProjectIds.includes(project.id)}
onClick={() => {
if (selectedProjectIds.includes(project.id)) {
setSelectedProjects(selectedProjects.filter((p) => p.id !== project.id));
updatedSelectedProjects(selectedProjects.filter((p) => p.id !== project.id));
} else {
setSelectedProjects([...selectedProjects, project]);
updatedSelectedProjects([...selectedProjects, project]);
}
}}
/>
Expand Down

0 comments on commit 9260000

Please sign in to comment.