Skip to content

Commit

Permalink
fix(web): update projects cache after delete (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Oct 3, 2024
1 parent e647233 commit 6f6112a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions web/src/services/api/projectApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useLazyQuery, useMutation, useQuery } from "@apollo/client";
import {
Reference,
StoreObject,
useLazyQuery,
useMutation,
useQuery
} from "@apollo/client";
import { type PublishStatus } from "@reearth/beta/features/Editor/Publish/PublishToolsPanel/PublishModal/hooks";
import { GetProjectsQueryVariables } from "@reearth/services/gql";
import {
Expand Down Expand Up @@ -302,8 +308,26 @@ export default () => {
);

const [deleteProjectMutation] = useMutation(DELETE_PROJECT, {
refetchQueries: ["GetProject"]
refetchQueries: ["GetProject"],
update(cache, { data }) {
if (data?.deleteProject?.projectId) {
cache.modify({
fields: {
projects(existingData = {}, { readField }) {
return {
...existingData,
edges: (existingData.edges || []).filter(
(e: { node: Reference | StoreObject | undefined }) =>
readField("id", e.node) !== data?.deleteProject?.projectId
)
};
}
}
});
}
}
});

const useDeleteProject = useCallback(
async (input: DeleteProjectInput) => {
if (!input.projectId) return { status: "error" };
Expand Down

0 comments on commit 6f6112a

Please sign in to comment.