import { useEffect, useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import { useRobotContext } from 'src/pages/robot/robot.context';
import InfiniteScroll from 'react-infinite-scroll-component';
import { RootState } from 'src/redux/store';
import {
  NoItems,
  Dots,
  SearchSnippet,
  ContainerGradientText,
} from '../../components';
import useGetTweets from './useGetTweets';
import ActionBarCont from '../market/actionBarContainer';
import useSetActiveAddress from '../../hooks/useSetActiveAddress';
import { CID_TWEET } from 'src/constants/app';
import { useAdviser } from 'src/features/adviser/context';

const LOAD_COUNT = 10;

function Taverna() {
  const { address, isOwner } = useRobotContext();
  const { defaultAccount } = useSelector((state: RootState) => state.pocket);
  const { tweets, loadingTweets } = useGetTweets(address || null);
  const { addressActive } = useSetActiveAddress(defaultAccount);
  const [rankLink, setRankLink] = useState<string | null>();
  const [update, setUpdate] = useState(1);

  const [itemsToShow, setItemsToShow] = useState(20);

  const { setAdviser } = useAdviser();

  useEffect(() => {
    setAdviser(
      <>
        real feed <br /> no ad, no spam, no scam
      </>
    );
  }, [setAdviser]);

  useEffect(() => {
    setRankLink(null);
  }, [update]);

  async function onClickRank(key: string) {
    if (rankLink === key) {
      setRankLink(null);
    } else {
      setRankLink(key);
    }
  }

  // const d = new Date();

  const displayedPalettes = useMemo(
    () =>
      Object.keys(tweets)
        .sort((a, b) => {
          const x = Date.parse(tweets[a].time);
          const y = Date.parse(tweets[b].time);
          return y - x;
        })
        .slice(0, itemsToShow)
        .map((key) => {
          // let timeAgoInMS = 0;
          // const time = Date.parse(d) - Date.parse(tweets[key].time);
          // if (time > 0) {
          //   timeAgoInMS = time;
          // }
          return (
            <SearchSnippet
              key={key}
              cid={key}
              data={tweets[key]}
              onClickRank={onClickRank}
            />
            // <Pane
            //   position="relative"
            //   className="hover-rank"
            //   display="flex"
            //   alignItems="center"
            //   marginBottom="10px"
            //   key={`${key}_${i}`}
            // >
            //   {!mobile && (
            //     <Pane
            //       className="time-discussion rank-contentItem"
            //       position="absolute"
            //     >
            //       <Rank
            //         hash={key}
            //         rank="n/a"
            //         grade={{ from: 'n/a', to: 'n/a', value: 'n/a' }}
            //         onClick={() => onClickRank(key)}
            //       />
            //     </Pane>
            //   )}
            //   <ContentItem
            //     nodeIpfs={node}
            //     cid={key}
            //     item={tweets[key]}
            //     className="contentItem"
            //   />
            //   <Pane
            //     className="time-discussion rank-contentItem"
            //     position="absolute"
            //     right="0"
            //     fontSize={12}
            //     whiteSpace="nowrap"
            //     top="5px"
            //   >
            //     {timeSince(timeAgoInMS)} ago
            //   </Pane>
            // </Pane>
          );
        }),
    [itemsToShow, tweets]
  );

  if (loadingTweets) {
    return <Dots />;
  }

  function loadMore() {
    setItemsToShow((i) => i + LOAD_COUNT);
  }

  return (
    <>
      <ContainerGradientText>
        {/* <main className="block-body"> */}
        {/* <Pane
            width="90%"
            marginX="auto"
            marginY={0}
            display="flex"
            flexDirection="column"
          > */}

        <div className="container-contentItem" style={{ width: '100%' }}>
          <InfiniteScroll
            dataLength={itemsToShow}
            next={loadMore}
            // endMessage={<p>all loaded</p>}
            hasMore={Object.keys(tweets).length > itemsToShow}
            loader={<Dots />}
          >
            {Object.keys(tweets).length > 0 ? (
              displayedPalettes
            ) : (
              <NoItems text="No feeds" />
            )}
          </InfiniteScroll>
        </div>

        {/* </Pane> */}
        {/* </main> */}
      </ContainerGradientText>

      <div
        style={{
          position: 'fixed',
          left: 0,
          zIndex: 1,
        }}
      >
        {isOwner && (
          <ActionBarCont
            addressActive={addressActive}
            keywordHash={CID_TWEET}
            updateFunc={() => setUpdate(update + 1)}
            rankLink={rankLink}
            textBtn="Tweet"
          />
        )}
      </div>
    </>
  );
}

export default Taverna;

Synonyms

cyb/src/index.tsx
pussy-ts/src/index.tsx
bostrom.network/src/pages/Index.tsx
pussy-landing/src/pages/index.tsx
pussy.meme/src/pages/index.tsx
pussy-ts/src/containers/txs/index.tsx
pussy-ts/src/containers/mint/index.tsx
cyb/src/containers/mint/index.tsx
pussy-ts/src/components/ButtonSwap/index.tsx
pussy-ts/src/components/denom/index.tsx
cyb/src/containers/Objects/index.tsx
cyb/src/components/btnGrd/index.tsx
pussy-ts/src/components/Select/index.tsx
cyb/src/components/actionBar/index.tsx
pussy-ts/src/components/BandwidthBar/index.tsx
cyb/src/components/Select/index.tsx
pussy-ts/src/containers/portal/index.tsx
pussy-ts/src/components/btnGrd/index.tsx
cyb/src/components/TextMarkdown/index.tsx
cyb/src/containers/energy/index.tsx
pussy-ts/src/components/MainContainer/index.tsx
pussy-ts/src/components/actionBar/index.tsx
cyb/src/containers/portal/index.tsx
cyb/src/components/ButtonSwap/index.tsx
cyb/src/containers/nebula/index.tsx
pussy-ts/src/components/DonutChart/index.tsx
cyb/src/components/DonutChart/index.tsx
pussy-ts/src/containers/nebula/index.tsx
cyb/src/components/BandwidthBar/index.tsx
pussy-ts/src/containers/energy/index.tsx
cyb/src/components/denom/index.tsx
cyb/src/containers/sigma/index.tsx
cyb/src/components/Input/index.tsx
pussy-ts/src/containers/sigma/index.tsx
pussy-ts/src/components/Input/index.tsx
cyb/src/containers/blok/index.tsx
cyb/src/components/PDF/index.tsx
cyb/src/containers/txs/index.tsx
cyb/src/containers/taverna/index.tsx
cyb/src/components/MainContainer/index.tsx
pussy-ts/src/components/TextMarkdown/index.tsx
pussy-ts/src/components/PDF/index.tsx
cyb/src/containers/portal/citizenship/index.tsx
pussy-landing/src/components/xp/btnGrd/index.tsx
cyb/src/containers/portal/pasport/index.tsx
pussy-landing/src/components/xp/stars/index.tsx
cyb/src/components/buttons/ButtonIcon/index.tsx
cyb/src/containers/wasm/codes/index.tsx
pussy-ts/src/features/ipfs/Drive/index.tsx
pussy-ts/src/containers/portal/gift/index.tsx
pussy-ts/src/features/ipfs/ipfsSettings/index.tsx
pussy-ts/src/components/buttons/ButtonIcon/index.tsx
pussy-ts/src/containers/portal/release/index.tsx
cyb/src/containers/portal/release/index.tsx
cyb/src/features/ipfs/Drive/index.tsx
pussy-ts/src/containers/portal/pasport/index.tsx
cyb/src/features/ipfs/ipfsSettings/index.tsx
pussy-ts/src/containers/portal/citizenship/index.tsx
cyb/src/containers/portal/gift/index.tsx
cyb/src/components/contentIpfs/component/gateway/index.tsx
pussy-ts/src/containers/portal/components/ReleaseStatus/index.tsx
pussy-ts/src/components/contentIpfs/component/gateway/index.tsx
pussy-ts/src/containers/sigma/components/CardPassport/index.tsx
cyb/src/containers/sigma/components/CardPassport/index.tsx
cyb/src/components/contentIpfs/component/img/index.tsx
pussy-ts/src/components/contentIpfs/component/img/index.tsx
cyb/src/containers/portal/components/ActionBar/index.tsx
pussy-ts/src/components/contentIpfs/component/link/index.tsx
cyb/src/containers/portal/components/ReleaseStatus/index.tsx
cyb/src/containers/portal/components/stars/index.tsx
pussy-ts/src/containers/portal/components/stars/index.tsx
cyb/src/components/contentIpfs/component/link/index.tsx
pussy-ts/src/containers/sigma/components/cardUi/TitleCard/index.tsx
cyb/src/containers/sigma/components/cardUi/TitleCard/index.tsx
cyb/src/containers/sigma/components/cardUi/RowBalancesDetails/index.tsx
pussy-ts/src/containers/sigma/components/cardUi/RowBalancesDetails/index.tsx

Neighbours