153 lines
6.7 KiB
JavaScript
153 lines
6.7 KiB
JavaScript
import { u as useRouter$1, a as useConfigStore, b as useUserStore, m as useIntersectionObserver, _ as __nuxt_component_0, n as getToken, d as api$1 } from './server.mjs';
|
|
import { defineComponent, computed, ref, withAsyncContext, provide, unref, useSSRContext } from 'vue';
|
|
import { ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrInterpolate, ssrRenderList, ssrRenderStyle } from 'vue/server-renderer';
|
|
import { P as Post, _ as _sfc_main$1 } from './PostCardSkeleton-BfG9M_Aj.mjs';
|
|
import { u as useUserPostStore } from './userPostsStore-CAxMlK-n.mjs';
|
|
import { C as CommentAddEdit, _ as _sfc_main$2, d as deletePostLike, c as createPostLike } from './moreOptionProduct-DGhUOthE.mjs';
|
|
import { d as deleteSave, c as createSave } from './save-6qQTYFWc.mjs';
|
|
import { u as useAsyncData } from './asyncData-CZ9BKXPA.mjs';
|
|
|
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
__name: "index",
|
|
__ssrInlineRender: true,
|
|
async setup(__props) {
|
|
let __temp, __restore;
|
|
const router = useRouter$1();
|
|
const config = useConfigStore();
|
|
const user = useUserStore();
|
|
const userId = computed(() => router.currentRoute.value.query.userId);
|
|
const commentPostId = ref();
|
|
const commentVisible = ref(false);
|
|
const optionVisible = ref(false);
|
|
const optionPostId = ref();
|
|
const ownerPostId = ref();
|
|
const addLikeLoading = ref(false);
|
|
const userPostStore = useUserPostStore();
|
|
computed(() => router.currentRoute.value.query.target || null);
|
|
function handleLike(isLiked, id) {
|
|
try {
|
|
addLikeLoading.value = true;
|
|
if (getToken()) {
|
|
if (isLiked) {
|
|
deletePostLike(id);
|
|
const index = userPostStore.posts?.findIndex((x) => x.id === id);
|
|
userPostStore.posts[index]?.likes.splice(userPostStore.posts[index]?.likes?.findIndex((y) => y.user_id === user.user.id));
|
|
} else {
|
|
createPostLike(id);
|
|
const index = userPostStore.posts?.findIndex((x) => x.id === id);
|
|
userPostStore.posts[index]?.likes.push({
|
|
product_id: id,
|
|
user_id: user.user.id
|
|
});
|
|
}
|
|
} else {
|
|
router.push({ name: "auth-login" });
|
|
api$1.warn(config.useString("pleaseLoginOrRegister"));
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
} finally {
|
|
addLikeLoading.value = false;
|
|
}
|
|
}
|
|
function addCommentId(id) {
|
|
userPostStore.posts[userPostStore.posts.findIndex((x) => x.id === commentPostId.value)]?.comments.push({ id });
|
|
}
|
|
function deleteCommentId() {
|
|
userPostStore.posts[userPostStore.posts.findIndex((x) => x.id === commentPostId.value)]?.comments.splice(0, 1);
|
|
}
|
|
const observer = ref();
|
|
useIntersectionObserver(observer, async ([{ isIntersecting }]) => {
|
|
if (isIntersecting && !userPostStore.loading && !userPostStore.endPage) {
|
|
const nextPage = userPostStore.currentPage + 1;
|
|
const data2 = await userPostStore.loadPosts(userId.value, nextPage);
|
|
userPostStore.loadStateNextPage(data2);
|
|
}
|
|
});
|
|
const { data } = ([__temp, __restore] = withAsyncContext(async () => useAsyncData("productPostMainSeller", async () => {
|
|
if (userPostStore.posts.length === 0) {
|
|
return await userPostStore.loadPosts(userId.value, 1);
|
|
} else {
|
|
return null;
|
|
}
|
|
})), __temp = await __temp, __restore(), __temp);
|
|
function handleSave(isSaved, id) {
|
|
if (getToken()) {
|
|
if (isSaved) {
|
|
deleteSave(id);
|
|
const index = userPostStore.posts?.findIndex((x) => x.id === id);
|
|
userPostStore.posts[index]?.saved.splice(userPostStore.posts[index]?.saved?.findIndex((y) => y.user_id === user.user.id));
|
|
} else {
|
|
createSave(id);
|
|
const index = userPostStore.posts?.findIndex((x) => x.id === id);
|
|
userPostStore.posts[index]?.saved.push({
|
|
product_id: id,
|
|
user_id: user.user.id
|
|
});
|
|
}
|
|
} else {
|
|
router.push({ name: "auth-login" });
|
|
api$1.warn(config.useString("pleaseLoginOrRegister"));
|
|
}
|
|
}
|
|
function openOption(id) {
|
|
optionPostId.value = id;
|
|
optionVisible.value = true;
|
|
}
|
|
function openComment(id, owner_id) {
|
|
commentPostId.value = id;
|
|
commentVisible.value = true;
|
|
ownerPostId.value = owner_id;
|
|
}
|
|
provide("ownerPostId", ownerPostId);
|
|
return (_ctx, _push, _parent, _attrs) => {
|
|
const _component_ClientOnly = __nuxt_component_0;
|
|
_push(`<div${ssrRenderAttrs(_attrs)}><div class="${ssrRenderClass(["z-20 fixed w-full top-0", !unref(config).isNightStore ? "bg-header-color" : "bg-header-color-dark "])}"><div class="px-4 flex items-center justify-between"><div class="flex gap-3 py-3 items-center">`);
|
|
_push(ssrRenderComponent(_component_ClientOnly, null, {}, _parent));
|
|
_push(`<div class="font-semibold">${ssrInterpolate(unref(config).sellerConfig?.store?.username)}</div></div></div></div><div class="pt-15 overflow-y-auto userPostScroll h-95vh pb-3rem scrollHome"><!--[-->`);
|
|
ssrRenderList(unref(userPostStore).posts, (post, index) => {
|
|
_push(`<div class="tg-item" style="${ssrRenderStyle({ transitionDelay: index * 50 + "ms" })}">`);
|
|
_push(ssrRenderComponent(Post, {
|
|
index,
|
|
post,
|
|
onOpenOption: openOption,
|
|
onOpenComment: openComment,
|
|
onHandleLike: handleLike,
|
|
onHandleSave: handleSave,
|
|
"scroll-save": "scrollPositionSeller",
|
|
"add-like-loading": addLikeLoading.value
|
|
}, null, _parent));
|
|
_push(`</div>`);
|
|
});
|
|
_push(`<!--]-->`);
|
|
if (unref(userPostStore).loading) {
|
|
_push(ssrRenderComponent(_sfc_main$1, null, null, _parent));
|
|
} else {
|
|
_push(`<!---->`);
|
|
}
|
|
_push(`<div style="${ssrRenderStyle(!unref(userPostStore).loading ? null : { display: "none" })}" class="w-full opacity-1 relative"> load </div></div>`);
|
|
_push(ssrRenderComponent(CommentAddEdit, {
|
|
id: commentPostId.value,
|
|
open: commentVisible.value,
|
|
"onUpdate:open": ($event) => commentVisible.value = $event,
|
|
onAddCommentId: addCommentId,
|
|
onDeleteCommentId: deleteCommentId
|
|
}, null, _parent));
|
|
_push(ssrRenderComponent(_sfc_main$2, {
|
|
id: optionPostId.value,
|
|
open: optionVisible.value,
|
|
"onUpdate:open": ($event) => optionVisible.value = $event
|
|
}, null, _parent));
|
|
_push(`</div>`);
|
|
};
|
|
}
|
|
});
|
|
const _sfc_setup = _sfc_main.setup;
|
|
_sfc_main.setup = (props, ctx) => {
|
|
const ssrContext = useSSRContext();
|
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("views/base/pages/user/userMain/posts/index.vue");
|
|
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
};
|
|
|
|
export { _sfc_main as _ };
|