Files
5chan/src/components/views/Home.jsx
T

232 lines
9.5 KiB
React
Raw Normal View History

import React, { Fragment, useEffect, useRef, useState } from 'react';
2023-04-21 10:47:39 +02:00
import { Helmet } from 'react-helmet-async';
2023-06-22 18:12:15 +02:00
import { useAccount, useBufferedFeeds } from '@plebbit/plebbit-react-hooks';
2023-04-01 15:09:04 +02:00
import { Link, useNavigate } from 'react-router-dom';
2023-05-24 12:15:43 +02:00
import { Container, Header, Logo, Page, Search, About, AboutTitle, AboutContent, Boards, BoardsTitle, BoardsContent, Footer } from '../styled/views/Home.styled';
import BoardAvatar from '../BoardAvatar';
2023-05-06 15:40:30 +02:00
import OfflineIndicator from '../OfflineIndicator';
import CreateBoardModal from '../modals/CreateBoardModal';
2023-06-16 14:42:23 +02:00
import useGeneralStore from '../../hooks/stores/useGeneralStore';
2023-05-05 18:28:07 +02:00
import packageJson from '../../../package.json'
import { Tooltip } from 'react-tooltip';
2023-04-24 20:00:11 +00:00
const {version} = packageJson
2023-05-24 22:30:49 +00:00
// show commit ref on netlify to know which commit is being served for debugging
const commitRef = process?.env?.REACT_APP_COMMIT_REF ? ` ${process.env.REACT_APP_COMMIT_REF.slice(0, 7)}` : ''
2023-03-13 14:29:34 +01:00
2023-01-31 23:08:57 +01:00
2023-03-21 11:17:54 +01:00
const Home = () => {
2023-06-16 14:42:23 +02:00
const {
2023-05-27 12:55:16 +02:00
bodyStyle, setBodyStyle,
2023-03-21 11:17:54 +01:00
defaultSubplebbits,
setSelectedAddress,
2023-05-27 12:55:16 +02:00
selectedStyle, setSelectedStyle,
2023-03-21 11:17:54 +01:00
setSelectedTitle
2023-04-08 13:27:17 +02:00
} = useGeneralStore(state => state);
2023-02-13 12:05:10 +01:00
2023-05-03 14:16:00 +02:00
const account = useAccount();
2023-04-01 15:09:04 +02:00
const navigate = useNavigate();
2023-05-27 12:55:16 +02:00
const inputRef = useRef(null);
const prevStyle = useRef(selectedStyle);
const prevBodyStyle = useRef(bodyStyle);
2023-04-01 15:09:04 +02:00
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
2023-06-22 18:12:15 +02:00
// preload default subs and subscriptions
useBufferedFeeds({
feedsOptions: [
{subplebbitAddresses: defaultSubplebbits.map(
(subplebbit) => subplebbit.address
), sortType: 'active'},
{subplebbitAddresses: account?.subscriptions, sortType: 'active'}
]
});
2023-03-21 11:17:54 +01:00
// prevent dark mode
2023-02-13 12:05:10 +01:00
useEffect(() => {
2023-05-27 12:55:16 +02:00
const currentPrevStyle = prevStyle.current;
const currentPrevBodyStyle = prevBodyStyle.current;
2023-02-13 12:05:10 +01:00
setBodyStyle({
2023-04-29 12:47:30 +02:00
background: "#ffe url(assets/fade.png) top repeat-x",
2023-02-13 12:05:10 +01:00
color: "maroon",
fontFamily: "Helvetica, Arial, sans-serif"
});
setSelectedStyle("Yotsuba");
2023-05-27 12:55:16 +02:00
return () => {
setSelectedStyle(currentPrevStyle);
setBodyStyle(currentPrevBodyStyle);
};
2023-02-13 12:05:10 +01:00
}, [setBodyStyle, setSelectedStyle]);
2023-02-09 19:08:15 +01:00
2023-02-04 11:35:46 +01:00
2023-02-02 21:58:02 +01:00
return (
2023-04-21 10:47:39 +02:00
<>
<CreateBoardModal
selectedStyle={selectedStyle}
isOpen={isCreateBoardOpen}
closeModal={() => setIsCreateBoardOpen(false)} />
2023-04-21 10:47:39 +02:00
<Helmet>
<title>plebchan</title>
</Helmet>
<Container>
2023-05-05 18:28:07 +02:00
<Tooltip id="tooltip" className="tooltip" />
2023-04-21 10:47:39 +02:00
<Header>
<Logo>
<Link to="/">
2023-04-29 12:47:30 +02:00
<img alt="plebchan" src="assets/logo/logo-transparent.png" />
2023-04-21 10:47:39 +02:00
</Link>
</Logo>
</Header>
<Page>
<Search>
<input type="text" placeholder='"board.eth" or "12D3KooW..."' ref={inputRef} onKeyDown={
(event) => {
if (event.key === "Enter") {
event.preventDefault();
const address = inputRef.current.value;
if (address) {
setSelectedAddress(address);
navigate(`/p/${address}`)
}
}
}} />
<input type="submit" value="Search" onClick={
() => {
2023-04-01 15:09:04 +02:00
const address = inputRef.current.value;
if (address) {
setSelectedAddress(address);
2023-04-08 22:30:44 +02:00
navigate(`/p/${address}`)
2023-04-01 15:09:04 +02:00
}
}
2023-04-21 10:47:39 +02:00
} />
</Search>
<About>
<AboutTitle>
<h2>What is plebchan?</h2>
</AboutTitle>
<AboutContent>
<div id="content">
2023-06-28 09:31:59 +02:00
<p>Plebchan is a serverless, adminless, decentralized 4chan alternative that uses the <a href="https://plebbit.com" target="_blank" rel="noreferrer">plebbit protocol</a>. Users do not need to register an account before participating in a community; anyone can post comments, share media links, and <button
2023-04-30 17:37:19 +02:00
style={{all: 'unset', cursor: 'pointer'}}
onClick={() =>{
window.electron && window.electron.isElectron ? (
setIsCreateBoardOpen(true)
) : (
alert(
2023-07-20 10:00:58 +02:00
'You can create a board with the desktop version of plebchan:\nhttps://github.com/plebbit/plebchan/releases/latest\n\nIf you are comfortable with the command line, use plebbit-cli:\nhttps://github.com/plebbit/plebbit-cli\n\n'
)
)
}}
2023-05-10 18:00:04 +02:00
>create a board</button>. All the content is just text, and plebchan's speed depends on how many users are <a href="https://github.com/plebbit/whitepaper/blob/master/contribute.md" target="_blank" rel="noreferrer">seeding</a>. Search for any board address above, or feel free to click on a popular board below that interests you and jump right in! </p>
2023-04-21 10:47:39 +02:00
<br />
2023-06-28 09:31:59 +02:00
<p>There are no global rules, each board is completely independent and its owner decides how/if it should be moderated.</p>
2023-04-21 10:47:39 +02:00
</div>
</AboutContent>
</About>
2023-06-17 20:24:38 +02:00
{account?.subscriptions?.length > 0 ? (
2023-05-03 15:47:00 +02:00
<Boards>
2023-05-03 14:16:00 +02:00
<BoardsTitle>
2023-05-07 17:29:37 +02:00
<h2>Subscriptions</h2>
2023-05-03 14:16:00 +02:00
</BoardsTitle>
<BoardsContent id="subscriptions">
<h3 style={{textDecoration: 'underline', display: 'inline'}}>
2023-05-03 15:47:00 +02:00
You have subscribed to {account?.subscriptions?.length} board{account?.subscriptions?.length > 1 ? "s" : null}
</h3>&nbsp;
<Link to="/p/subscriptions" id="view-all" onClick={()=> {window.scrollTo(0, 0)}}>[view all]</Link>
2023-05-03 14:16:00 +02:00
<br />
2023-05-03 15:47:00 +02:00
{account?.subscriptions?.map((subscription, index) => (
2023-05-27 17:21:13 +02:00
<Fragment key={`frag-${index}`}>
<Link key={`sub-${index}`} className="boardlink"
onClick={()=> {window.scrollTo(0, 0)}}
to={`/p/${subscription}`}>
2023-05-03 15:47:00 +02:00
<br id="mobile-br" />
2023-05-06 15:40:30 +02:00
{subscription}&nbsp;
2023-05-15 14:07:14 +02:00
</Link>
<OfflineIndicator
2023-05-27 17:21:13 +02:00
key={`offline-${index}`}
2023-05-06 15:40:30 +02:00
address={subscription}
2023-05-29 18:30:09 +02:00
className="disconnected"
2023-05-29 12:20:45 +02:00
isText={true} />
2023-05-27 17:21:13 +02:00
<br key={`br-${index}`} />
</Fragment>
2023-05-03 14:16:00 +02:00
))}
2023-05-03 15:47:00 +02:00
<br id="mobile-br" />
2023-05-03 14:16:00 +02:00
</BoardsContent>
</Boards>
) : null}
2023-04-21 10:47:39 +02:00
<Boards>
<BoardsTitle>
2023-05-03 14:16:00 +02:00
<h2>Popular Boards</h2>
2023-04-21 10:47:39 +02:00
</BoardsTitle>
<BoardsContent>
2023-05-27 17:21:13 +02:00
{defaultSubplebbits.map((subplebbit, index) => (
<div className="board" key={`board-${index}`}>
<div className="board-title" key="board-title">
2023-04-21 10:47:39 +02:00
{subplebbit.title ? subplebbit.title : <span style={{userSelect: "none"}}>&nbsp;</span>}
</div>
2023-05-27 17:21:13 +02:00
<div className="board-avatar-container" key="board-avatar-container">
<Link to={`/p/${subplebbit.address}`} key="link" onClick={() => {
2023-05-15 14:07:14 +02:00
setSelectedTitle(subplebbit.title);
setSelectedAddress(subplebbit.address);
window.scrollTo(0, 0);
}} >
2023-05-27 17:21:13 +02:00
<BoardAvatar key="baordavatar" address={subplebbit.address} />
2023-05-15 14:07:14 +02:00
</Link>
<OfflineIndicator
address={subplebbit.address}
className="offline-indicator"
2023-05-27 17:21:13 +02:00
tooltipPlace="top"
key="oi2"/>
2023-05-15 14:07:14 +02:00
</div>
2023-05-27 17:21:13 +02:00
<div className="board-text" key="bt">
<b key="b">{subplebbit.address}</b>
2023-04-21 10:47:39 +02:00
</div>
2023-04-01 14:51:07 +02:00
</div>
2023-04-21 10:47:39 +02:00
))}
</BoardsContent>
</Boards>
</Page>
<Footer>
<ul>
<li className="fill"></li>
<li className="first">
2023-05-20 15:39:51 +02:00
<a href="https://etherscan.io/token/0xEA81DaB2e0EcBc6B5c4172DE4c22B6Ef6E55Bd8f" target="_blank" rel="noopener noreferrer">Token</a>
2023-04-21 10:47:39 +02:00
</li>
<li>
<a href="https://gitcoin.co/grants/5515/plebbit-a-serverless-adminless-decentralized-redd" target="_blank" rel="noopener noreferrer">Donate</a>
</li>
<li>
2023-05-10 18:00:04 +02:00
<a href="https://github.com/plebbit/whitepaper/discussions/2" target="_blank" rel="noopener noreferrer">Whitepaper</a>
2023-04-21 10:47:39 +02:00
</li>
<li>
2023-05-10 18:00:04 +02:00
<a href="https://github.com/plebbit/plebchan" target="_blank" rel="noopener noreferrer">GitHub</a>
2023-04-21 10:47:39 +02:00
</li>
<li>
<a href="https://matrix.to/#/#plebbit:plebbitchat.org" target="_blank" rel="noopener noreferrer">Matrix</a>
</li>
<li>
<a href="https://t.me/plebbit" target="_blank" rel="noopener noreferrer">Telegram</a>
</li>
<li>
2023-05-10 18:00:04 +02:00
<a href="https://twitter.com/plebchan_eth" target="_blank" rel="noopener noreferrer">Twitter</a>
2023-04-21 10:47:39 +02:00
</li>
<li>
<a href="https://discord.gg/E7ejphwzGW" target="_blank" rel="noopener noreferrer">Discord</a>
</li>
</ul>
</Footer>
2023-04-22 13:11:42 +02:00
<div style={{
textAlign: "center",
fontSize: "11px",
2023-04-23 08:43:53 +02:00
marginBottom: "2em",
2023-04-22 13:11:42 +02:00
}}>
2023-05-24 22:30:49 +00:00
plebchan v{version}{commitRef}. GPL-2.0
2023-04-22 13:11:42 +02:00
</div>
2023-04-21 10:47:39 +02:00
</Container>
</>
2023-02-02 21:58:02 +01:00
)
};
2023-01-31 23:08:57 +01:00
export default Home;