Skip to content

Commit a41cbe8

Browse files
committed
make sure no dupes
1 parent 7a93e5f commit a41cbe8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/webpage/channel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class Channel extends SnowFlake {
530530
}
531531
return this.parent !== undefined;
532532
}
533-
calculateReorder() {
533+
calculateReorder(numbset: Set<number>) {
534534
let position = -1;
535535
const build: {
536536
id: string;
@@ -544,9 +544,15 @@ class Channel extends SnowFlake {
544544
parent_id: string | undefined;
545545
} = {id: thing.id, position: undefined, parent_id: undefined};
546546

547-
if (thing.position < position) {
547+
if (thing.position <= position) {
548548
thing.position = thisthing.position = position + 1;
549549
}
550+
while (numbset.has(thing.position)) {
551+
thing.position++;
552+
thisthing.position = thing.position;
553+
console.log(thing.position - 1);
554+
}
555+
numbset.add(thing.position);
550556
position = thing.position;
551557
if (thing.move_id && thing.move_id !== thing.parent_id) {
552558
thing.parent_id = thing.move_id;

src/webpage/guild.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ class Guild extends SnowFlake {
11631163
position: number | undefined;
11641164
parent_id: string | undefined | null;
11651165
}[] = [];
1166+
const numbset = new Set<number>();
11661167
for (const thing of this.headchannels) {
11671168
const thisthing: {
11681169
id: string;
@@ -1172,6 +1173,12 @@ class Guild extends SnowFlake {
11721173
if (thing.position <= position) {
11731174
thing.position = thisthing.position = position + 1;
11741175
}
1176+
while (numbset.has(thing.position)) {
1177+
thing.position++;
1178+
thisthing.position = thing.position;
1179+
console.log(thing.position - 1);
1180+
}
1181+
numbset.add(thing.position);
11751182
position = thing.position;
11761183
console.log(position);
11771184
if (thing.move_id && thing.move_id !== thing.parent_id) {
@@ -1183,7 +1190,7 @@ class Guild extends SnowFlake {
11831190
build.push(thisthing);
11841191
}
11851192
if (thing.children.length > 0) {
1186-
const things = thing.calculateReorder();
1193+
const things = thing.calculateReorder(numbset);
11871194
for (const thing of things) {
11881195
build.push(thing);
11891196
}

0 commit comments

Comments
 (0)