Skip to content

Commit b0ac839

Browse files
added polling for projects list.
1 parent 063d789 commit b0ac839

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/redux/actions/projects/getMyProjectsAction.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import { projectActionTypes } from '../../actionTypes';
22
import getMyProjectsApi from '../../../api/projects/getMyProjectsApi';
33

44
export const getMyProjectsAction = ({
5+
selectDefault,
6+
selectedProject,
57
onSuccess,
68
onFailure,
79
}: {
10+
selectedProject?: string;
11+
selectDefault?: boolean;
812
onSuccess?: () => void;
913
onFailure?: () => void;
1014
}): TRequestAction => ({
@@ -14,6 +18,7 @@ export const getMyProjectsAction = ({
1418
isAuthenticated: true,
1519
failureActionType: projectActionTypes.getMyProjects.failure,
1620
successActionType: projectActionTypes.getMyProjects.success,
21+
params: { selectDefault, selectedProject },
1722
onSuccess,
1823
onFailure,
1924
},

src/redux/reducers/projectsReducer.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ProjectsPayload = Projects[];
1414
type ProjectPayload = Projects;
1515

1616
export type Action = {
17+
requestParams: any;
1718
type: string;
1819
payload: any;
1920
};
@@ -49,12 +50,19 @@ const projectsReducer = (
4950
const myProjectIds: TId[] = projects.map(
5051
(project: Projects) => project.id,
5152
);
52-
const defaultSelectedProject = projects[0].name;
53+
if (action.requestParams.selectDefault === undefined) {
54+
const defaultSelectedProject = projects[0].name;
5355

54-
return {
55-
...newState(state, projects, defaultSelectedProject),
56-
myProjectIds,
57-
};
56+
return {
57+
...newState(state, projects, defaultSelectedProject),
58+
myProjectIds,
59+
};
60+
} else {
61+
return {
62+
...newState(state, projects, action.requestParams.selectedProject),
63+
myProjectIds,
64+
};
65+
}
5866
}
5967
case projectActionTypes.selectProject.success: {
6068
const { seletecdProject, allProjects } = action.payload as any;

src/ui/layouts/common/layouts/AuthenticatedLayout/AuthenticatedHeader.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import {
33
FlexBox,
44
Box,
@@ -34,7 +34,19 @@ export const AuthenticatedHeader: React.FC<{
3434
const [popupOpen, setPopupOpen] = useState<boolean>(false);
3535
const dispatch = useDispatch();
3636
const { push } = usePushRoute();
37+
useEffect(() => {
38+
const intervalId = setInterval(() => {
39+
//assign interval to a variable to clear it.
3740

41+
dispatch(
42+
projectsActions.getMy({ selectDefault: false, selectedProject }),
43+
);
44+
}, 5000);
45+
46+
return () => clearInterval(intervalId);
47+
48+
//This is important
49+
});
3850
if (!user) return null;
3951

4052
const userFullName = user.fullName || user.name || DEFAULT_FULL_NAME;

0 commit comments

Comments
 (0)