feat: add animation

This commit is contained in:
Sergey Krylov 2025-01-27 07:28:58 +03:00
parent 7f2d0ccc9d
commit e25a5d3bfb
6 changed files with 21 additions and 5 deletions

View File

@ -11,6 +11,7 @@
"format": "prettier --write src/" "format": "prettier --write src/"
}, },
"dependencies": { "dependencies": {
"@formkit/auto-animate": "^0.8.2",
"axios": "^1.7.9", "axios": "^1.7.9",
"vue": "^3.5.13", "vue": "^3.5.13",
"vue3-toastify": "^0.2.8" "vue3-toastify": "^0.2.8"

View File

@ -10,13 +10,14 @@
const showDrawer = ref(false); const showDrawer = ref(false);
const items = ref([]); const items = ref([]);
const isLoading = ref(false); const isLoading = ref(false);
const isFetching = ref(false);
const filters = reactive({ const filters = reactive({
searchQuery: '', searchQuery: '',
sortBy: '' sortBy: ''
}); });
const isCreatingOrder = ref(false); const isCreatingOrder = ref(false);
const fetchItems = async (filters = {}) => { const fetchItems = async (filters = {}, {isFirstLoading}) => {
const params = {}; const params = {};
if (filters.searchQuery) { if (filters.searchQuery) {
params.title = '*' + filters.searchQuery + '*' params.title = '*' + filters.searchQuery + '*'
@ -26,17 +27,21 @@
} }
try { try {
if (isFirstLoading) {
isLoading.value = true isLoading.value = true
}
isFetching.value = true
const { data } = await axios.get(`${import.meta.env.VITE_API_URL}/items`, { params }); const { data } = await axios.get(`${import.meta.env.VITE_API_URL}/items`, { params });
items.value = data items.value = data
} catch (e) { } catch (e) {
console.error('Some error', e) console.error('Some error', e)
} finally { } finally {
isLoading.value = false isLoading.value = false
isFetching.value = false
} }
} }
onMounted(fetchItems) onMounted(() => fetchItems({}, {isFirstLoading: true}))
watch(filters, fetchItems) watch(filters, fetchItems)
const toggleToFavorite = async (item) => { const toggleToFavorite = async (item) => {

View File

@ -12,7 +12,7 @@
</script> </script>
<template> <template>
<div class="grid md:grid-cols-2 xl:grid-cols-4 gap-5"> <div class="grid md:grid-cols-2 xl:grid-cols-4 gap-5" v-auto-animate>
<Card <Card
v-for="item in items" v-for="item in items"
:key="item.id" :key="item.id"

View File

@ -13,7 +13,7 @@
</script> </script>
<template> <template>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4" v-auto-animate>
<CartItem v-for="item in items" :key="item.id" :item="item" @on-remove="toggleToCart" /> <CartItem v-for="item in items" :key="item.id" :item="item" @on-remove="toggleToCart" />
</div> </div>
</template> </template>

View File

@ -2,7 +2,9 @@ import { createApp } from 'vue'
import './assets/main.css' import './assets/main.css'
import App from './App.vue' import App from './App.vue'
import Vue3Toastify from 'vue3-toastify'; import Vue3Toastify from 'vue3-toastify';
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'
const app = createApp(App); const app = createApp(App);
app.use(Vue3Toastify, { autoClose: 1000 }); app.use(Vue3Toastify, { autoClose: 1000 });
app.use(autoAnimatePlugin);
app.mount('#app') app.mount('#app')

View File

@ -609,6 +609,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@formkit/auto-animate@npm:^0.8.2":
version: 0.8.2
resolution: "@formkit/auto-animate@npm:0.8.2"
checksum: 10c0/0b24af241c229f37643cd62ea78fd7fddf621c06516cf62452035ea0bf489b6b53068eea47abb40b6bb3653bb91c1efad8b7257014a3559d26ad77b47b5337cb
languageName: node
linkType: hard
"@humanfs/core@npm:^0.19.1": "@humanfs/core@npm:^0.19.1":
version: 0.19.1 version: 0.19.1
resolution: "@humanfs/core@npm:0.19.1" resolution: "@humanfs/core@npm:0.19.1"
@ -1276,6 +1283,7 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "archakov-vue@workspace:." resolution: "archakov-vue@workspace:."
dependencies: dependencies:
"@formkit/auto-animate": "npm:^0.8.2"
"@vitejs/plugin-vue": "npm:^5.2.1" "@vitejs/plugin-vue": "npm:^5.2.1"
"@vitejs/plugin-vue-jsx": "npm:^4.1.1" "@vitejs/plugin-vue-jsx": "npm:^4.1.1"
"@vue/eslint-config-prettier": "npm:^10.1.0" "@vue/eslint-config-prettier": "npm:^10.1.0"