mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Fix: LibraryToolbar Folder Drag
This commit is contained in:
@@ -117,13 +117,15 @@
|
|||||||
|
|
||||||
const visibleCategories = $derived((() => {
|
const visibleCategories = $derived((() => {
|
||||||
const defaultId = store.settings.defaultLibraryCategoryId ?? null;
|
const defaultId = store.settings.defaultLibraryCategoryId ?? null;
|
||||||
return store.categories
|
const pinned = store.settings.libraryPinnedTabOrder ?? [];
|
||||||
.filter(c => c.id !== 0 && !hiddenTabs.has(String(c.id)))
|
const cats = store.categories.filter(c => c.id !== 0 && !hiddenTabs.has(String(c.id)));
|
||||||
.sort((a, b) => {
|
const pinOrder = (id: number) => { const i = pinned.indexOf(String(id)); return i === -1 ? Infinity : i; };
|
||||||
if (a.id === defaultId) return -1;
|
return cats.sort((a, b) => {
|
||||||
if (b.id === defaultId) return 1;
|
if (a.id === defaultId) return -1;
|
||||||
return a.order - b.order;
|
if (b.id === defaultId) return 1;
|
||||||
});
|
const pd = pinOrder(a.id) - pinOrder(b.id);
|
||||||
|
return pd !== 0 ? pd : a.order - b.order;
|
||||||
|
});
|
||||||
})());
|
})());
|
||||||
|
|
||||||
const categoryMangaMap = $derived((() => {
|
const categoryMangaMap = $derived((() => {
|
||||||
@@ -538,17 +540,21 @@
|
|||||||
dragInsertIdx = -1;
|
dragInsertIdx = -1;
|
||||||
if (activeDragKind !== "tab" || dragTabId === null || dragTabId === dropCat.id) { dragTabId = null; return; }
|
if (activeDragKind !== "tab" || dragTabId === null || dragTabId === dropCat.id) { dragTabId = null; return; }
|
||||||
const dragId = dragTabId; dragTabId = null; activeDragKind = null;
|
const dragId = dragTabId; dragTabId = null; activeDragKind = null;
|
||||||
const sorted = [...store.categories].filter(c => c.id !== 0).sort((a, b) => a.order - b.order);
|
const dragStrId = String(dragId);
|
||||||
const fromIdx = sorted.findIndex(c => c.id === dragId);
|
const tabs = [...visibleTabIds];
|
||||||
|
const fromIdx = tabs.indexOf(dragStrId);
|
||||||
if (fromIdx < 0) return;
|
if (fromIdx < 0) return;
|
||||||
const reordered = [...sorted];
|
tabs.splice(fromIdx, 1);
|
||||||
const [moved] = reordered.splice(fromIdx, 1);
|
const dest = Math.max(0, Math.min(insertAt > fromIdx ? insertAt - 1 : insertAt, tabs.length));
|
||||||
const dest = Math.max(0, Math.min(insertAt > fromIdx ? insertAt - 1 : insertAt, reordered.length));
|
tabs.splice(dest, 0, dragStrId);
|
||||||
reordered.splice(dest, 0, moved);
|
updateSettings({ libraryPinnedTabOrder: tabs });
|
||||||
const withNewOrder = reordered.map((c, i) => ({ ...c, order: i + 1 }));
|
const catIds = tabs.filter(id => id !== "library" && id !== "downloaded");
|
||||||
setCategories(store.categories.map(c => withNewOrder.find(u => u.id === c.id) ?? c));
|
const zeroCat = store.categories.filter(c => c.id === 0);
|
||||||
|
const reordered = catIds.map((id, i) => { const c = store.categories.find(x => String(x.id) === id)!; return { ...c, order: i + 1 }; });
|
||||||
|
setCategories([...zeroCat, ...reordered]);
|
||||||
|
const serverPos = catIds.indexOf(dragStrId) + 1;
|
||||||
try {
|
try {
|
||||||
await gql<{ updateCategoryOrder: { categories: Category[] } }>(UPDATE_CATEGORY_ORDER, { id: dragId, position: dest + 1 });
|
await gql<{ updateCategoryOrder: { categories: Category[] } }>(UPDATE_CATEGORY_ORDER, { id: dragId, position: serverPos });
|
||||||
} catch (err) { console.error("Tab reorder failed:", err); await reloadCategories(); }
|
} catch (err) { console.error("Tab reorder failed:", err); await reloadCategories(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
{#each visibleTabIds as id, idx}
|
{#each visibleTabIds as id, idx}
|
||||||
{@const cat = visibleCategories.find(c => String(c.id) === id)}
|
{@const cat = visibleCategories.find(c => String(c.id) === id)}
|
||||||
{#if id === "library" || id === "downloaded" || cat}
|
{#if id === "library" || id === "downloaded" || cat}
|
||||||
{#if cat && dragInsertIdx === idx && activeDragKind === "tab"}
|
{#if activeDragKind === "tab" && dragInsertIdx === idx}
|
||||||
<div class="tab-insert-bar" aria-hidden="true"></div>
|
<div class="tab-insert-bar" aria-hidden="true"></div>
|
||||||
{/if}
|
{/if}
|
||||||
<button
|
<button
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
{id === "library" ? "Saved" : id === "downloaded" ? "Downloaded" : (cat?.name ?? id)}
|
{id === "library" ? "Saved" : id === "downloaded" ? "Downloaded" : (cat?.name ?? id)}
|
||||||
<span class="tab-count">{counts[id] ?? 0}</span>
|
<span class="tab-count">{counts[id] ?? 0}</span>
|
||||||
</button>
|
</button>
|
||||||
{#if cat && id !== String(completedCatId) && dragInsertIdx === idx + 1 && activeDragKind === "tab" && idx === visibleTabIds.length - 1}
|
{#if activeDragKind === "tab" && dragInsertIdx === idx + 1}
|
||||||
<div class="tab-insert-bar" aria-hidden="true"></div>
|
<div class="tab-insert-bar" aria-hidden="true"></div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user