feat: add update polling
This commit is contained in:
@ -323,6 +323,7 @@ const ProjectBoard: React.FC<ProjectBoardProps> = ({ projectID, onCardLabelClick
|
||||
const [updateTaskGroupName] = useUpdateTaskGroupNameMutation({});
|
||||
const { loading, data } = useFindProjectQuery({
|
||||
variables: { projectID },
|
||||
pollInterval: 5000,
|
||||
});
|
||||
const [deleteTaskGroupTasks] = useDeleteTaskGroupTasksMutation({
|
||||
update: (client, resp) =>
|
||||
|
@ -3,7 +3,7 @@ import Modal from 'shared/components/Modal';
|
||||
import TaskDetails from 'shared/components/TaskDetails';
|
||||
import { Popup, usePopup } from 'shared/components/PopupMenu';
|
||||
import MemberManager from 'shared/components/MemberManager';
|
||||
import { useRouteMatch, useHistory } from 'react-router';
|
||||
import { useRouteMatch, useHistory, Redirect } from 'react-router';
|
||||
import {
|
||||
useDeleteTaskChecklistMutation,
|
||||
useUpdateTaskChecklistNameMutation,
|
||||
@ -32,6 +32,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 hasNotFoundError from 'shared/utils/error';
|
||||
|
||||
const calculateChecklistBadge = (checklists: Array<TaskChecklist>) => {
|
||||
const total = checklists.reduce((prev: any, next: any) => {
|
||||
@ -269,8 +270,8 @@ const Details: React.FC<DetailsProps> = ({
|
||||
);
|
||||
},
|
||||
});
|
||||
const { loading, data, refetch } = useFindTaskQuery({ variables: { taskID } });
|
||||
const [setTaskComplete] = useSetTaskCompleteMutation();
|
||||
const { loading, data, refetch, error } = useFindTaskQuery({ variables: { taskID }, pollInterval: 5000 });
|
||||
const [setTaskComplete, { error: setTaskCompleteError }] = useSetTaskCompleteMutation();
|
||||
const [updateTaskDueDate] = useUpdateTaskDueDateMutation({
|
||||
onCompleted: () => {
|
||||
refetch();
|
||||
@ -289,9 +290,13 @@ const Details: React.FC<DetailsProps> = ({
|
||||
refreshCache();
|
||||
},
|
||||
});
|
||||
if (loading) {
|
||||
return null;
|
||||
if (hasNotFoundError(error, setTaskCompleteError)) {
|
||||
return <Redirect to={projectURL} />;
|
||||
}
|
||||
if (setTaskCompleteError && setTaskCompleteError)
|
||||
if (loading) {
|
||||
return null;
|
||||
}
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
@ -346,7 +351,11 @@ const Details: React.FC<DetailsProps> = ({
|
||||
onTaskNameChange={onTaskNameChange}
|
||||
onTaskDescriptionChange={onTaskDescriptionChange}
|
||||
onToggleTaskComplete={task => {
|
||||
setTaskComplete({ variables: { taskID: task.id, complete: !task.complete } });
|
||||
setTaskComplete({ variables: { taskID: task.id, complete: !task.complete } }).catch(r => {
|
||||
if (hasNotFoundError(r)) {
|
||||
history.push(projectURL);
|
||||
}
|
||||
});
|
||||
}}
|
||||
onDeleteTask={onDeleteTask}
|
||||
onChangeItemName={(itemID, itemName) => {
|
||||
|
@ -234,7 +234,7 @@ type ShowNewProject = {
|
||||
|
||||
const Projects = () => {
|
||||
const { showPopup, hidePopup } = usePopup();
|
||||
const { loading, data } = useGetProjectsQuery({ fetchPolicy: 'network-only' });
|
||||
const { loading, data } = useGetProjectsQuery({ fetchPolicy: 'network-only', pollInterval: 5000 });
|
||||
useEffect(() => {
|
||||
document.title = 'Taskcafé';
|
||||
}, []);
|
||||
|
@ -154,7 +154,7 @@ type TeamProjectsProps = {
|
||||
};
|
||||
|
||||
const TeamProjects: React.FC<TeamProjectsProps> = ({ teamID }) => {
|
||||
const { loading, data } = useGetTeamQuery({ variables: { teamID } });
|
||||
const { loading, data } = useGetTeamQuery({ variables: { teamID }, pollInterval: 5000 });
|
||||
if (loading) {
|
||||
return <span>loading</span>;
|
||||
}
|
||||
|
@ -209,7 +209,8 @@ export enum ObjectType {
|
||||
Org = 'ORG',
|
||||
Team = 'TEAM',
|
||||
Project = 'PROJECT',
|
||||
Task = 'TASK'
|
||||
Task = 'TASK',
|
||||
TaskGroup = 'TASK_GROUP'
|
||||
}
|
||||
|
||||
export type Query = {
|
||||
@ -722,7 +723,7 @@ export type UpdateProjectMemberRolePayload = {
|
||||
};
|
||||
|
||||
export type NewTask = {
|
||||
taskGroupID: Scalars['String'];
|
||||
taskGroupID: Scalars['UUID'];
|
||||
name: Scalars['String'];
|
||||
position: Scalars['Float'];
|
||||
};
|
||||
@ -1472,7 +1473,7 @@ export type UpdateProjectMemberRoleMutation = (
|
||||
);
|
||||
|
||||
export type CreateTaskMutationVariables = {
|
||||
taskGroupID: Scalars['String'];
|
||||
taskGroupID: Scalars['UUID'];
|
||||
name: Scalars['String'];
|
||||
position: Scalars['Float'];
|
||||
};
|
||||
@ -3044,7 +3045,7 @@ export type UpdateProjectMemberRoleMutationHookResult = ReturnType<typeof useUpd
|
||||
export type UpdateProjectMemberRoleMutationResult = ApolloReactCommon.MutationResult<UpdateProjectMemberRoleMutation>;
|
||||
export type UpdateProjectMemberRoleMutationOptions = ApolloReactCommon.BaseMutationOptions<UpdateProjectMemberRoleMutation, UpdateProjectMemberRoleMutationVariables>;
|
||||
export const CreateTaskDocument = gql`
|
||||
mutation createTask($taskGroupID: String!, $name: String!, $position: Float!) {
|
||||
mutation createTask($taskGroupID: UUID!, $name: String!, $position: Float!) {
|
||||
createTask(input: {taskGroupID: $taskGroupID, name: $name, position: $position}) {
|
||||
...TaskFields
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import gql from 'graphql-tag';
|
||||
import TASK_FRAGMENT from '../fragments/task';
|
||||
|
||||
const CREATE_TASK_MUTATION = gql`
|
||||
mutation createTask($taskGroupID: String!, $name: String!, $position: Float!) {
|
||||
mutation createTask($taskGroupID: UUID!, $name: String!, $position: Float!) {
|
||||
createTask(input: { taskGroupID: $taskGroupID, name: $name, position: $position }) {
|
||||
...TaskFields
|
||||
}
|
||||
|
13
frontend/src/shared/utils/error.ts
Normal file
13
frontend/src/shared/utils/error.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { ApolloError } from '@apollo/client';
|
||||
|
||||
export default function hasNotFoundError(...errors: Array<ApolloError | undefined>) {
|
||||
for (const error of errors) {
|
||||
if (error && error.graphQLErrors.length !== 0) {
|
||||
const notFound = error.graphQLErrors.find(e => e.extensions && e.extensions.code === '404');
|
||||
if (notFound) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user