145 lines
6.7 KiB
JavaScript
145 lines
6.7 KiB
JavaScript
import { defineComponent, computed, ref, withAsyncContext, unref, useSSRContext } from 'vue';
|
|
import { ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrInterpolate, ssrRenderList, ssrRenderStyle } from 'vue/server-renderer';
|
|
import { B as BasicIconOld } from './BasicIconOld-I4c2ShMu.mjs';
|
|
import { u as useRouter$1, a as useConfigStore, b as useUserStore, n as useIntersectionObserver, o as getToken, e as api$1 } from './server.mjs';
|
|
import { _ as _sfc_main$2, a as _sfc_main$1, b as _sfc_main$3, d as deletePostLike, c as createPostLike } from './CommentAddEdit-DIzvwqEQ.mjs';
|
|
import { u as useUserPostStore } from './userPostsStore-CTOjnW_T.mjs';
|
|
import { d as deleteSave, c as createSave } from './save-kY8A0w-Z.mjs';
|
|
import { _ as _sfc_main$4 } from './moreOptionProduct-DIWh2yKL.mjs';
|
|
import { u as useAsyncData } from './asyncData-C9E5x-0d.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 addLikeLoading = ref(false);
|
|
const userPostStore = useUserPostStore();
|
|
computed(() => router.currentRoute.value.query.target || null);
|
|
function handleLike(isLiked, id) {
|
|
var _a, _b, _c, _d, _e, _f;
|
|
try {
|
|
addLikeLoading.value = true;
|
|
if (getToken()) {
|
|
if (isLiked) {
|
|
deletePostLike(id);
|
|
const index = (_a = userPostStore.posts) == null ? void 0 : _a.findIndex((x) => x.id === id);
|
|
(_d = userPostStore.posts[index]) == null ? void 0 : _d.likes.splice((_c = (_b = userPostStore.posts[index]) == null ? void 0 : _b.likes) == null ? void 0 : _c.findIndex((y) => y.user_id === user.user.id));
|
|
} else {
|
|
createPostLike(id);
|
|
const index = (_e = userPostStore.posts) == null ? void 0 : _e.findIndex((x) => x.id === id);
|
|
(_f = userPostStore.posts[index]) == null ? void 0 : _f.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;
|
|
}
|
|
}
|
|
const observer = ref();
|
|
useIntersectionObserver(observer, async ([{ isIntersecting }]) => {
|
|
if (isIntersecting && !userPostStore.loading && !userPostStore.endPage) {
|
|
const nextPage = userPostStore.currentPage + 1;
|
|
console.log(userPostStore.endPage, nextPage, userPostStore.currentPage);
|
|
const data2 = await userPostStore.loadPosts(userId.value, nextPage);
|
|
userPostStore.loadStateNextPage(data2);
|
|
}
|
|
});
|
|
const { data } = ([__temp, __restore] = withAsyncContext(async () => useAsyncData("productPostMainSeller", async () => {
|
|
return await userPostStore.loadPosts(userId.value, 1);
|
|
})), __temp = await __temp, __restore(), __temp);
|
|
function handleSave(isSaved, id) {
|
|
var _a, _b, _c, _d, _e, _f;
|
|
if (getToken()) {
|
|
if (isSaved) {
|
|
deleteSave(id);
|
|
const index = (_a = userPostStore.posts) == null ? void 0 : _a.findIndex((x) => x.id === id);
|
|
(_d = userPostStore.posts[index]) == null ? void 0 : _d.saved.splice((_c = (_b = userPostStore.posts[index]) == null ? void 0 : _b.saved) == null ? void 0 : _c.findIndex((y) => y.user_id === user.user.id));
|
|
} else {
|
|
createSave(id);
|
|
const index = (_e = userPostStore.posts) == null ? void 0 : _e.findIndex((x) => x.id === id);
|
|
(_f = userPostStore.posts[index]) == null ? void 0 : _f.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) {
|
|
commentPostId.value = id;
|
|
commentVisible.value = true;
|
|
}
|
|
return (_ctx, _push, _parent, _attrs) => {
|
|
var _a, _b;
|
|
_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-5 py-3">`);
|
|
_push(ssrRenderComponent(BasicIconOld, {
|
|
icon: unref(config).isRTL ? "vuesax-linear:arrow-right" : "vuesax-linear:arrow-left",
|
|
onClick: ($event) => unref(router).back()
|
|
}, null, _parent));
|
|
_push(`<div class="font-semibold">${ssrInterpolate((_b = (_a = unref(config).sellerConfig) == null ? void 0 : _a.store) == null ? void 0 : _b.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(ssrRenderComponent(_sfc_main$2, {
|
|
onOpenOption: openOption,
|
|
onOpenComment: openComment,
|
|
onHandleLike: handleLike,
|
|
onHandleSave: handleSave,
|
|
index,
|
|
post,
|
|
key: index,
|
|
"scroll-save": "scrollPositionSeller",
|
|
"add-like-loading": addLikeLoading.value
|
|
}, null, _parent));
|
|
});
|
|
_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-0 relative"> load </div></div>`);
|
|
_push(ssrRenderComponent(_sfc_main$3, {
|
|
id: commentPostId.value,
|
|
open: commentVisible.value,
|
|
"onUpdate:open": ($event) => commentVisible.value = $event
|
|
}, null, _parent));
|
|
_push(ssrRenderComponent(_sfc_main$4, {
|
|
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 _ };
|
|
//# sourceMappingURL=index-DiCaPauN.mjs.map
|