added drag&drop
This commit is contained in:
parent
6116069fff
commit
623d3f90bf
|
|
@ -2,7 +2,7 @@
|
||||||
import type { Topic } from '@ka-note/shared';
|
import type { Topic } from '@ka-note/shared';
|
||||||
import { liveQuery } from 'dexie';
|
import { liveQuery } from 'dexie';
|
||||||
import { db } from '$lib/db/schema';
|
import { db } from '$lib/db/schema';
|
||||||
import { createTopic, createHistoryEntry, JOURNAL_TOPIC_ID } from '$lib/db/repositories';
|
import { createTopic, createHistoryEntry, updateTopicSortOrder, JOURNAL_TOPIC_ID } from '$lib/db/repositories';
|
||||||
import { today } from '$lib/db/helpers';
|
import { today } from '$lib/db/helpers';
|
||||||
import { processedTopicIds } from '$lib/stores/agenda';
|
import { processedTopicIds } from '$lib/stores/agenda';
|
||||||
import TopicInput from './TopicInput.svelte';
|
import TopicInput from './TopicInput.svelte';
|
||||||
|
|
@ -53,6 +53,34 @@
|
||||||
const topic = await createTopic(contextId, title);
|
const topic = await createTopic(contextId, title);
|
||||||
await createHistoryEntry(topic.id, today(), 'Thema angelegt.');
|
await createHistoryEntry(topic.id, today(), 'Thema angelegt.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Drag & Drop ---
|
||||||
|
let dragId = $state<string | null>(null);
|
||||||
|
let dragOverId = $state<string | null>(null);
|
||||||
|
|
||||||
|
function onDragStart(id: string) {
|
||||||
|
dragId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragOver(id: string) {
|
||||||
|
if (dragId && id !== dragId) dragOverId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragEnd() {
|
||||||
|
if (dragId && dragOverId) {
|
||||||
|
const list = showSplit ? [...openTopics] : [...allTopics];
|
||||||
|
const fromIdx = list.findIndex(t => t.id === dragId);
|
||||||
|
const toIdx = list.findIndex(t => t.id === dragOverId);
|
||||||
|
if (fromIdx !== -1 && toIdx !== -1) {
|
||||||
|
const reordered = [...list];
|
||||||
|
const [moved] = reordered.splice(fromIdx, 1);
|
||||||
|
reordered.splice(toIdx, 0, moved);
|
||||||
|
updateTopicSortOrder(contextId, reordered.map(t => t.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dragId = null;
|
||||||
|
dragOverId = null;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TopicInput oncreate={handleCreate} />
|
<TopicInput oncreate={handleCreate} />
|
||||||
|
|
@ -65,13 +93,21 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#each openTopics as topic (topic.id)}
|
{#each openTopics as topic (topic.id)}
|
||||||
<TopicCard
|
<div
|
||||||
{topic}
|
draggable="true"
|
||||||
{contextId}
|
ondragstart={() => onDragStart(topic.id)}
|
||||||
{isDailyLog}
|
ondragover={(e) => { e.preventDefault(); onDragOver(topic.id); }}
|
||||||
{isMeetingMode}
|
ondragend={onDragEnd}
|
||||||
isProcessed={false}
|
class="transition-opacity {dragId === topic.id ? 'opacity-30' : ''} {dragOverId === topic.id ? 'outline outline-2 outline-accent rounded-lg' : ''}"
|
||||||
/>
|
>
|
||||||
|
<TopicCard
|
||||||
|
{topic}
|
||||||
|
{contextId}
|
||||||
|
{isDailyLog}
|
||||||
|
{isMeetingMode}
|
||||||
|
isProcessed={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
{#if processedTopics.length > 0}
|
{#if processedTopics.length > 0}
|
||||||
|
|
@ -91,13 +127,21 @@
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
{#each allTopics as topic (topic.id)}
|
{#each allTopics as topic (topic.id)}
|
||||||
<TopicCard
|
<div
|
||||||
{topic}
|
draggable="true"
|
||||||
{contextId}
|
ondragstart={() => onDragStart(topic.id)}
|
||||||
{isDailyLog}
|
ondragover={(e) => { e.preventDefault(); onDragOver(topic.id); }}
|
||||||
{isMeetingMode}
|
ondragend={onDragEnd}
|
||||||
isProcessed={processedIds.has(topic.id)}
|
class="transition-opacity {dragId === topic.id ? 'opacity-30' : ''} {dragOverId === topic.id ? 'outline outline-2 outline-accent rounded-lg' : ''}"
|
||||||
/>
|
>
|
||||||
|
<TopicCard
|
||||||
|
{topic}
|
||||||
|
{contextId}
|
||||||
|
{isDailyLog}
|
||||||
|
{isMeetingMode}
|
||||||
|
isProcessed={processedIds.has(topic.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue