From bb3a5c93dfc394c3186587fde0c9c834c12da06f Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 6 Nov 2020 10:10:38 +0900 Subject: Add some basic routing --- src/App.js | 197 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 132 insertions(+), 65 deletions(-) (limited to 'src/App.js') diff --git a/src/App.js b/src/App.js index 2225ac5..69ff38e 100644 --- a/src/App.js +++ b/src/App.js @@ -48,6 +48,15 @@ import { useWindowDimensions } from './utils.js'; import 'pure-react-carousel/dist/react-carousel.es.css'; import 'fontsource-roboto'; +import { + BrowserRouter as Router, + Switch, + Route, + Redirect, + Link, + useLocation +} from "react-router-dom"; + const StyledBadge = withStyles((theme) => ({ badge: { right: -3, @@ -231,6 +240,74 @@ function StoreList(props) { ); } +function StoreView(props) { + const [state, setState] = useState({data: [], loaded: false}); + useEffect(() => { + async function fetchData() { + function getRandomInt(max) { + return Math.floor(Math.random() * Math.floor(max)); + } + var result = await fetch('https://cors-anywhere.herokuapp.com/https://www.eisys-bcs.jp/data.json?key[]=dlsite-doujin_home_center2').then(result => result.json()); + result = result.data.['dlsite-doujin_home_center2'].banners.map(item => { return { + id: 'no-id', + author: he.decode(item.title), + title: he.decode(item.title), + shortdesc: 'foobar', + desc: 'foobar', + img: 'https:' + item.ssl_path, + cat: 'Misc', + price: getRandomInt(3000) + '円', + rating: getRandomInt(5), + }}) + setState({data: result, loaded: true}); + } + fetchData(); + }, []); + + return ( + <> + + + + + ); +} + +function LibraryView(props) { + const [state, setState] = useState({data: [], loaded: false}); + useEffect(() => { + async function fetchData() { + function getRandomInt(max) { + return Math.floor(Math.random() * Math.floor(max)); + } + var result = await fetch('https://cors-anywhere.herokuapp.com/https://www.eisys-bcs.jp/data.json?key[]=dlsite-doujin_home_center2').then(result => result.json()); + result = result.data.['dlsite-doujin_home_center2'].banners.map(item => { return { + id: 'no-id', + author: he.decode(item.title), + title: he.decode(item.title), + shortdesc: 'foobar', + desc: 'foobar', + img: 'https:' + item.ssl_path, + cat: 'Misc', + price: getRandomInt(3000) + '円', + rating: getRandomInt(5), + }}) + setState({data: result, loaded: true}); + } + fetchData(); + }, []); + + return ( + <> + + + ); +} + +function AccountView(props) { + return <>; +} + function ItemSearch(props) { const { t } = useTranslation(); @@ -317,82 +394,73 @@ function ItemSearch(props) { ); } -function StoreView(props) { +function BottomBar(props) { const { t } = useTranslation(); - - const [data, setData] = useState([]); - const [loaded, setLoaded] = useState(false); - useEffect(() => { - async function fetchData() { - function getRandomInt(max) { - return Math.floor(Math.random() * Math.floor(max)); - } - var result = await fetch('https://cors-anywhere.herokuapp.com/https://www.eisys-bcs.jp/data.json?key[]=dlsite-doujin_home_center2').then(result => result.json()); - console.log(result) - result = result.data.['dlsite-doujin_home_center2'].banners.map(item => { return { - id: 'no-id', - author: he.decode(item.title), - title: he.decode(item.title), - shortdesc: 'foobar', - desc: 'foobar', - img: 'https:' + item.ssl_path, - cat: 'Misc', - price: getRandomInt(3000) + '円', - rating: getRandomInt(5), - }}) - setData(result); - setLoaded(true) - } - fetchData(); - }, []); - const classes = makeStyles((theme) => ({ - root: { - paddingTop: 105, - paddingBottom: 65, - }, stickyBottom: { position: 'fixed', width: '100%', bottom: 0, }, + }))(); + return ( + + } component={Link} to='/store'/> + } component={Link} to='/library'/> + } component={Link} to='/account'/> + + ); +} + +function TopBar(props) { + const { t } = useTranslation(); + const classes = makeStyles((theme) => ({ title: { flexGrow: 1 }, }))(); + return ( + + + + {t('DoujinSea')} + + + + + + + + + + + {props.search ? : null} + + ); +} +function Routing() { + const classes = makeStyles((theme) => ({ + content: { + paddingTop: 105, + paddingBottom: 65, + minHeight: '100vh', + }, + }))(); + var location = useLocation(); + const path = location.pathname.split('/')[1]; return ( <> - - - - {t('DoujinSea')} - - - - - - - - - - - - - - - - - - {}} - showLabels - > - } /> - } /> - } /> - + + + + + + + + + + - ) + ); } export default function Main() { @@ -403,12 +471,11 @@ export default function Main() { primary: red, }, }), [prefersDarkMode]); - return ( <> - + ); -- cgit v1.2.3