Skip to content

Commit

Permalink
fix based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty committed Oct 21, 2024
1 parent b7db495 commit 9b209d0
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Props = {
selectedProjectId?: string;
onProjectUpdate?: (project: ProjectType, projectId: string) => void;
onProjectSelect?: (e?: MouseEvent<Element>, projectId?: string) => void;
onProjectRemove?: (projectId?: string) => void;
onProjectRemove?: (projectId: string) => void;
};

export default ({
Expand Down Expand Up @@ -160,23 +160,20 @@ export default ({
return projectPublished || storiesPublished;
}, [projectPublished, storiesPublished]);

const handleProjectRemove = useCallback(
async (projectId?: string) => {
if (!projectId) return;
const storyId = stories?.map((story) => story.id)[0] || "";
const handleProjectPublish = useCallback(
async (projectId: string) => {
if (projectPublished) {
await usePublishProject("unpublished", projectId);
}
if (storiesPublished) {
await usePublishStory("unpublished", storyId);
}

onProjectRemove?.(projectId);
handleProjectRemoveModal(false);
if (storiesPublished && stories?.length) {
const storyPromises = stories.map((story) =>
usePublishStory("unpublished", story.id)
);
await Promise.all(storyPromises);
}
},
[
handleProjectRemoveModal,
onProjectRemove,
projectPublished,
stories,
storiesPublished,
Expand All @@ -185,6 +182,16 @@ export default ({
]
);

const handleProjectRemove = useCallback(
async (projectId: string) => {
if (!projectId) return;
handleProjectPublish(projectId);
onProjectRemove?.(projectId);
handleProjectRemoveModal(false);
},
[handleProjectRemoveModal, handleProjectPublish, onProjectRemove]
);

return {
isEditing,
projectName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const ProjectRemoveModal: FC<Props> = ({
<Wrapper>
<WarningIcon icon="warning" />
<Typography size="body">
{t("Your project will be move to trash.")}
{t("Your project will be moved to trash.")}
</Typography>
<Typography size="body">
{t(
"This means the project will no longer be published. But you can still see and restore you project from recycle bin."
"This means the project will no longer be published. But you can still see and restore your project from the recycle bin."
)}
</Typography>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default (workspaceId?: string) => {
client.cache.gc();
},

[client.cache, usePublishProject, useUpdateProjectRemove]
[client, usePublishProject, useUpdateProjectRemove]
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ProjectDeleteModal: FC<Props> = ({
</Typography>
<Typography size="body">
{t(
"This action cannot be undone. This will permanently delete the project totally. You will lost all your project data"
"This action cannot be undone. This will permanently delete the project totally. You will lose all your project data"
)}
</Typography>
<Typography size="body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export default (workspaceId?: string) => {

const filteredDeletedProjects = useMemo(
() =>
(deletedProjects ?? []).map<DeletedProject | undefined>((project) => {
if (!project) return undefined;
return {
id: project.id,
name: project.name,
imageUrl: project.imageUrl,
isDeleted: project.isDeleted
};
}),
(deletedProjects ?? [])
.map((project) => {
if (!project) return undefined;
return {
id: project.id,
name: project.name,
imageUrl: project.imageUrl,
isDeleted: project.isDeleted
};
})
.filter(Boolean),
[deletedProjects]
);

Expand All @@ -49,17 +51,24 @@ export default (workspaceId?: string) => {
const handleProjectDelete = useCallback(
async (projectId: string) => {
if (!projectId) return;
setDisabled(!disabled);
await useDeleteProject({ projectId });
client.cache.evict({
id: client.cache.identify({
__typename: "Project",
id: projectId
})
});
client.cache.gc();
setDisabled(true);

try {
await useDeleteProject({ projectId });
client.cache.evict({
id: client.cache.identify({
__typename: "Project",
id: projectId
})
});
client.cache.gc();
} catch (error) {
console.error("Failed to delete project:", error);
} finally {
setDisabled(false);
}
},
[client.cache, disabled, useDeleteProject]
[client, useDeleteProject]
);
return {
filteredDeletedProjects,
Expand Down
52 changes: 32 additions & 20 deletions web/src/beta/features/ProjectSettings/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,43 @@ export default ({ projectId }: Props) => {
});
}, [scene?.stories]);

const handleProjectPublish = useCallback(
async (projectId: string) => {
if (projectPublished) {
await usePublishProject("unpublished", projectId);
}
if (storiesPublished && scene?.stories) {
await Promise.all(
scene.stories.map(async (story) => {
const publishmentStatus = toPublishmentStatus(
story.publishmentStatus
);
if (
publishmentStatus === "published" ||
publishmentStatus === "limited"
) {
await usePublishStory("unpublished", story.id);
}
})
);
}
},
[
projectPublished,
scene?.stories,
storiesPublished,
usePublishProject,
usePublishStory
]
);

const handleProjectRemove = useCallback(async () => {
const updatedProject = {
projectId,
deleted: true
};
setDisabled(!disabled);
const storyId = scene?.stories?.map((story) => story.id)[0] || "";
if (projectPublished) {
await usePublishProject("unpublished", projectId);
}
if (storiesPublished) {
await usePublishStory("unpublished", storyId);
}
handleProjectPublish(projectId);
const { status } = await useUpdateProjectRemove(updatedProject);
client.cache.evict({
id: client.cache.identify({
Expand All @@ -94,19 +118,7 @@ export default ({ projectId }: Props) => {
if (status === "success") {
navigate(`/dashboard/${workspaceId}/`);
}
}, [
client.cache,
disabled,
navigate,
projectId,
projectPublished,
scene?.stories,
storiesPublished,
usePublishProject,
usePublishStory,
useUpdateProjectRemove,
workspaceId
]);
}, [client.cache, disabled, handleProjectPublish, navigate, projectId, useUpdateProjectRemove, workspaceId]);

const handleUpdateProjectBasicAuth = useCallback(
async (settings: PublicBasicAuthSettingsType) => {
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/api/projectApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ export default () => {
setNotification({
type: "error",
text: input.deleted
? t("Failed to moved the project to trash.")
: t("Failed to restored the project!")
? t("Failed to move the project to trash.")
: t("Failed to restore the project!")
});

return { status: "error" };
Expand Down
10 changes: 5 additions & 5 deletions web/src/services/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ Text: ''
Description: ''
Write down your content: ''
Cover Image: ''
Your project will be move to trash.: ''
This means the project will no longer be published. But you can still see and restore you project from recycle bin.: ''
Your project will be moved to trash.: ''
This means the project will no longer be published. But you can still see and restore your project from the recycle bin.: ''
Starred: ''
No Project in recycle bin.: ''
Recover: ''
Delete: ''
Delete project: ''
Cancel: ''
I am sure I want to delete this project: ''
This action cannot be undone. This will permanently delete the project totally. You will lost all your project data: ''
This action cannot be undone. This will permanently delete the project totally. You will lose all your project data: ''
Please type your project name to continue.: ''
Switch Workspace: ''
Personal: ''
Expand Down Expand Up @@ -399,8 +399,8 @@ Successfully published your project with search engine indexing!: ''
Successfully unpublished your scene. Now nobody can access your scene.: ''
Failed to update project.: ''
Successfully updated project!: ''
Failed to moved the project to trash.: ''
Failed to restored the project!: ''
Failed to move the project to trash.: ''
Failed to restore the project!: ''
Successfully moved the project to trash!: ''
Successfully restored the project!: ''
Failed to archive project.: ''
Expand Down
10 changes: 5 additions & 5 deletions web/src/services/i18n/translations/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ Text: ''
Description: プロジェクト概要
Write down your content: ''
Cover Image: ''
Your project will be move to trash.: ''
This means the project will no longer be published. But you can still see and restore you project from recycle bin.: ''
Your project will be moved to trash.: ''
This means the project will no longer be published. But you can still see and restore your project from the recycle bin.: ''
Starred: ''
No Project in recycle bin.: ''
Recover: ''
Delete: ''
Delete project: ''
Cancel: ''
I am sure I want to delete this project: ''
This action cannot be undone. This will permanently delete the project totally. You will lost all your project data: ''
This action cannot be undone. This will permanently delete the project totally. You will lose all your project data: ''
Please type your project name to continue.: ''
Switch Workspace: ''
Personal: ''
Expand Down Expand Up @@ -399,8 +399,8 @@ Successfully published your project with search engine indexing!: 検索エン
Successfully unpublished your scene. Now nobody can access your scene.: シーンは非公開状態です。現在、誰も閲覧することはできません。
Failed to update project.: プロジェクトのアップデートに失敗しました。
Successfully updated project!: プロジェクトのアップデートに成功しました!
Failed to moved the project to trash.: ''
Failed to restored the project!: ''
Failed to move the project to trash.: ''
Failed to restore the project!: ''
Successfully moved the project to trash!: ''
Successfully restored the project!: ''
Failed to archive project.: プロジェクトの非編集状態に失敗しました。
Expand Down

0 comments on commit 9b209d0

Please sign in to comment.