Api2.5/ rename scene (#500)

- rename scene endpoint done
- slight refactor, cleanup
- and update eslint config for better eslint debugging

this goes after https://github.com/storytold/GottaGoFast/pull/499

Co-authored-by: wil <wil@storyteller.ai>
This commit is contained in:
wilandwil authored and GitHub committed 2024-06-18 23:59:51 -04:00
1 parent d19fa3cb82
commit a40173bc74
5 files changed
+24 -40

No files matched your search

+1
View File
@@ -59,6 +59,7 @@ module.exports = {
"jsx-a11y/click-events-have-key-events": SEVERITY.OFF,
"jsx-a11y/no-static-element-interactions": SEVERITY.OFF,
"jsx-a11y/media-has-caption": SEVERITY.OFF,
"jsx-a11y/no-autofocus": SEVERITY.OFF,
},
},
+1 -1
View File
@@ -222,7 +222,7 @@ export class MediaFilesApi extends ApiManager {
mediaToken: string;
name: string;
}): Promise<ApiResponse<undefined>> {
const endpoint = `${this.ApiTargets.BaseApi}/v1/media_file/rename/${mediaToken}`;
const endpoint = `${this.ApiTargets.BaseApi}/v1/media_files/rename/${mediaToken}`;
const body = { name };
return await this.post<
+2 -2
View File
@@ -37,5 +37,5 @@ export const uploadNewScene = `${apiHost}/v1/media_files/upload/new_scene`;
export const uploadThumbnail = `${apiHost}/v1/media_files/cover_image/`;
export const updateExistingScene = (sceneToken: string) =>
`${apiHost}/v1/media_files/upload/saved_scene/${sceneToken}`;
export const renameScene = (sceneToken: string) =>
`${apiHost}/v1/media_files/rename/${sceneToken}`;
// export const renameScene = (sceneToken: string) =>
// `${apiHost}/v1/media_files/rename/${sceneToken}`;
@@ -10,7 +10,7 @@ import {
errorDialogTitle,
} from "~/pages/PageEnigma/signals";
import { Input } from "~/components";
import { renameScene } from "./utilities";
import { MediaFilesApi } from "~/Classes/ApiManager/MediaFilesApi";
interface Props {
pageName: string;
@@ -34,9 +34,9 @@ export const SceneTitleInput = ({ pageName }: Props) => {
setState((curr) => ({ ...curr, isSaving: val }));
};
const handleShowErrorDialog = () => {
const handleShowErrorDialog = (errorMessage: string) => {
errorDialogTitle.value = "Error";
errorDialogMessage.value = "Scene name can not be empty.";
errorDialogMessage.value = errorMessage;
showErrorDialog.value = true;
};
@@ -50,11 +50,26 @@ export const SceneTitleInput = ({ pageName }: Props) => {
}
};
const renameScene = async (sceneTitle: string, sceneToken: string) => {
const mediaFileApi = new MediaFilesApi();
const response = await mediaFileApi.RenameMediaFileByToken({
mediaToken: sceneToken,
name: sceneTitle,
});
if (!response.success) {
handleShowErrorDialog(
response.errorMessage || "Unknown Error in Renaming Scene",
);
resetPreviousTitle();
}
setIsSaving(false);
};
const validateSceneTitle = (e: React.FocusEvent<HTMLInputElement>) => {
setShowInput(false);
if (scene.value.title === "") {
setIsValid(false);
handleShowErrorDialog();
handleShowErrorDialog("Scene name can not be empty.");
resetPreviousTitle();
e.currentTarget.focus();
} else if (scene.value.token) {
@@ -62,11 +77,7 @@ export const SceneTitleInput = ({ pageName }: Props) => {
renameScene(
scene.value.title!, //guarunteed by input
scene.value.token,
).then((res) => {
// console.log(res);
//TODO: HANDLE ERROR
setIsSaving(false);
});
);
}
};
@@ -1,28 +0,0 @@
import { renameScene as renameSceneEndpoint } from "~/api";
export const renameScene = (sceneTitle: string, sceneToken: string) => {
const endpoint = renameSceneEndpoint(sceneToken);
return fetch(endpoint, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
name: sceneTitle,
}),
})
.then((res) => res.json())
.then((res) => {
if (res && res.success) {
// console.log(res);
return res;
}
return { success: false };
})
.catch(() => {
return { success: false };
});
};