Files
5chan/src/components/Board.jsx
T

251 lines
9.2 KiB
React
Raw Normal View History

2023-02-04 22:10:54 +01:00
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
2023-02-07 13:23:14 +01:00
import { Container, NavBar, Header, Break, PostForm, TopBar, BoardForm } from './styles/Board.styled';
2023-02-04 22:10:54 +01:00
import { useFeed } from '@plebbit/plebbit-react-hooks';
2023-02-08 21:49:36 +01:00
import ImageBanner from './ImageBanner';
2023-01-31 23:08:57 +01:00
2023-02-05 18:44:16 +01:00
2023-02-08 21:49:36 +01:00
const Board = ({ setBodyStyle }) => {
2023-02-04 22:10:54 +01:00
const [defaultSubplebbits, setDefaultSubplebbits] = useState([]);
2023-02-07 22:55:00 +01:00
const [selectedTitle, setSelectedTitle] = useState("");
const [selectedAddress, setSelectedAddress] = useState("");
2023-02-08 21:49:36 +01:00
const [selectedStyle, setSelectedStyle] = useState("Yotsuba");
2023-02-04 22:10:54 +01:00
useEffect(() => {
let didCancel = false;
fetch(
"https://raw.githubusercontent.com/plebbit/temporary-default-subplebbits/master/subplebbits.json",
{ cache: "no-cache" }
)
.then((res) => res.json())
.then(res => {
if (!didCancel) {
setDefaultSubplebbits(res);
}
});
return () => {
didCancel = true;
};
}, []);
2023-02-07 22:55:00 +01:00
const handleClick = (title, address) => {
setSelectedTitle(title);
setSelectedAddress(address);
};
2023-02-08 21:49:36 +01:00
const handleStyleChange = (event) => {
switch (event.target.value) {
case "Yotsuba":
setBodyStyle({
background: "#ffe url(/fade.png) top repeat-x",
color: "maroon",
fontFamily: "Arial, Helvetica, sans-serif"
});
setSelectedStyle("Yotsuba");
break;
case "Yotsuba B":
setBodyStyle({
background: "#eef2ff url(/fade-blue.png) top center repeat-x",
color: "#000",
fontFamily: "Arial, Helvetica, sans-serif"
});
setSelectedStyle("Yotsuba B");
break;
case "Futaba":
setBodyStyle({
background: "#ffe",
color: "maroon",
fontFamily: "times new roman, serif"
});
setSelectedStyle("Futaba");
break;
case "Burichan":
setBodyStyle({
background: "#eef2ff",
color: "#000",
fontFamily: "times new roman, serif"
});
setSelectedStyle("Burichan");
break;
case "Tomorrow":
setBodyStyle({
background: "#1d1f21 none",
color: "#c5c8c6",
fontFamily: "Arial, Helvetica, sans-serif"
});
setSelectedStyle("Tomorrow");
break;
case "Photon":
setBodyStyle({
background: "#eee none",
color: "#333",
fontFamily: "Arial, Helvetica, sans-serif"
});
setSelectedStyle("Photon");
break;
default:
setBodyStyle({
background: "#ffe url(/fade.png) top repeat-x",
color: "maroon",
fontFamily: "Arial, Helvetica, sans-serif"
});
setSelectedStyle("Yotsuba");
}
}
// eslint-disable-next-line
2023-02-07 22:55:00 +01:00
const {feed, hasMore, loadMore} = useFeed([`${selectedAddress}`], 'new');
2023-02-08 21:49:36 +01:00
// console.log(feed);
2023-02-07 22:55:00 +01:00
2023-02-02 21:58:02 +01:00
return (
2023-02-04 22:10:54 +01:00
<Container>
2023-02-08 21:49:36 +01:00
<NavBar selectedStyle={selectedStyle}>
2023-02-04 22:10:54 +01:00
<>
{defaultSubplebbits.map(subplebbit => (
2023-02-07 22:55:00 +01:00
<span className="boardList" key={subplebbit.address}>
[
<a href="#" onClick={() => handleClick(subplebbit.title, subplebbit.address)}
>{subplebbit.title}</a>
2023-02-04 22:10:54 +01:00
]&nbsp;
</span>
))}
<span className="nav">[
2023-02-08 21:49:36 +01:00
<Link to="/" onClick={() => handleStyleChange({target: {value: "Yotsuba"}}
)}>Home</Link>]&nbsp;
2023-02-04 22:10:54 +01:00
</span>
</>
</NavBar>
2023-02-08 21:49:36 +01:00
<Header selectedStyle={selectedStyle}>
2023-02-04 22:10:54 +01:00
<>
<div className="banner">
2023-02-05 18:44:16 +01:00
<ImageBanner />
2023-02-04 22:10:54 +01:00
</div>
2023-02-07 13:23:14 +01:00
<>
2023-02-07 22:55:00 +01:00
<div className="board-title">{selectedTitle}</div>
<div className="board-address">p/{selectedAddress}</div>
2023-02-07 13:23:14 +01:00
</>
2023-02-04 22:10:54 +01:00
</>
</Header>
2023-02-08 21:49:36 +01:00
<Break selectedStyle={selectedStyle} />
<PostForm selectedStyle={selectedStyle} name="post" action="" method="post" enctype="multipart/form-data">
2023-02-05 18:44:16 +01:00
<div id="post-form-link">
2023-02-04 22:10:54 +01:00
[
<a href="#">Start a New Thread</a>
]
</div>
2023-02-05 18:44:16 +01:00
<table id="post-form"></table>
2023-02-04 22:10:54 +01:00
</PostForm>
2023-02-08 21:49:36 +01:00
<TopBar selectedStyle={selectedStyle}>
2023-02-05 18:44:16 +01:00
<hr />
2023-02-07 13:23:14 +01:00
<span className="style-changer">
Style:
 
2023-02-08 21:49:36 +01:00
<select id="style-selector" onChange={handleStyleChange}>
<option value="Yotsuba">Yotsuba</option>
2023-02-07 13:23:14 +01:00
<option value="Yotsuba B">Yotsuba B</option>
2023-02-08 21:49:36 +01:00
<option value="Futaba">Futaba</option>
2023-02-07 13:23:14 +01:00
<option value="Burichan">Burichan</option>
<option value="Tomorrow">Tomorrow</option>
<option value="Photon">Photon</option>
</select>
</span>
2023-02-05 18:44:16 +01:00
<hr />
</TopBar>
2023-02-08 21:49:36 +01:00
<BoardForm selectedStyle={selectedStyle} id="board-form" name="board-form" action="" method="post">
2023-02-05 22:15:38 +01:00
<div className="board">
2023-02-08 11:02:02 +01:00
{feed.map(object => {
const thread = object;
const { replies: { pages: { topAll: { comments } } } } = object;
return (
2023-02-07 22:55:00 +01:00
<>
2023-02-08 11:02:02 +01:00
<div key={`t-${thread.cid}`} className="thread">
<div key={`c-${thread.pc}`} className="post-container op-container">
<div key={`po-${thread.cid}`} className="post op">
<div key={`pi-${thread.cid}`} className="post-info">
&nbsp;
<span key={`nb-${thread.cid}`} className="name-block">
<span key={`n-${thread.cid}`} className="name">{thread.author.displayName}</span>
&nbsp;
<span key={`pa-${thread.cid}`} className="poster-address">
(User: {thread.author.address})
2023-02-07 22:55:00 +01:00
</span>
2023-02-05 22:15:38 +01:00
</span>
2023-02-08 11:02:02 +01:00
&nbsp;
<span key={`dt-${thread.cid}`} className="date-time" data-utc="data">2 weeks ago</span>
&nbsp;
<span key={`pn-${thread.cid}`} className="post-number">
<a key={`pl1-${thread.cid}`} href="post-link" title="Link to this post">No.</a>
<a key={`pl2-${thread.cid}`} href="post-link" title="Reply to this post">00000001</a>
&nbsp; &nbsp;
<span key={`rl1-${thread.cid}`}>
2023-02-07 22:55:00 +01:00
[
2023-02-08 11:02:02 +01:00
<a key={`rl2-${thread.cid}`} className="reply-link" href="post-link">Reply</a>
2023-02-07 22:55:00 +01:00
]
</span>
</span>
2023-02-08 11:02:02 +01:00
<a key={`pmb-${thread.cid}`} className="post-menu-button" href="post-menu" title="Post menu" data-cmd="post-menu"></a>
<div key={`bi-${thread.cid}`} id="backlink-id" className="backlink">
<span key={`ql1-${thread.cid}`}>
<a key={`ql2-${thread.cid}`} className="quote-link" href="post-link">{'>>'}00000002</a>
2023-02-05 22:15:38 +01:00
</span>
2023-02-07 22:55:00 +01:00
</div>
2023-02-08 11:02:02 +01:00
<blockquote key={`t-${thread.cid}`}>
<span key={`q-${thread.cid}`} className="quote">
{'>'}{thread.title}
2023-02-07 22:55:00 +01:00
</span>
2023-02-08 11:02:02 +01:00
<br key={`br-${thread.cid}`} />
{thread.content}
2023-02-07 22:55:00 +01:00
</blockquote>
2023-02-05 22:15:38 +01:00
</div>
2023-02-07 22:55:00 +01:00
</div>
</div>
2023-02-08 11:02:02 +01:00
{comments.map(reply => (
<div key={`pc-${reply.cid}`} className="post-container reply-container">
<div key={`sa-${reply.cid}`} className="side-arrows">{'>>'}</div>
<div key={`pr-${reply.cid}`} className="post-reply">
<div key={`pi-${reply.cid}`} className="post-info">
&nbsp;
<span key={`nb-${reply.cid}`} className="nameblock">
<span key={`n-${reply.cid}`} className="name">{reply.author.displayName}</span>
&nbsp;
<span key={`pa-${reply.cid}`} className="poster-address">
(User: {reply.author.address})
2023-02-07 22:55:00 +01:00
</span>
</span>
2023-02-08 11:02:02 +01:00
&nbsp;
<span key={`dt-${reply.cid}`} className="date-time" data-utc="data">2 weeks ago</span>
&nbsp;
<span key={`pn-${reply.cid}`} className="post-number">
<a key={`pl1-${reply.cid}`} href="post-link" title="Link to this post">No.</a>
<a key={`pl2-${reply.cid}`} href="post-link" title="Reply to this post">00000002</a>
2023-02-07 22:55:00 +01:00
</span>
2023-02-08 11:02:02 +01:00
<a key={`pmb-${reply.cid}`} className="post-menu-button" href="#" title="Post menu" data-cmd="post-menu"></a>
2023-02-07 22:55:00 +01:00
</div>
2023-02-08 11:02:02 +01:00
<blockquote key={`pm-${reply.cid}`} className="post-message">
<span key={`q-${reply.cid}`} className="quote">
{'>'}{reply.title}
2023-02-05 22:15:38 +01:00
</span>
2023-02-07 13:23:14 +01:00
<br />
2023-02-08 11:02:02 +01:00
{reply.content}
2023-02-05 22:15:38 +01:00
</blockquote>
</div>
</div>
2023-02-08 11:02:02 +01:00
))}
2023-02-05 22:15:38 +01:00
</div>
2023-02-08 21:49:36 +01:00
<hr key={`hr-${thread.cid}`} />
2023-02-07 22:55:00 +01:00
</>
2023-02-08 11:02:02 +01:00
)})}
2023-02-07 13:23:14 +01:00
</div>
2023-02-05 22:15:38 +01:00
</BoardForm>
2023-02-04 22:10:54 +01:00
</Container>
2023-02-07 22:55:00 +01:00
);
2023-01-31 23:08:57 +01:00
}
export default Board;