11<script setup lang="ts">
2- import { Heart } from ' @vicons/tabler' ;
2+ import { DragDrop , Heart } from ' @vicons/tabler' ;
33import { useHead } from ' @vueuse/head' ;
4+ import { computed } from ' vue' ;
5+ import Draggable from ' vuedraggable' ;
46import ColoredCard from ' ../components/ColoredCard.vue' ;
57import ToolCard from ' ../components/ToolCard.vue' ;
68import { useToolStore } from ' @/tools/tools.store' ;
@@ -10,6 +12,13 @@ const toolStore = useToolStore();
1012
1113useHead ({ title: ' IT Tools - Handy online tools for developers' });
1214const { 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
0 commit comments