more reodering fixes

This commit is contained in:
MathMan05 2025-05-02 12:06:20 -05:00
parent 169f56b5c5
commit f0fd2e59b3
4 changed files with 30 additions and 35 deletions

View file

@ -79,7 +79,7 @@ await build();
if (process.argv.includes("watch")) { if (process.argv.includes("watch")) {
let last = Date.now(); let last = Date.now();
(async () => { (async () => {
for await (const thing of fs.watch(path.join(__dirname, "src"))) { for await (const thing of fs.watch(path.join(__dirname, "src"), {recursive: true})) {
if (Date.now() - last < 100) { if (Date.now() - last < 100) {
continue; continue;
} }

View file

@ -530,8 +530,7 @@ class Channel extends SnowFlake {
} }
return this.parent !== undefined; return this.parent !== undefined;
} }
calculateReorder(numbset: Set<number>) { calculateReorder(position: number) {
let position = -1;
const build: { const build: {
id: string; id: string;
position: number | undefined; position: number | undefined;
@ -544,16 +543,9 @@ class Channel extends SnowFlake {
parent_id: string | undefined; parent_id: string | undefined;
} = {id: thing.id, position: undefined, parent_id: undefined}; } = {id: thing.id, position: undefined, parent_id: undefined};
if (thing.position <= position) { if (thing.position != position) {
thing.position = thisthing.position = position + 1; thisthing.position = thing.position = position;
} }
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) { if (thing.move_id && thing.move_id !== thing.parent_id) {
thing.parent_id = thing.move_id; thing.parent_id = thing.move_id;
thisthing.parent_id = thing.parent?.id; thisthing.parent_id = thing.parent?.id;
@ -563,8 +555,9 @@ class Channel extends SnowFlake {
if (thisthing.position || thisthing.parent_id) { if (thisthing.position || thisthing.parent_id) {
build.push(thisthing); build.push(thisthing);
} }
position++;
} }
return build; return [build, position] as const;
} }
static dragged: [Channel, HTMLDivElement] | [] = []; static dragged: [Channel, HTMLDivElement] | [] = [];
html: WeakRef<HTMLElement> | undefined; html: WeakRef<HTMLElement> | undefined;
@ -804,6 +797,7 @@ class Channel extends SnowFlake {
} }
coatDropDiv(div: HTMLDivElement, container: HTMLElement | false = false) { coatDropDiv(div: HTMLDivElement, container: HTMLElement | false = false) {
div.style.position = "relative";
div.addEventListener("dragenter", (event) => { div.addEventListener("dragenter", (event) => {
console.log("enter"); console.log("enter");
event.preventDefault(); event.preventDefault();
@ -889,17 +883,16 @@ class Channel extends SnowFlake {
div.after(Channel.dragged[1]); div.after(Channel.dragged[1]);
} }
} else { } else {
div = div.parentElement as HTMLDivElement; let tdiv = div.parentElement as HTMLDivElement;
if (!div) return; if (!tdiv) return;
div = div.parentElement as HTMLDivElement; tdiv = tdiv.parentElement as HTMLDivElement;
if (!div) return; if (!tdiv) return;
console.log(div);
Channel.dragged[1].remove(); Channel.dragged[1].remove();
if (before) { if (before) {
div.before(Channel.dragged[1]); tdiv.before(Channel.dragged[1]);
} else { } else {
div.after(Channel.dragged[1]); tdiv.after(Channel.dragged[1]);
} }
} }
} }

View file

@ -1157,40 +1157,36 @@ class Guild extends SnowFlake {
console.log(build); console.log(build);
} }
calculateReorder(movedId?: string) { calculateReorder(movedId?: string) {
let position = -1; let position = 0;
const build: { type buildtype = {
id: string; id: string;
position: number | undefined; position: number | undefined;
parent_id: string | undefined | null; parent_id: string | undefined | null;
}[] = []; }[];
const numbset = new Set<number>(); const build: buildtype = [];
for (const thing of this.headchannels) { for (const thing of this.headchannels) {
const thisthing: { const thisthing: {
id: string; id: string;
position: number | undefined; position: number | undefined;
parent_id: string | undefined; parent_id: string | undefined;
} = {id: thing.id, position: undefined, parent_id: undefined}; } = {id: thing.id, position: undefined, parent_id: undefined};
if (thing.position <= position) { if (thing.position != position) {
thing.position = thisthing.position = position + 1; thisthing.position = thing.position = position;
} }
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); console.log(position);
if (thing.move_id && thing.move_id !== thing.parent_id) { if (thing.move_id && thing.move_id !== thing.parent_id) {
thing.parent_id = thing.move_id; thing.parent_id = thing.move_id;
thisthing.parent_id = thing.parent?.id; thisthing.parent_id = thing.parent?.id;
thing.move_id = undefined; thing.move_id = undefined;
} }
if (thisthing.position || thisthing.parent_id) { if (thisthing.position !== undefined || thisthing.parent_id) {
build.push(thisthing); build.push(thisthing);
} }
position++;
if (thing.children.length > 0) { if (thing.children.length > 0) {
const things = thing.calculateReorder(numbset); let things: buildtype;
[things, position] = thing.calculateReorder(position);
for (const thing of things) { for (const thing of things) {
build.push(thing); build.push(thing);
} }

View file

@ -3056,6 +3056,12 @@ img.error::after {
top: 0; top: 0;
left: 0; left: 0;
} }
.dragBottomView {
position: relative;
}
.dragTopView {
position: relative;
}
.dragTopView::after { .dragTopView::after {
content: ""; content: "";
width: 100%; width: 100%;