Files
appco_dist/.output/server/chunks/build/userPostsStore-zgAQCVWR.mjs
T

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-02-23 12:50:59 +03:30
import { defineStore } from 'pinia';
import { ref, nextTick } from 'vue';
2025-07-23 16:57:31 +03:30
import { a as useConfigStore } from './server.mjs';
2026-02-22 12:27:05 +03:30
import { g as getUserPosts } from './media-CiMHc-Ka.mjs';
2025-07-23 16:57:31 +03:30
const useUserPostStore = defineStore("userPosts", () => {
const posts = ref([]);
const endPage = ref(false);
2026-01-27 16:02:45 +03:30
useConfigStore();
2025-07-23 16:57:31 +03:30
const loading2 = ref(false);
const currentPage = ref(0);
2026-01-27 16:02:45 +03:30
const limit = 15;
2025-07-23 16:57:31 +03:30
const total = ref(0);
async function loadPosts(userId, page) {
try {
loading2.value = true;
await nextTick();
2026-01-27 16:02:45 +03:30
const res = await getUserPosts(userId, page, limit);
2025-07-23 16:57:31 +03:30
loading2.value = false;
return res;
} catch (e) {
console.log(e);
} finally {
loading2.value = false;
}
}
function loadStateNextPage(res) {
2025-08-19 21:38:30 +03:30
posts.value.push(...res?.data ?? []);
total.value = res?.count ?? 0;
2025-07-23 16:57:31 +03:30
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 };