Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesUoM committed Dec 10, 2024
1 parent ef7c14f commit 769eea6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
"success-tooltip-aria": "Saved successfully",
"saveArea-tooltip": "Save Area",
"confirm-success": "Okay",
"cancel-save": "Don't save"
"cancel-save": "Don't save",
"invalid-headline-text": "Invalid Edits",
"invalid-text": "The segments do not create a valid video. Either change or discard your edits if you wish to proceed. If you wanted to delete this video use the Opencast Admin UI. Contact {{ contact }} for further help."
},

"discard": {
Expand Down
12 changes: 9 additions & 3 deletions src/main/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
selectSegments,
selectTracks,
setHasChanges as videoSetHasChanges,
selectValidSegments,
validateSegments,
} from "../redux/videoSlice";
import { postVideoInformation, selectStatus, selectError } from "../redux/workflowPostSlice";

Expand Down Expand Up @@ -53,6 +55,10 @@ const Save: React.FC = () => {
const hasChanges = useAppSelector(selectHasChanges);
const subtitleHasChanges = useAppSelector(selectSubtitleHasChanges);

const dispatch = useAppDispatch();
dispatch(validateSegments());
const validSegments = useAppSelector(selectValidSegments);

const saveStyle = css({
height: "100%",
display: finishState !== "Save changes" ? "none" : "flex",
Expand All @@ -77,11 +83,11 @@ const Save: React.FC = () => {
return (
<>
<span css={{ maxWidth: "500px" }}>
{t("save.info-text")}
{validSegments ? t("save.info-text") : t("save.invalid-text", { contact: settings.help.contact })}
</span>
<div css={backOrContinueStyle}>
<PageButton pageNumber={0} label={t("various.goBack-button")} Icon={LuChevronLeft} />
<SaveButton />
{validSegments && <SaveButton />}
</div>
</>
);
Expand All @@ -90,7 +96,7 @@ const Save: React.FC = () => {

return (
<div css={saveStyle}>
<h1>{t("save.headline-text")}</h1>
<h1>{validSegments ? t("save.headline-text") : t("save.invalid-headline-text")}</h1>
{render()}
<div css={errorBoxStyle(postWorkflowStatus === "failed", theme)} role="alert">
<span>{t("various.error-text", { contact: settings.help.contact })}</span><br />
Expand Down
20 changes: 17 additions & 3 deletions src/main/WorkflowSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { selectFinishState, selectPageNumber } from "../redux/finishSlice";
import { PageButton } from "./Finish";
import { LuChevronLeft } from "react-icons/lu";
import { SaveAndProcessButton } from "./WorkflowConfiguration";
import { selectValidSegments, validateSegments } from "../redux/videoSlice";
import { selectStatus, selectError } from "../redux/workflowPostAndProcessSlice";
import { selectStatus as saveSelectStatus, selectError as saveSelectError } from "../redux/workflowPostSlice";
import { httpRequestState, Workflow } from "../types";
import { SaveButton } from "./Save";
import { EmotionJSX } from "@emotion/react/types/jsx-namespace";

import { useTranslation } from "react-i18next";
import { Trans } from "react-i18next";
import { useTranslation, Trans } from "react-i18next";
import { FormControlLabel, Radio, RadioGroup } from "@mui/material";
import { useTheme } from "../themes";
import { settings } from "../config";
Expand Down Expand Up @@ -47,6 +47,9 @@ const WorkflowSelection: React.FC = () => {
const saveStatus = useAppSelector(saveSelectStatus);
const saveError = useAppSelector(saveSelectError);

dispatch(validateSegments());
const validSegments = useAppSelector(selectValidSegments);

const workflowSelectionStyle = css({
padding: "20px",
display: (finishState === "Start processing" && pageNumber === 1) ? "flex" : "none",
Expand Down Expand Up @@ -117,7 +120,18 @@ const WorkflowSelection: React.FC = () => {

// Fills the layout template with values based on how many workflows are available
const renderSelection = () => {
if (workflows.length <= 0) {
if (!validSegments) {
return (
render(
t("save.invalid-headline-text"),
<span css={{ maxWidth: "500px" }}>{t("save.invalid-text", { contact: settings.help.contact })}</span>,
false,
<div/>,
saveStatus,
saveError
)
);
} else if (workflows.length <= 0) {
return (
render(
t("workflowSelection.saveAndProcess-text"),
Expand Down
14 changes: 14 additions & 0 deletions src/redux/videoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface video {
tracks: Track[],
subtitlesFromOpencast: SubtitlesFromOpencast[],
activeSegmentIndex: number, // Index of the segment that is currenlty hovered
validSegments: boolean, // Whether the segment will result in a valid video edit
selectedWorkflowId: string, // Id of the currently selected workflow
aspectRatios: { width: number, height: number; }[], // Aspect ratios of every video
hasChanges: boolean, // Did user make changes in cutting view since last save
Expand Down Expand Up @@ -52,6 +53,7 @@ export const initialState: video & httpRequestState = {
tracks: [],
subtitlesFromOpencast: [],
activeSegmentIndex: 0,
validSegments: true,
selectedWorkflowId: "",
previewTriggered: false,
clickTriggered: false,
Expand Down Expand Up @@ -178,6 +180,15 @@ const videoSlice = createSlice({
updateCurrentlyAt(state, state.segments[nextSegmentIndex].start);
state.jumpTriggered = true;
},
validateSegments: state => {
// Test if whole video has been deleted
if (state.segments.length === 1 && state.segments[0].deleted && state.segments[0].start === 0 &&
state.segments[0].end === state.duration) {
state.validSegments = false;
} else {
state.validSegments = true;
}
},
addSegment: (state, action: PayloadAction<video["segments"][0]>) => {
state.segments.push(action.payload);
},
Expand Down Expand Up @@ -351,6 +362,7 @@ const videoSlice = createSlice({
selectCurrentlyAtInSeconds: state => state.currentlyAt / 1000,
selectSegments: state => state.segments,
selectActiveSegmentIndex: state => state.activeSegmentIndex,
selectValidSegments: state => state.validSegments,
selectIsCurrentSegmentAlive: state => !state.segments[state.activeSegmentIndex].deleted,
selectSelectedWorkflowId: state => state.selectedWorkflowId,
selectHasChanges: state => state.hasChanges,
Expand Down Expand Up @@ -520,6 +532,7 @@ export const {
setJumpTriggered,
jumpToPreviousSegment,
jumpToNextSegment,
validateSegments,
} = videoSlice.actions;

export const selectVideos = createSelector(
Expand All @@ -540,6 +553,7 @@ export const {
selectCurrentlyAtInSeconds,
selectSegments,
selectActiveSegmentIndex,
selectValidSegments,
selectIsCurrentSegmentAlive,
selectSelectedWorkflowId,
selectHasChanges,
Expand Down

0 comments on commit 769eea6

Please sign in to comment.