Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OV-445: validate scenes #449

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,22 @@ class ScriptProcessor {
voice: string;
scene: Scene;
}): void {
if (text && this.currentAvatar) {
if (!text || !this.currentAvatar) {
return;
}

const lastScene = this.result.at(-1);

if (
lastScene &&
lastScene.avatar.voice === voice &&
lastScene.avatar.name === this.currentAvatar.name &&
lastScene.avatar.style === this.currentAvatar.style &&
JSON.stringify(lastScene.background) ===
JSON.stringify(scene.background)
) {
lastScene.avatar.text += ' ' + text;
} else {
this.result.push({
...scene,
id: uuidv4(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { type Scene } from '../types/types.js';

function areAllScenesWithAvatar(scenes: Scene[]): boolean {
return scenes.every((scene) => scene.avatar !== undefined);
}

export { areAllScenesWithAvatar };
1 change: 1 addition & 0 deletions frontend/src/bundles/studio/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { addScene } from './add-scene.js';
export { addScript } from './add-script.js';
export { areAllScenesWithAvatar } from './are-all-scenes-with-scenes.helper.js';
export { createDefaultAvatarFromRequest } from './create-default-avatar.js';
export { getDestinationPointerValue } from './get-destination-pointer-value.js';
export { getElementEnd } from './get-element-end.js';
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/bundles/studio/pages/studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ import {
VIDEO_SUBMIT_NOTIFICATION_ID,
} from '../constants/constants.js';
import { NotificationMessage, NotificationTitle } from '../enums/enums.js';
import { getVoicesConfigs, scenesExceedScripts } from '../helpers/helpers.js';
import {
areAllScenesWithAvatar,
getVoicesConfigs,
scenesExceedScripts,
} from '../helpers/helpers.js';
import { selectVideoDataById } from '../store/selectors.js';
import { actions as studioActions } from '../store/studio.js';

Expand Down Expand Up @@ -93,15 +97,14 @@ const Studio: React.FC = () => {

const handleConfirmSubmit = useCallback(() => {
// TODO: REPLACE LOGIC WITH MULTIPLE SCENES
const scene = scenes[0];

const script = scripts[0];
if (!scene?.avatar || !script) {
notificationService.warn({
if (!areAllScenesWithAvatar(scenes) || !script) {
return notificationService.warn({
id: SCRIPT_AND_AVATAR_ARE_REQUIRED,
message: NotificationMessage.SCRIPT_AND_AVATAR_ARE_REQUIRED,
title: NotificationTitle.SCRIPT_AND_AVATAR_ARE_REQUIRED,
});
return;
}

void dispatch(studioActions.generateAllScriptsSpeech())
Expand Down Expand Up @@ -158,7 +161,6 @@ const Studio: React.FC = () => {
composition: {
scenes,
scripts: getVoicesConfigs(scripts),
// TODO : CHANGE TO ENUM
videoOrientation: videoSize,
},
name: videoName,
Expand Down
Loading