Files
appco_dist/.output/server/chunks/build/userPostsStore-CAxMlK-n.mjs
T
2026-01-27 16:02:45 +03:30

54 lines
1.4 KiB
JavaScript

import { defineStore } from 'file:///mnt/new-volume-7/vue_projects/montify/montify/node_modules/pinia/dist/pinia.prod.cjs';
import { ref, nextTick } from 'file:///mnt/new-volume-7/vue_projects/montify/montify/node_modules/vue/index.mjs';
import { a as useConfigStore } from './server.mjs';
import { a as getUserPosts } from './media-_NDkNIvH.mjs';
const useUserPostStore = defineStore("userPosts", () => {
const posts = ref([]);
const endPage = ref(false);
useConfigStore();
const loading2 = ref(false);
const currentPage = ref(0);
const limit = 15;
const total = ref(0);
async function loadPosts(userId, page) {
try {
loading2.value = true;
await nextTick();
const res = await getUserPosts(userId, page, limit);
loading2.value = false;
return res;
} catch (e) {
console.log(e);
} finally {
loading2.value = false;
}
}
function loadStateNextPage(res) {
posts.value.push(...res?.data ?? []);
total.value = res?.count ?? 0;
currentPage.value++;
if (posts.value.length >= total.value) {
endPage.value = true;
}
}
function reset() {
currentPage.value = 0;
posts.value = [];
total.value = 0;
endPage.value = false;
}
return {
loadPosts,
posts,
reset,
loadStateNextPage,
endPage,
currentPage,
limit,
loading: loading2
};
});
export { useUserPostStore as u };