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

N21-2070 Prevent media shelf card from duplicating #3329

Merged
merged 6 commits into from
Jul 19, 2024
50 changes: 30 additions & 20 deletions src/modules/feature/media-shelf/data/mediaBoardState.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ const useMediaBoardState = () => {
return;
}

mediaBoard.value.lines.splice(lineIndex, 1);
const temp = Array.from(mediaBoard.value.lines);
temp.splice(lineIndex, 1);
mediaBoard.value.lines = temp;

await api.deleteLine(lineId);

Expand Down Expand Up @@ -171,12 +173,11 @@ const useMediaBoardState = () => {
return;
}

const line: MediaLineResponse = mediaBoard.value.lines.splice(
oldLineIndex,
1
)[0];
const temp = Array.from(mediaBoard.value.lines);
const line: MediaLineResponse = temp.splice(oldLineIndex, 1)[0];

mediaBoard.value.lines.splice(newLineIndex, 0, line);
temp.splice(newLineIndex, 0, line);
mediaBoard.value.lines = temp;

await api.moveLine(lineId, mediaBoard.value.id, newLineIndex);
} catch (error) {
Expand Down Expand Up @@ -334,7 +335,11 @@ const useMediaBoardState = () => {
toLineId = newLine.id;
}

availableMediaLine.value?.elements.splice(oldElementIndex, 1);
if (availableMediaLine.value) {
const temp = Array.from(availableMediaLine.value.elements);
temp.splice(oldElementIndex, 1);
availableMediaLine.value.elements = temp;
}

const newElement: MediaExternalToolElementResponse =
await api.createElement(
Expand All @@ -345,11 +350,9 @@ const useMediaBoardState = () => {

const lineIndex: number = getLineIndex(toLineId);

mediaBoard.value.lines[lineIndex].elements.splice(
newElementIndex,
0,
newElement
);
const temp = Array.from(mediaBoard.value.lines[lineIndex].elements);
temp.splice(newElementIndex, 0, newElement);
mediaBoard.value.lines[lineIndex].elements = temp;

return newElement;
} catch (error) {
Expand Down Expand Up @@ -377,7 +380,9 @@ const useMediaBoardState = () => {
lineIndex
].elements.findIndex((element) => element.id === elementId);

mediaBoard.value.lines[lineIndex].elements.splice(elementIndex, 1);
const temp = Array.from(mediaBoard.value.lines[lineIndex].elements);
temp.splice(elementIndex, 1);
mediaBoard.value.lines[lineIndex].elements = temp;

await api.deleteElement(elementId);

Expand Down Expand Up @@ -429,15 +434,20 @@ const useMediaBoardState = () => {

await api.moveElement(elementId, toLineId, newElementIndex);

const element: MediaExternalToolElementResponse = mediaBoard.value.lines[
fromLineIndex
].elements.splice(oldElementIndex, 1)[0];
const tempFromLine = Array.from(
mediaBoard.value.lines[fromLineIndex].elements
);
const element: MediaExternalToolElementResponse = tempFromLine.splice(
oldElementIndex,
1
)[0];
mediaBoard.value.lines[fromLineIndex].elements = tempFromLine;

mediaBoard.value.lines[toLineIndex].elements.splice(
newElementIndex,
0,
element
const tempToLine = Array.from(
mediaBoard.value.lines[toLineIndex].elements
);
tempToLine.splice(newElementIndex, 0, element);
mediaBoard.value.lines[toLineIndex].elements = tempToLine;
} catch (error) {
handleAnyError(
error,
Expand Down
Loading