drag & drop - change order in pinned dbs #227

This commit is contained in:
Jan Prochazka
2022-06-02 17:26:45 +02:00
parent 5c6989bf91
commit 8bb40e991b
5 changed files with 40 additions and 3 deletions

View File

@@ -8,14 +8,43 @@
}
return data.connection._id;
};
function dragExchange(dragged, data, pinned, setPinned, compare) {
}
</script>
<script lang="ts">
import _ from 'lodash';
import { draggedPinnedObject, pinnedDatabases } from '../stores';
export let data;
</script>
{#if data.objectTypeField}
<DatabaseObjectAppObject {...$$props} />
<DatabaseObjectAppObject {...$$props}
/>
{:else}
<DatabaseAppObject {...$$props} />
<DatabaseAppObject
{...$$props}
on:dragstart={() => {
$draggedPinnedObject = data;
}}
on:dragenter={e => {
const dragged = $draggedPinnedObject;
if (dragged?.connection?._id != data?.connection?._id || dragged?.name != data?.name) {
const dbs = $pinnedDatabases;
const i1 = _.findIndex(dbs, x => x?.name == dragged?.name && x?.connection?._id == dragged?.connection?._id);
const i2 = _.findIndex(dbs, x => x?.name == data?.name && x?.connection?._id == data?.connection?._id);
const newDbs = [...dbs];
const tmp = newDbs[i1];
newDbs[i1] = newDbs[i2];
newDbs[i2] = tmp;
$pinnedDatabases = newDbs;
}
}}
on:dragend={() => {
$draggedPinnedObject = null;
}}
/>
{/if}