Skip to content

Commit b6681a4

Browse files
committed
feat: search feature for projects
Signed-off-by: Karthik Ayangar <[email protected]>
1 parent 00f3c50 commit b6681a4

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

frontend/src/app/components/search/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from 'react';
1+
import { useState } from 'react';
22
import { useDispatch } from 'react-redux';
33
import { searchAction } from 'features/workspace/slices/projectSearchSlice';
44
import search_icon from 'app/assets/images/search_icon.svg';
55
import './index.scss';
66

77
const SearchBar = () => {
88
const dispatch = useDispatch();
9-
let search = '';
9+
const [search,setSearch] = useState('')
1010
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
11-
search = e.target.value;
11+
setSearch(e.target.value);
1212
};
1313
const handleSearch = (e: React.FormEvent<HTMLFormElement>) => {
1414
e.preventDefault();

frontend/src/features/AddProject/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChangeEvent, useEffect, useState } from 'react';
22
import './index.scss';
3-
// import tick from '../../app/assets/images/tick.png';
3+
import tick from '../../app/assets/images/tick.png';
44
import { useNavigate, useParams } from 'react-router-dom';
55
import toast from 'react-hot-toast';
66
import { addProject } from 'app/api/project';
@@ -131,7 +131,7 @@ const AddProject = () => {
131131
'Description length should not be greater than 200'}
132132
</form>
133133
<button className='add-project-btn' onClick={SubmitHandler}>
134-
{/* <img src={tick} alt='' /> */}
134+
<img src={tick} alt='' />
135135
Done
136136
</button>
137137
</div>

frontend/src/features/EditProject/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { ChangeEvent, useEffect, useState } from 'react';
22
import './index.scss';
3-
import tick from '../../app/assets/images/tick.png';
3+
// import tick from '../../app/assets/images/tick.png';
44
import { useNavigate, useParams } from 'react-router-dom';
55
import toast from 'react-hot-toast';
66
import {
77
getProject,
88
updateProject,
99
} from 'app/api/project';
10-
import UserContext from 'app/context/user/userContext';
1110
import { Projects, getOrgProjects } from 'app/api/organization';
1211

1312

@@ -144,7 +143,8 @@ const EditProject = () => {
144143
'Description length should not be greater than 200'}
145144
</form>
146145
<button className='add-project-btn' onClick={SubmitHandler}>
147-
<img src={tick} alt='' /> Done
146+
{/* <img src={tick} alt='' /> */}
147+
Done
148148
</button>
149149
</div>
150150
</div>

frontend/src/features/workspace-view/index.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const WorkspaceView = () => {
1717
const [userOrgs, setUserOrgs] = useState<UserOrgs>();
1818
const token = localStorage.getItem('token');
1919
const navigate = useNavigate();
20-
2120
const searchValue = useSelector((state: any) => state.searchKeyword.value);
22-
2321
const fetchData = async () => {
2422
if (token && userContext?.username) {
2523
setIsLoad(true);
@@ -31,12 +29,7 @@ const WorkspaceView = () => {
3129
userContext?.setUserOrgs(userOrgs.data);
3230
setUserOrgs(userOrgs.data);
3331
setIsLoad(false);
34-
// console.log(userContext)
35-
// console.log(userOrgs)
36-
37-
3832
} catch (e) {}
39-
4033
setIsLoad(false);
4134
}
4235
};

frontend/src/features/workspace/components/projectCardContainer/index.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ const ProjectCardCont: React.FC<Props> = ({
2222
weeklyOrgProjectsData,
2323
archives,
2424
}) => {
25-
const searchValue = useSelector((state: any) => state.searchKeyword.value);
26-
27-
useEffect(() => {}, [weekly, searchValue]);
25+
useEffect(() => {
26+
return;
27+
}, [weekly]);
2828

2929
return (
30-
<>
3130
<div className='projectcard-cont'>
3231
{orgProjects &&
33-
Object.entries(orgProjects)
34-
.filter(([key, value]) => {
35-
if (key.toLowerCase().includes(searchValue.toLowerCase()))
36-
return [key, value];
37-
})
38-
.map(([key, value]) => {
32+
Object.entries(orgProjects).map(([key, value]) => {
3933
return (
4034
archives === value.archeive && (
4135
<ProjectCard
@@ -53,7 +47,6 @@ const ProjectCardCont: React.FC<Props> = ({
5347
);
5448
})}
5549
</div>
56-
</>
5750
);
5851
};
5952

frontend/src/features/workspace/index.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import { Contributors } from 'app/api/githubData';
1616
import loader from '../../app/assets/gifs/loader.gif';
1717
import UserContext from 'app/context/user/userContext';
1818
import { getUserOrgs } from 'app/api/user';
19+
import { useSelector } from 'react-redux';
1920

2021

2122
const Workspace = () => {
23+
const searchValue = useSelector((state: any) => state.searchKeyword.value);
2224
const navigate = useNavigate();
2325
const token = localStorage.getItem('token');
2426
const userContext = useContext(UserContext);
25-
// userContext?.setUsername('test');
2627
const [weekly, setWeekly] = useState<boolean>(true);
2728
const [orgProjects, setOrgProjects] = useState<Projects | null>(null);
2829
const [archives, setArcheives] = useState<boolean>(false);
@@ -41,7 +42,8 @@ const Workspace = () => {
4142
if (token && spaceName) {
4243
try {
4344
const orgProjects = await getOrgProjects(token, spaceName);
44-
setOrgProjects(orgProjects.data.projects);
45+
const temp = Object.entries(orgProjects.data.projects).filter(([key]) => key.toLowerCase().includes(searchValue.toLowerCase()));
46+
setOrgProjects(Object.fromEntries(temp))
4547
} catch (e) {
4648
navigate('/');
4749
}
@@ -98,7 +100,7 @@ const Workspace = () => {
98100
fetchOrgProjects();
99101
fetchWeeklyData();
100102
fetchMonthlyData();
101-
}, [weekly,spaceName]);
103+
}, [weekly,spaceName,searchValue]);
102104

103105
return (
104106
<>

0 commit comments

Comments
 (0)