diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..7d672fa --- /dev/null +++ b/frontend/.env @@ -0,0 +1 @@ +REACT_APP_ENABLE_POLLING=true diff --git a/frontend/.env.development b/frontend/.env.development new file mode 100644 index 0000000..5e581bb --- /dev/null +++ b/frontend/.env.development @@ -0,0 +1 @@ +REACT_APP_ENABLE_POLLING=false diff --git a/frontend/src/Projects/Project/Details/index.tsx b/frontend/src/Projects/Project/Details/index.tsx index 7142190..d4d7fea 100644 --- a/frontend/src/Projects/Project/Details/index.tsx +++ b/frontend/src/Projects/Project/Details/index.tsx @@ -36,6 +36,7 @@ import Input from 'shared/components/Input'; import { useForm } from 'react-hook-form'; import updateApolloCache from 'shared/utils/cache'; import NOOP from 'shared/utils/noop'; +import polling from 'shared/utils/polling'; export const ActionsList = styled.ul` margin: 0; @@ -384,7 +385,7 @@ const Details: React.FC = ({ }); const { loading, data, refetch } = useFindTaskQuery({ variables: { taskID }, - pollInterval: 3000, + pollInterval: polling.TASK_DETAILS, fetchPolicy: 'cache-and-network', }); const [setTaskComplete] = useSetTaskCompleteMutation(); diff --git a/frontend/src/Projects/Project/index.tsx b/frontend/src/Projects/Project/index.tsx index 69c3067..9b2f06b 100644 --- a/frontend/src/Projects/Project/index.tsx +++ b/frontend/src/Projects/Project/index.tsx @@ -35,6 +35,7 @@ import Board, { BoardLoading } from './Board'; import Details from './Details'; import LabelManagerEditor from './LabelManagerEditor'; import UserManagementPopup from './UserManagementPopup'; +import polling from 'shared/utils/polling'; type TaskRouteProps = { taskID: string; @@ -60,7 +61,7 @@ const Project = () => { const [updateTaskName] = useUpdateTaskNameMutation(); const { data, error } = useFindProjectQuery({ variables: { projectID }, - pollInterval: 3000, + pollInterval: polling.PROJECT, }); const [toggleTaskLabel] = useToggleTaskLabelMutation({ onCompleted: newTaskLabel => { diff --git a/frontend/src/Projects/index.tsx b/frontend/src/Projects/index.tsx index 6eb9387..a3b976c 100644 --- a/frontend/src/Projects/index.tsx +++ b/frontend/src/Projects/index.tsx @@ -22,6 +22,7 @@ import produce from 'immer'; import NOOP from 'shared/utils/noop'; import theme from 'App/ThemeStyles'; import { mixin } from '../shared/utils/styles'; +import polling from 'shared/utils/polling'; type CreateTeamData = { teamName: string }; @@ -203,7 +204,7 @@ type ShowNewProject = { const Projects = () => { const { showPopup, hidePopup } = usePopup(); - const { loading, data } = useGetProjectsQuery({ pollInterval: 3000, fetchPolicy: 'cache-and-network' }); + const { loading, data } = useGetProjectsQuery({ pollInterval: polling.PROJECTS, fetchPolicy: 'cache-and-network' }); useEffect(() => { document.title = 'Taskcafé'; }, []); diff --git a/frontend/src/Teams/Members/index.tsx b/frontend/src/Teams/Members/index.tsx index f8eeb4a..771eb05 100644 --- a/frontend/src/Teams/Members/index.tsx +++ b/frontend/src/Teams/Members/index.tsx @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import Input from 'shared/components/Input'; import updateApolloCache from 'shared/utils/cache'; import produce from 'immer'; +import polling from 'shared/utils/polling'; import Button from 'shared/components/Button'; import { useCurrentUser } from 'App/context'; import Select from 'shared/components/Select'; @@ -422,7 +423,7 @@ const Members: React.FC = ({ teamID }) => { const { loading, data } = useGetTeamQuery({ variables: { teamID }, fetchPolicy: 'cache-and-network', - pollInterval: 3000, + pollInterval: polling.MEMBERS, }); const { user } = useCurrentUser(); const warning = diff --git a/frontend/src/Teams/Projects/index.tsx b/frontend/src/Teams/Projects/index.tsx index 48491b5..9a68b94 100644 --- a/frontend/src/Teams/Projects/index.tsx +++ b/frontend/src/Teams/Projects/index.tsx @@ -9,6 +9,7 @@ import { import { Link } from 'react-router-dom'; import Input from 'shared/components/Input'; import theme from 'App/ThemeStyles'; +import polling from 'shared/utils/polling'; const FilterSearch = styled(Input)` margin: 0; @@ -158,7 +159,7 @@ const TeamProjects: React.FC = ({ teamID }) => { const { loading, data } = useGetTeamQuery({ variables: { teamID }, fetchPolicy: 'cache-and-network', - pollInterval: 3000, + pollInterval: polling.TEAM_PROJECTS, }); if (data) { return ( diff --git a/frontend/src/shared/utils/polling.ts b/frontend/src/shared/utils/polling.ts new file mode 100644 index 0000000..897ceae --- /dev/null +++ b/frontend/src/shared/utils/polling.ts @@ -0,0 +1,13 @@ +function resolve(interval: number) { + if (process.env.REACT_APP_ENABLE_POLLING === 'true') return interval; + return 0; +} +const polling = { + PROJECTS: resolve(3000), + PROJECT: resolve(3000), + MEMBERS: resolve(3000), + TEAM_PROJECTS: resolve(3000), + TASK_DETAILS: resolve(3000), +}; + +export default polling;