Skip to content

Commit

Permalink
feat: search feature
Browse files Browse the repository at this point in the history
Signed-off-by: Karthik Ayangar <[email protected]>
  • Loading branch information
kituuu committed Jan 20, 2024
1 parent 9719e1a commit f8efe9d
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 56 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@reduxjs/toolkit": "^1.9.6",
"@reduxjs/toolkit": "^1.9.7",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const SearchBar = () => {
};
const handleSearch = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (search !== '') dispatch(searchAction(search));
dispatch(searchAction(search));
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/features/AddProject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const AddProject = () => {
if (token && spaceName) {
try {
const res = await getOrgProjects(token, spaceName);
console.log(res.data.projects);
setOrgProjects(res.data.projects);
} catch (e) {}
}
Expand Down
22 changes: 12 additions & 10 deletions src/features/project-members/components/MemberCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ const MemberCard = ({
name: string;
role: string;
}) => {
const handleRemove = () => {
console.log('Remove member');
}
const handleRemove = () => {
console.log('Remove member');
};
return (
<div className='member-card'>
<div className='member-info'>
<img src={image} alt='image' />
<h1 className='member-name'>{name}</h1>
</div>
<div className='member-actions'>
<div className="select-overlay">
<select name='role' id='role' defaultValue={role.toLowerCase()}>
<option value='maintainer'>Maintainer</option>
<option value='manager'>Manager</option>
<option value='member'>Member</option>
</select>
<div className='select-overlay'>
<select name='role' id='role' defaultValue={role.toLowerCase()}>
<option value='maintainer'>Maintainer</option>
<option value='manager'>Manager</option>
<option value='member'>Member</option>
</select>
</div>
<button className='member-remove-btn' onClick={handleRemove}>Remove</button>
<button className='member-remove-btn' onClick={handleRemove}>
Remove
</button>
</div>
</div>
);
Expand Down
10 changes: 5 additions & 5 deletions src/features/project-members/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
font-size: 1.2rem;
}
.select-overlay {
padding-right: 1rem;
background: #402aa4;
cursor: pointer;
padding-right: 1rem;
background: #402aa4;
cursor: pointer;
}
select {
border: none;
Expand All @@ -136,8 +136,8 @@
cursor: pointer;
}
option {
padding: 1rem;
margin: 2rem;
padding: 1rem;
margin: 2rem;
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/features/workspace-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import UserContext from 'app/context/user/userContext';
import { UserOrgDetails, getUserOrgs } from 'app/api/user';
import loader from '../../app/assets/gifs/loader.gif';
import { Navigate, useNavigate } from 'react-router-dom';
import { useSelector } from 'react-redux';

const WorkspaceView = () => {
const userContext = useContext(UserContext);
Expand All @@ -28,6 +29,7 @@ const WorkspaceView = () => {
setIsLoad(false);
}
};
const searchValue = useSelector((state: any) => state.searchKeyword.value);

useEffect(() => {
fetchData();
Expand All @@ -36,6 +38,7 @@ const WorkspaceView = () => {
userContext?.username,
navigate,
userContext?.setUserOrgs,
searchValue,
]);

return (
Expand All @@ -54,8 +57,12 @@ const WorkspaceView = () => {
<img src={loader} className='loader' />
) : (
userContext?.userOrgs &&
Object.entries(userContext.userOrgs.userOrgs).map(
([orgName, details]) => {
Object.entries(userContext.userOrgs.userOrgs)
.filter(([key, value]) => {
if (key.toLowerCase().includes(searchValue.toLowerCase()))
return [key, value];
})
.map(([orgName, details]) => {
return (
<WorkspaceCard
key={orgName}
Expand All @@ -66,8 +73,7 @@ const WorkspaceView = () => {
archeives={archeives}
/>
);
}
)
})
)}
</div>
</div>
Expand Down
55 changes: 28 additions & 27 deletions src/features/workspace/components/projectCardContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ProjectCard from '../projectCard';
import './index.scss';
import { Projects } from 'app/api/organization';
import { ProjectsGithubData } from 'app/api/githubData';
import { useSelector } from 'react-redux';

interface Props {
weekly: boolean;
Expand All @@ -21,38 +22,38 @@ const ProjectCardCont: React.FC<Props> = ({
weeklyOrgProjectsData,
archives,
}) => {
useEffect(() => {}, [weekly]);
const searchValue = useSelector((state: any) => state.searchKeyword.value);

useEffect(() => {
console.log(orgProjects);
}, [weekly, searchValue]);

return (
<>
<div className='projectcard-cont'>
{orgProjects &&
Object.entries(orgProjects).map(([key, value]) => {
return (
archives === value.archeive &&
(weekly ? (
<ProjectCard
key={key}
orgName={orgName}
projectName={key}
status={value}
githubData={
weeklyOrgProjectsData ? weeklyOrgProjectsData[key] : null
}
/>
) : (
<ProjectCard
key={key}
orgName={orgName}
projectName={key}
status={value}
githubData={
monthlyOrgProjectsData ? monthlyOrgProjectsData[key] : null
}
/>
))
);
})}
Object.entries(orgProjects)
.filter(([key, value]) => {
if (key.toLowerCase().includes(searchValue.toLowerCase()))
return [key, value];
})
.map(([key, value]) => {
return (
archives === value.archeive && (
<ProjectCard
key={key}
orgName={orgName}
projectName={key}
status={value}
githubData={
weekly
? weeklyOrgProjectsData && weeklyOrgProjectsData[key]
: monthlyOrgProjectsData && monthlyOrgProjectsData[key]
}
/>
)
);
})}
</div>
</>
);
Expand Down
8 changes: 6 additions & 2 deletions src/features/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { ProjectsGithubData } from 'app/api/githubData';
import { Contributors } from 'app/api/githubData';
import loader from '../../app/assets/gifs/loader.gif';
import UserContext from 'app/context/user/userContext';
import { useSelector } from 'react-redux';
import { SEARCH } from 'app/constants/sliceNames';

const Workspace = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -94,8 +96,10 @@ const Workspace = () => {
<>
<div className='home-header'>
<SearchBar />

<button className='' onClick={() => setArcheives(!archives)}>
<button
style={archives ? { background: 'var(--home-page-card-bg)' } : {}}
onClick={() => setArcheives(!archives)}
>
Archives
</button>
{spaceName &&
Expand Down
2 changes: 1 addition & 1 deletion src/features/workspace/slices/projectSearchSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const searchSlice = createSlice({
value: '',
},
reducers: {
searchAction: (state, action: PayloadAction<string>) => {
searchAction: (state: any, action: PayloadAction<string>) => {
state.value = action.payload;
},
},
Expand Down

0 comments on commit f8efe9d

Please sign in to comment.