From a41cbe89ca74b03e73320ba4bf7abeddf609903c Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 30 Apr 2025 22:54:13 -0500 Subject: [PATCH] make sure no dupes --- src/webpage/channel.ts | 10 ++++++++-- src/webpage/guild.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 0331c69..47b7823 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -530,7 +530,7 @@ class Channel extends SnowFlake { } return this.parent !== undefined; } - calculateReorder() { + calculateReorder(numbset: Set) { let position = -1; const build: { id: string; @@ -544,9 +544,15 @@ class Channel extends SnowFlake { parent_id: string | undefined; } = {id: thing.id, position: undefined, parent_id: undefined}; - if (thing.position < position) { + if (thing.position <= position) { thing.position = thisthing.position = position + 1; } + while (numbset.has(thing.position)) { + thing.position++; + thisthing.position = thing.position; + console.log(thing.position - 1); + } + numbset.add(thing.position); position = thing.position; if (thing.move_id && thing.move_id !== thing.parent_id) { thing.parent_id = thing.move_id; diff --git a/src/webpage/guild.ts b/src/webpage/guild.ts index 28d47a9..1ce5fe5 100644 --- a/src/webpage/guild.ts +++ b/src/webpage/guild.ts @@ -1163,6 +1163,7 @@ class Guild extends SnowFlake { position: number | undefined; parent_id: string | undefined | null; }[] = []; + const numbset = new Set(); for (const thing of this.headchannels) { const thisthing: { id: string; @@ -1172,6 +1173,12 @@ class Guild extends SnowFlake { if (thing.position <= position) { thing.position = thisthing.position = position + 1; } + while (numbset.has(thing.position)) { + thing.position++; + thisthing.position = thing.position; + console.log(thing.position - 1); + } + numbset.add(thing.position); position = thing.position; console.log(position); if (thing.move_id && thing.move_id !== thing.parent_id) { @@ -1183,7 +1190,7 @@ class Guild extends SnowFlake { build.push(thisthing); } if (thing.children.length > 0) { - const things = thing.calculateReorder(); + const things = thing.calculateReorder(numbset); for (const thing of things) { build.push(thing); }