Skip to content

Commit

Permalink
update the imprort project query
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty committed Oct 25, 2024
1 parent 61f707c commit a438718
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ export default ({
const handleExportProject = useCallback(async () => {
if (!project.id) return;

const result = await useExportProject(project.id);

if (result.status === "success") {
console.log("export success");
} else {
console.error("Failed to export project:", result.status);
}
await useExportProject(project.id);
}, [useExportProject, project.id]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ export default (workspaceId?: string) => {
async (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const result = await useImportProject(file);
const result = await useImportProject({
teamId: workspaceId || "",
file
});
if (result.status === "success") {
await refetch();
}
}
},
[useImportProject, refetch]
[useImportProject, workspaceId, refetch]
);

// project remove
Expand Down
9 changes: 5 additions & 4 deletions web/src/services/api/projectApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
DeleteProjectInput,
ArchiveProjectMutationVariables,
UpdateProjectBasicAuthMutationVariables,
UpdateProjectAliasMutationVariables
UpdateProjectAliasMutationVariables,
ImportProjectInput
} from "@reearth/services/gql/__gen__/graphql";
import {
ARCHIVE_PROJECT,
Expand Down Expand Up @@ -527,12 +528,12 @@ export default () => {
const [importProjectMutation] = useMutation(IMPORT_PROJECT);

const useImportProject = useCallback(
async (file: File) => {
if (!file) return { status: "error" };
async (input: ImportProjectInput) => {
if (!input) return { status: "error" };

try {
const { data, errors } = await importProjectMutation({
variables: { file }
variables: { ...input }
});

if (errors || !data?.importProject) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/gql/__gen__/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const documents = {
"\n mutation DeleteProject($projectId: ID!) {\n deleteProject(input: { projectId: $projectId }) {\n projectId\n }\n }\n": types.DeleteProjectDocument,
"\n query GetStarredProjects($teamId: ID!) {\n starredProjects(teamId: $teamId) {\n\t\t\t\tnodes {\n\t\t\t\t\tid\n\t\t\t\t\tname\n\t\t\t\t\tstarred\n scene {\n id\n }\n\t\t\t\t}\n\t\t\t\ttotalCount\n\t\t\t}\n }\n": types.GetStarredProjectsDocument,
"\n mutation ExportProject($projectId: ID!) {\n exportProject(input: { projectId: $projectId }) {\n projectDataPath\n }\n }\n": types.ExportProjectDocument,
"\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n": types.ImportProjectDocument,
"\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n": types.ImportProjectDocument,
"\n query GetDeletedProjects($teamId: ID!) {\n deletedProjects(teamId: $teamId) {\n\t\t\tnodes {\n\t\t\t\tid\n\t\t\t\tname\n\t\t\t\tisDeleted\n imageUrl\n\t\t\t\t}\n\t\t\ttotalCount\n\t\t}\n }\n": types.GetDeletedProjectsDocument,
"\n mutation UpdatePropertyValue(\n $propertyId: ID!\n $schemaGroupId: ID\n $itemId: ID\n $fieldId: ID!\n $value: Any\n $type: ValueType!\n $lang: Lang\n ) {\n updatePropertyValue(\n input: {\n propertyId: $propertyId\n schemaGroupId: $schemaGroupId\n itemId: $itemId\n fieldId: $fieldId\n value: $value\n type: $type\n }\n ) {\n property {\n id\n ...PropertyFragment\n layer {\n id\n ...Layer1Fragment\n }\n }\n }\n }\n": types.UpdatePropertyValueDocument,
"\n mutation AddPropertyItem(\n $propertyId: ID!\n $schemaGroupId: ID!\n $lang: Lang\n ) {\n addPropertyItem(\n input: {\n propertyId: $propertyId\n schemaGroupId: $schemaGroupId\n }\n ) {\n property {\n id\n ...PropertyFragment\n layer {\n id\n ...Layer1Fragment\n }\n }\n }\n }\n": types.AddPropertyItemDocument,
Expand Down Expand Up @@ -306,7 +306,7 @@ export function gql(source: "\n mutation ExportProject($projectId: ID!) {\n
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n"): (typeof documents)["\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n"];
export function gql(source: "\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n"): (typeof documents)["\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
4 changes: 3 additions & 1 deletion web/src/services/gql/__gen__/graphql.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/src/services/gql/queries/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ export const EXPORT_PROJECT = gql(`
`);

export const IMPORT_PROJECT = gql(`
mutation ImportProject($file: Upload!) {
importProject(input: { file: $file }) {
mutation ImportProject($teamId: ID!, $file: Upload!) {
importProject(input: { teamId: $teamId, file: $file }) {
projectData
}
}
Expand Down

0 comments on commit a438718

Please sign in to comment.