mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
added Board context
This commit is contained in:
+12
-8
@@ -6,6 +6,7 @@ import Board from './components/Board';
|
|||||||
import Thread from './components/Thread';
|
import Thread from './components/Thread';
|
||||||
import { createGlobalStyle } from 'styled-components';
|
import { createGlobalStyle } from 'styled-components';
|
||||||
|
|
||||||
|
export const BoardContext = React.createContext();
|
||||||
|
|
||||||
const GlobalStyle = createGlobalStyle`
|
const GlobalStyle = createGlobalStyle`
|
||||||
body {
|
body {
|
||||||
@@ -17,13 +18,16 @@ const GlobalStyle = createGlobalStyle`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function App() {
|
export default function App() {
|
||||||
const [bodyStyle, setBodyStyle] = useState({
|
const [bodyStyle, setBodyStyle] = useState({
|
||||||
background: "#ffe url(/fade.png) top repeat-x",
|
background: "#ffe url(/fade.png) top repeat-x",
|
||||||
color: "maroon",
|
color: "maroon",
|
||||||
fontFamily: "Helvetica, Arial, sans-serif"
|
fontFamily: "Helvetica, Arial, sans-serif"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [selectedTitle, setSelectedTitle] = useState('');
|
||||||
|
const [selectedAddress, setSelectedAddress] = useState('');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
@@ -40,12 +44,12 @@ function App() {
|
|||||||
color={bodyStyle.color}
|
color={bodyStyle.color}
|
||||||
fontFamily={bodyStyle.fontFamily}
|
fontFamily={bodyStyle.fontFamily}
|
||||||
/>
|
/>
|
||||||
<Routes>
|
<BoardContext.Provider value={{ selectedTitle, setSelectedTitle, selectedAddress, setSelectedAddress }}>
|
||||||
<Route path='/' element={<Home />} />
|
<Routes>
|
||||||
<Route path='/board' element={<Board setBodyStyle={setBodyStyle} />} />
|
<Route path='/' element={<Home />} />
|
||||||
<Route path='/board/:thread' element={<Thread />} />
|
<Route path='/board' element={<Board setBodyStyle={setBodyStyle} />} />
|
||||||
</Routes>
|
<Route path='/board/:thread' element={<Thread />} />
|
||||||
|
</Routes>
|
||||||
|
</BoardContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
export default App;
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useContext } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Container, NavBar, Header, Break, PostForm, TopBar, BoardForm } from './styles/Board.styled';
|
import { Container, NavBar, Header, Break, PostForm, TopBar, BoardForm } from './styles/Board.styled';
|
||||||
import { useFeed } from '@plebbit/plebbit-react-hooks';
|
import { useFeed } from '@plebbit/plebbit-react-hooks';
|
||||||
import ImageBanner from './ImageBanner';
|
import ImageBanner from './ImageBanner';
|
||||||
|
import { BoardContext } from '../App';
|
||||||
|
|
||||||
const Board = ({ setBodyStyle }) => {
|
const Board = ({ setBodyStyle }) => {
|
||||||
const [defaultSubplebbits, setDefaultSubplebbits] = useState([]);
|
const [defaultSubplebbits, setDefaultSubplebbits] = useState([]);
|
||||||
const [selectedTitle, setSelectedTitle] = useState("");
|
|
||||||
const [selectedAddress, setSelectedAddress] = useState("");
|
|
||||||
const [selectedStyle, setSelectedStyle] = useState("Yotsuba");
|
const [selectedStyle, setSelectedStyle] = useState("Yotsuba");
|
||||||
|
const { selectedTitle, setSelectedTitle, selectedAddress, setSelectedAddress } = useContext(BoardContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let didCancel = false;
|
let didCancel = false;
|
||||||
|
|||||||
+11
-2
@@ -1,9 +1,16 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useContext } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Container, Header, Logo, Page, Search, About, AboutTitle, AboutContent, Boards, BoardsTitle, BoardsContent, Footer } from './styles/Home.styled';
|
import { Container, Header, Logo, Page, Search, About, AboutTitle, AboutContent, Boards, BoardsTitle, BoardsContent, Footer } from './styles/Home.styled';
|
||||||
|
import { BoardContext } from '../App';
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const [defaultSubplebbits, setDefaultSubplebbits] = useState([]);
|
const [defaultSubplebbits, setDefaultSubplebbits] = useState([]);
|
||||||
|
const { selectedTitle, setSelectedTitle, selectedAddress, setSelectedAddress } = useContext(BoardContext);
|
||||||
|
|
||||||
|
const handleClick = (title, address) => {
|
||||||
|
setSelectedTitle(title);
|
||||||
|
setSelectedAddress(address);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let didCancel = false;
|
let didCancel = false;
|
||||||
@@ -58,7 +65,9 @@ const Home = () => {
|
|||||||
{defaultSubplebbits.map(subplebbit => (
|
{defaultSubplebbits.map(subplebbit => (
|
||||||
<div className="board" key={subplebbit.address}>
|
<div className="board" key={subplebbit.address}>
|
||||||
<div className="board-title">{subplebbit.title}</div>
|
<div className="board-title">{subplebbit.title}</div>
|
||||||
<Link to="/board">
|
<Link to="/board" onClick={() => {
|
||||||
|
handleClick(subplebbit.title, subplebbit.address);
|
||||||
|
}} >
|
||||||
<img alt="board logo" src="/plebchan.png" />
|
<img alt="board logo" src="/plebchan.png" />
|
||||||
</Link>
|
</Link>
|
||||||
<div className="board-text">
|
<div className="board-text">
|
||||||
|
|||||||
Reference in New Issue
Block a user