import { Col, Row } from "antd";
import { Link } from "react-router-dom";
import { MaybeLink, PostWidget } from "./PostWidget";
import { MoodReadResponse, PostReadResponse } from "@newstackdev/iosdk-newgraph-client-js";
import { NLView } from "../types";
import { PremiumContent } from "./PremiumContent";
import { Spin } from "./Spin";
import { useActions, useAppState } from "../overmind";
import { useCallback, useEffect } from "react";
import FolderClosed from "./Icons/Folder/Closed";
import InfiniteScroll from "react-infinite-scroller";
import Title from "../Pages/Explore/Title";
const MAX_POSTS_TO_SHOW = 7;
export const TopFoldersGrid: NLView<{
mood: MoodReadResponse;
maxPosts?: number;
title: string | undefined;
noFolder?: boolean;
wrap?: boolean;
noFullWidth?: boolean;
blur?: boolean;
}> = ({ mood, maxPosts, title, noFolder, noFullWidth, wrap }) => {
const relevant = mood.posts?.slice(0, maxPosts) || [];
const postsList = [
...relevant,
..."."
.repeat(Math.max(MAX_POSTS_TO_SHOW - relevant?.length, 0))
.split("")
.map(() => ({} as PostReadResponse)),
];
const actions = useActions();
const state = useAppState();
const getPostsHandler = useCallback(
(page: number) => {
actions.api.mood.getPosts({ id: mood.id });
},
[mood],
);
// if (true) return <>{postsList.length}>;
return (
<>
{/* {JSON.stringify((postsList || [])[0].content)} */}
<>
{/* // folder */}
{!noFolder && (
{/* @ts-ignore */}
{mood.title}
)}
{/* // image */}
{!relevant?.length && Nothing here}
{window.location.pathname.includes("folder/") ? (
}
hasMore={state.lists.top.isNextPostsAvailable && state.lists.selectedUser.isNextPostsAvailable}
>
!state.auth.authenticated && window.scrollTo(0, 0)} className="nl-mood-grid-row">
{postsList?.map((p) => {
if (!p.id) return ;
return (
);
})}
) : (
postsList?.map((p) => {
if (!p.id) return ;
const topFolderLinkClickUrl = !p.id
? ""
: ((p.description || "").match(/^https:\/\/[^.]+\.newlife\.io(\/\S+)$/) || "")[1]
? ((p.description || "").match(/^https:\/\/[^.]+\.newlife\.io(\/\S+)$/) || "")[1] || ""
: !mood
? `/post/${p.id}`
: `/folder/${mood.id}/${p.id}`;
return (
);
})
)}
>
>
);
};
const TopFolders: NLView<{
maxItems?: number;
maxPostsToShow: number;
skipItems?: number;
title?: string;
posts?: string;
filterToSameNumberPosts?: boolean;
userMoods?: MoodReadResponse[];
enableScrollForMoreMoods?: boolean;
loadMoreMoodsHandler?: () => void;
randomizeMoods?: boolean;
}> = ({
maxItems,
title,
posts,
userMoods,
skipItems,
maxPostsToShow,
filterToSameNumberPosts,
enableScrollForMoreMoods = true,
randomizeMoods = true,
loadMoreMoodsHandler,
}) => {
const state = useAppState();
useEffect(() => {
actions.lists.resetMoodAndPostAvailability();
}, []);
const moods = userMoods ? userMoods : state.lists.top.moods.items || [];
// if (true)
// return (
// <>
// {posts?.map((p) => (
//
{JSON.stringify(p.id)}
// ))}
// >
// );
const actions = useActions();
maxItems = maxItems || 100;
let remapMoods: MoodReadResponse[] = [];
if (filterToSameNumberPosts) {
remapMoods = moods.filter((m) => m.posts?.slice(0, maxPostsToShow).length === maxPostsToShow);
} else remapMoods = moods;
const loadMoreHandler = useCallback(
(page) => {
if (loadMoreMoodsHandler) {
loadMoreMoodsHandler();
} else {
actions.lists.top.moods({ requestedPage: page + 1 });
}
},
[loadMoreMoodsHandler, actions.lists.top.moods],
);
return (
<>
{title === undefined && (
{/* */}
Explore folders
)}
{title ?
: ""}
}
>
{remapMoods?.slice(skipItems || 0, (skipItems || 0) + (maxItems || 3)).map((m, i) => (
{/**
* MAX_POSTS_TO_SHOW is necessary; otherwise, top folder will render all of the posts
* containing in the moods which will overload the DOM and the experience super laggy.
*/}
))}
>
);
};
export default TopFolders;