112 lines
4.6 KiB
JavaScript
112 lines
4.6 KiB
JavaScript
import { l as loadGray, _ as __nuxt_component_0 } from './gray-Bd8mWW-o.mjs';
|
|
import { u as useRouter$1, a as useConfigStore, m as useIntersectionObserver, e as loading, b as useUserStore } from './server.mjs';
|
|
import { defineComponent, ref, resolveDirective, mergeProps, unref, useSSRContext } from 'vue';
|
|
import { ssrRenderAttrs, ssrRenderList, ssrInterpolate, ssrGetDirectiveProps, ssrRenderAttr, ssrRenderStyle, ssrRenderComponent } from 'vue/server-renderer';
|
|
import { defineStore } from 'pinia';
|
|
import { g as getUserSaved } from './save-DsCeVVYe.mjs';
|
|
|
|
const useSavedPostStore = defineStore("saved", () => {
|
|
const savedPosts = ref([]);
|
|
const endPage = ref(false);
|
|
useConfigStore();
|
|
const currentPage = ref(0);
|
|
const limit = ref(12);
|
|
const total = ref(0);
|
|
const user = useUserStore();
|
|
async function loadPosts() {
|
|
try {
|
|
if (!endPage.value) {
|
|
loading.value = true;
|
|
const res = await getUserSaved(user.user?.id, ++currentPage.value, limit.value);
|
|
if (res?.data?.length < limit.value)
|
|
endPage.value = true;
|
|
const products = res?.data.map((x) => x.products);
|
|
savedPosts.value.push(...products ?? []);
|
|
total.value = res?.count ?? 0;
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
function reset() {
|
|
currentPage.value = 0;
|
|
savedPosts.value = [];
|
|
total.value = 0;
|
|
endPage.value = false;
|
|
}
|
|
return {
|
|
loadPosts,
|
|
savedPosts,
|
|
reset
|
|
};
|
|
});
|
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
__name: "SavedList",
|
|
__ssrInlineRender: true,
|
|
setup(__props) {
|
|
useRouter$1();
|
|
const config = useConfigStore();
|
|
const userSavedPost = useSavedPostStore();
|
|
const videoThumbnails = ref({});
|
|
const observer = ref();
|
|
useIntersectionObserver(observer, ([{ isIntersecting }]) => {
|
|
if (isIntersecting) {
|
|
setTimeout(() => {
|
|
userSavedPost.loadPosts();
|
|
}, 100);
|
|
}
|
|
});
|
|
return (_ctx, _push, _parent, _attrs) => {
|
|
const _component_SquarePostSkeleton = __nuxt_component_0;
|
|
const _directive_lazy = resolveDirective("lazy");
|
|
let _temp0;
|
|
_push(`<div${ssrRenderAttrs(mergeProps({
|
|
class: ["flex flex-col gap-2 min-h-50vh", unref(userSavedPost).savedPosts?.length > 0 ? "" : "justify-center"]
|
|
}, _attrs))}>`);
|
|
if (!("loading" in _ctx ? _ctx.loading : unref(loading))) {
|
|
_push(`<!--[--><div class="w-full grid grid-cols-3 gap-2px"><!--[-->`);
|
|
ssrRenderList(unref(userSavedPost).savedPosts, (post, i) => {
|
|
_push(`<div class="w-full aspect-square relative">`);
|
|
if (post.files?.length) {
|
|
_push(`<!--[-->`);
|
|
if (post.files[0]?.type === "image") {
|
|
_push(`<img${ssrRenderAttrs(_temp0 = mergeProps({
|
|
class: "w-full h-full object-cover",
|
|
alt: "Post Image"
|
|
}, ssrGetDirectiveProps(_ctx, _directive_lazy, { src: unref(config).useDataStorage(post.files[0].url), loading: unref(loadGray), error: unref(loadGray) })))}>${"textContent" in _temp0 ? ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ""}`);
|
|
} else if (post.files[0]?.type === "video") {
|
|
_push(`<div class="relative w-full h-full"><video${ssrRenderAttr("src", post.files[0]?.url)} class="hidden"></video><img${ssrRenderAttr("src", videoThumbnails.value[post.files[0]?.url])} class="w-full h-full object-cover" alt="Video Thumbnail"><div class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-30"><svg class="w-12 h-12 text-white" fill="currentColor" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"></path></svg></div></div>`);
|
|
} else {
|
|
_push(`<!---->`);
|
|
}
|
|
_push(`<!--]-->`);
|
|
} else {
|
|
_push(`<!---->`);
|
|
}
|
|
_push(`</div>`);
|
|
});
|
|
_push(`<!--]--></div><div class="w-full opacity-0 relative" style="${ssrRenderStyle(!("loading" in _ctx ? _ctx.loading : unref(loading)) ? null : { display: "none" })}"> load </div>`);
|
|
if ("loading" in _ctx ? _ctx.loading : unref(loading)) {
|
|
_push(ssrRenderComponent(_component_SquarePostSkeleton, null, null, _parent));
|
|
} else {
|
|
_push(`<!---->`);
|
|
}
|
|
_push(`<!--]-->`);
|
|
} else {
|
|
_push(`<!---->`);
|
|
}
|
|
_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/statisticsList/components/SavedList.vue");
|
|
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
};
|
|
|
|
export { _sfc_main as _ };
|