Skip to content

Commit c47b67a

Browse files
committed
add vuedraggable to favorites section
1 parent f836666 commit c47b67a

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"vue-router": "^4.1.6",
9999
"vue-shadow-dom": "^4.2.0",
100100
"vue-tsc": "^1.8.1",
101+
"vuedraggable": "^4.1.0",
101102
"xml-formatter": "^3.3.2",
102103
"xml-js": "^1.6.11",
103104
"yaml": "^2.2.1"

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/Home.page.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
2-
import { Heart } from '@vicons/tabler';
2+
import { DragDrop, Heart } from '@vicons/tabler';
33
import { useHead } from '@vueuse/head';
4+
import { computed } from 'vue';
5+
import Draggable from 'vuedraggable';
46
import ColoredCard from '../components/ColoredCard.vue';
57
import ToolCard from '../components/ToolCard.vue';
68
import { useToolStore } from '@/tools/tools.store';
@@ -10,6 +12,13 @@ const toolStore = useToolStore();
1012
1113
useHead({ title: 'IT Tools - Handy online tools for developers' });
1214
const { t } = useI18n();
15+
16+
const favoriteTools = computed(() => toolStore.favoriteTools);
17+
18+
// Update favorite tools order when drag is finished
19+
function onUpdateFavoriteTools() {
20+
toolStore.updateFavoriteTools(favoriteTools.value); // Update the store with the new order
21+
}
1322
</script>
1423

1524
<template>
@@ -66,10 +75,20 @@ const { t } = useI18n();
6675
<div v-if="toolStore.favoriteTools.length > 0">
6776
<h3 class="mb-5px mt-25px font-500 text-neutral-400">
6877
{{ $t('home.categories.favoriteTools') }}
78+
<c-tooltip tooltip="Drag and drop to reorder favorites">
79+
<n-icon :component="DragDrop" size="18" />
80+
</c-tooltip>
6981
</h3>
70-
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
71-
<ToolCard v-for="tool in toolStore.favoriteTools" :key="tool.name" :tool="tool" />
72-
</div>
82+
<Draggable
83+
:list="favoriteTools"
84+
class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4"
85+
item-key="name"
86+
@end="onUpdateFavoriteTools"
87+
>
88+
<template #item="{ element: tool }">
89+
<ToolCard :tool="tool" />
90+
</template>
91+
</Draggable>
7392
</div>
7493
</transition>
7594

src/tools/tools.store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@ export const useToolStore = defineStore('tools', () => {
5656
return favoriteToolsName.value.includes(get(tool).name)
5757
|| favoriteToolsName.value.includes(get(tool).path);
5858
},
59+
60+
updateFavoriteTools(newOrder: ToolWithCategory[]) {
61+
favoriteToolsName.value = newOrder.map(tool => tool.path);
62+
},
5963
};
6064
});

0 commit comments

Comments
 (0)