import { Col } from "antd"; import { ContentImage } from "./Image"; import { ItemGrid } from "./ItemGrid"; import { Link } from "react-router-dom"; import { NLView } from "../types"; import { PostReadResponse } from "@newstackdev/iosdk-newgraph-client-js"; import { Row } from "antd-latest"; import { SpotlightGrid } from "./Spotlights"; import { fischerYates } from "../utils/random"; import { useActions, useAppState } from "../overmind"; import { useEffect, useRef, useState } from "react"; import Title from "../Pages/Explore/Title"; const TopHashtags: NLView<{ maxItems?: number; maxPostsToShow?: number; skipItems?: number; title?: string; posts?: string; }> = ({ maxItems, title, posts, skipItems, maxPostsToShow }) => { const state = useAppState(); const actions = useActions(); const [tagNames, setTagNames] = useState([] as string[]); const [tagImages, setTagImages] = useState([] as string[]); const items = useRef(state.lists.search.posts.results?.value || []).current; maxItems = maxItems || 100; useEffect(() => { actions.lists.searchPosts({ tags: "fashion, art, architecture, hat", }); }, []); const suggestedTagsSources = fischerYates(items, 8) || []; useEffect(() => { const tagsInSources = items .filter(Boolean) .map((p) => (p.tags || [])?.map((t) => t.value)) .reduce((r, c) => [...r, ...c], []); const ts = fischerYates(tagsInSources); setTagNames(ts); const tagsWithPics = suggestedTagsSources .filter(Boolean) .filter((p) => !!p.tags?.length) .map((p) => ({ value: fischerYates(p.tags, 1).values, contentUrl: p.contentUrl, })); const tp = fischerYates(tagsWithPics, 6); setTagImages(tp); }, [items]); const maybeLoadMore = () => { actions.lists.searchPosts({ tags: "fashion, art, architecture, hat", }); }; return (
Explore top hashtags
{tagNames ? tagNames[index] : ""}