Files
appco_dist/.output/server/chunks/build/userPostsStore-D99btRcA.mjs
T
2025-07-23 16:57:31 +03:30

60 lines
1.5 KiB
JavaScript

import { defineStore } from 'pinia';
import { ref, computed, nextTick } from 'vue';
import { a as useConfigStore } from './server.mjs';
import { a as getUserPosts } from './media-BgNug793.mjs';
const useUserPostStore = defineStore("userPosts", () => {
const posts = ref([]);
const endPage = ref(false);
const config = useConfigStore();
const loading2 = ref(false);
const currentPage = ref(0);
const limit = ref(15);
const total = ref(0);
computed(() => {
var _a;
return (_a = config.sellerConfig) == null ? void 0 : _a.store;
});
async function loadPosts(userId, page) {
try {
loading2.value = true;
await nextTick();
const res = await getUserPosts(userId, page, limit.value);
loading2.value = false;
return res;
} catch (e) {
console.log(e);
} finally {
loading2.value = false;
}
}
function loadStateNextPage(res) {
var _a, _b;
posts.value.push(...(_a = res == null ? void 0 : res.data) != null ? _a : []);
total.value = (_b = res == null ? void 0 : res.count) != null ? _b : 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 };
//# sourceMappingURL=userPostsStore-D99btRcA.mjs.map