@@ -16,102 +16,144 @@ const i18n = getI18N({ currentLocale });
1616
1717const verticalList= `
1818<script setup lang="ts">
19- import { ref } from "vue";
19+ import { ref, watchEffect } from "vue";
2020import { useDragAndDrop } from "fluid-dnd/vue";
21- import type { Pokemon } from "./Pokemon";
21+ import type { Pokemon } from ".. /Pokemon";
2222import PokemonComponent from "./PokemonComponent.vue";
2323import { fetchPokemons } from "@/server/pokemonServer";
24+ import touchDelaySilder from "./touchDelaySilder.vue";
25+ import { isMobileDevice } from "@/utils/mobile.ts";
2426
2527const pokemons = ref([] as Pokemon[]);
2628pokemons.value = await fetchPokemons(3);
27- const [ parent ] = useDragAndDrop(pokemons,{
28- draggingClass: "dragging-pokemon"
29+ const delay = ref(150);
30+ let parent = ref<HTMLElement | undefined>();
31+
32+ watchEffect(() => {
33+ const dragAndDrop = useDragAndDrop(pokemons, {
34+ draggingClass: "dragging-pokemon",
35+ delayBeforeTouchMoveEvent: delay.value
36+ });
37+ parent = dragAndDrop[0];
2938});
3039</script>
3140<template>
32- <div class="flex max-sm:justify-center items-start">
33- <div
34- ref="parent"
35- class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block"
36- >
37- <PokemonComponent
38- v-for="(pokemon, index) in pokemons"
39- :key="pokemon.name"
40- :index="index"
41- :pokemon="pokemon"
42- />
43- </div>
44- </div>
41+ <div class="flex-col gap-4">
42+ <div class="flex max-sm:justify-center items-start">
43+ <div
44+ ref="parent"
45+ class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block"
46+ >
47+ <PokemonComponent
48+ v-for="(pokemon, index) in pokemons"
49+ :key="pokemon.name"
50+ :index="index"
51+ :pokemon="pokemon"
52+ />
53+ </div>
54+ </div>
55+ <touchDelaySilder v-if="isMobileDevice()" v-model="delay" />
56+ </div>
4557</template>
4658`
4759const verticalListSvelteCode= `
4860 <script lang="ts">
4961 import { useDragAndDrop } from "fluid-dnd/svelte";
50- import type { Pokemon } from "./Pokemon";
62+ import type { Pokemon } from ".. /Pokemon";
5163 import PokemonComponent from "./PokemonComponent.svelte";
5264 import { fetchPokemons } from "@/server/pokemonServer";
65+ import TouchDelaySilder from "./touchDelaySilder.svelte";
66+ import { isMobileDevice } from "@/utils/mobile.ts";
5367
68+ let delay = $state(150);
5469 let pokemons = $state([] as Pokemon[]);
70+ let parent: HTMLElement;
5571 fetchPokemons(3).then((newPokemons) => {
5672 pokemons.push(...newPokemons);
5773 });
58- const [ parent ] = useDragAndDrop(pokemons, {
59- draggingClass: "dragging-pokemon",
60- });
61- </script>
74+ const changeDelay = (newDelay:number) => {
75+ delay = newDelay;
76+ if (parent) {
77+ dragAndDropAction(parent);
78+ }
79+ }
80+ const [ dragAndDropAction ] = $derived(useDragAndDrop(pokemons, {
81+ draggingClass: "dragging-pokemon",
82+ delayBeforeTouchMoveEvent: delay
83+ }));
84+
85+ </script>
86+ <div class="flex-col gap-4">
6287 <div class="flex max-sm:justify-center items-start">
6388 <div
64- use:parent
89+ bind:this={parent}
90+ use:dragAndDropAction
6591 class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block"
6692 >
67- {#each pokemons as pokemon, index (pokemon.name)}
68- <PokemonComponent
69- index={index}
70- pokemon={pokemon}
71- />
72- {/each}
93+ {#each pokemons as pokemon, index (pokemon.name)}
94+ <PokemonComponent
95+ index={index}
96+ pokemon={pokemon}
97+ />
98+ {/each}
7399 </div>
74100 </div>
101+ {#if isMobileDevice()}
102+ <TouchDelaySilder {changeDelay} />
103+ {/if}
104+ </div>
75105 `
76106const verticalListReact = `
77107import { useDragAndDrop } from "fluid-dnd/react";
78108import type { Pokemon } from "../Pokemon";
79109import { fetchPokemons } from "@/server/pokemonServer";
80110import { PokemonComponent } from "./PokemonComponent";
81- import { useEffect } from "react";
111+ import { useEffect, useState } from "react";
112+ import { TouchDelaySilder } from "./TouchDelaySilder.tsx";
113+ import { isMobileDevice } from "@/utils/mobile.ts";
82114
83115export const SingleVerticalListOfPokemons: React.FC = () => {
84- const [ parent, listOfPokemons, setPokemons ] = useDragAndDrop<Pokemon, HTMLDivElement>([], {
85- draggingClass: "dragging-pokemon",
86- });
87- useEffect(() => {
88- const fetchPokemonse = async () => {
89- const newPokemons = await fetchPokemons(3);
90- setPokemons(newPokemons);
91- }
92- fetchPokemonse();
93- }, [])
116+ const [delay, setDelay] = useState(150);
117+ const [isMobile, setIsMobile] = useState(false);
118+ const [parent, listOfPokemons, setPokemons] = useDragAndDrop<Pokemon, HTMLDivElement>([], {
119+ draggingClass: "dragging-pokemon",
120+ delayBeforeTouchMoveEvent: delay
121+ });
94122
95- return (
96- <div className="flex max-sm:justify-center items-start">
97- <div
98- ref={parent}
99- className="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block"
100- >
101- {
102- listOfPokemons.map((pokemon, index) => (
103- <PokemonComponent
104- key={pokemon.name}
105- className="min-w-44 max-sm:min-w-32"
106- index={index}
107- pokemon={pokemon}
108- />
109- ))
110- }
111- </div>
112- </div>
113- )
114- }
123+ useEffect(() => {
124+ const fetchPokemonse = async () => {
125+ const newPokemons = await fetchPokemons(3);
126+ setPokemons(newPokemons);
127+ };
128+ fetchPokemonse();
129+ }, []);
130+
131+ useEffect(() => {
132+ setIsMobile(isMobileDevice());
133+ }, []);
134+ return (
135+ <div className="flex-col gap-4">
136+ <div className="flex max-sm:justify-center items-start">
137+ <div
138+ ref={parent}
139+ className="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block"
140+ >
141+ {listOfPokemons.map((pokemon, index) => (
142+ <PokemonComponent key={pokemon.name} index={index} pokemon={pokemon} />
143+ ))}
144+ </div>
145+ </div>
146+ {isMobile && (
147+ <TouchDelaySilder
148+ value={delay}
149+ changeDelay={(newDelay) => {
150+ setDelay(newDelay);
151+ }}
152+ />
153+ )}
154+ </div>
155+ );
156+ };
115157`
116158const fileName = ' SingleVerticalListOfPokemons' ;
117159---
0 commit comments