Skip to content

Commit d64fed7

Browse files
committed
fix index=0 in addpod/pastepod
1 parent 9dea32a commit d64fed7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

ui/src/lib/queue/middleware.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ export default (storeAPI) => (next) => (action) => {
4545
// construct the ID here so that the client and the server got the same ID
4646
let payload = produce(action.payload, (draft) => {
4747
let { parent, index, anchor, shift } = draft;
48-
if (!index) {
49-
index = storeAPI.getState().repo.pods[parent].children.findIndex(({ id }) => id === anchor)
50-
if (index == -1) throw new Error("Cannot find anchoar pod:", anchor)
51-
index += shift | 0
52-
draft.index = index
48+
if (index === undefined) {
49+
index = storeAPI
50+
.getState()
51+
.repo.pods[parent].children.findIndex(({ id }) => id === anchor);
52+
if (index == -1)
53+
throw new Error("Cannot find anchoar pod:", anchor);
54+
index += shift | 0;
55+
draft.index = index;
5356
}
5457
const id = "CP" + nanoid();
5558
draft.id = id;
@@ -127,10 +130,12 @@ export default (storeAPI) => (next) => (action) => {
127130
// clear last clip
128131
storeAPI.dispatch(repoSlice.actions.clearLastClip());
129132
// compute index
130-
if (!index) {
131-
index = storeAPI.getState().repo.pods[parent].children.findIndex(({ id }) => id === anchor)
132-
if (index == -1) throw new Error("Cannot find anchoar pod:", anchor)
133-
index += shift | 0
133+
if (index === undefined) {
134+
index = storeAPI
135+
.getState()
136+
.repo.pods[parent].children.findIndex(({ id }) => id === anchor);
137+
if (index == -1) throw new Error("Cannot find anchoar pod:", anchor);
138+
index += shift | 0;
134139
}
135140
let tmpindex = index;
136141
for (let id of clip) {

0 commit comments

Comments
 (0)