2022-07-13 04:49:10 +00:00
|
|
|
import React, { useState, useEffect, useReducer } from 'react';
|
2022-07-14 21:58:50 +00:00
|
|
|
import { Switch, Route, Link, useHistory } from 'react-router-dom';
|
2020-01-23 23:42:32 +00:00
|
|
|
import './semantic-ui/semantic.min.css';
|
|
|
|
import './light.css';
|
2020-10-10 21:57:25 +00:00
|
|
|
import './dark.css';
|
2022-07-13 04:49:10 +00:00
|
|
|
import { Container, Dropdown, Menu } from 'semantic-ui-react';
|
2020-04-05 22:00:33 +00:00
|
|
|
import Darkmode from 'darkmode-js';
|
2020-01-31 23:47:52 +00:00
|
|
|
import { isAdmin, requester } from './utils.js';
|
2020-02-17 00:19:44 +00:00
|
|
|
import { ManageScroll } from './ManageScroll.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { Home } from './Home.js';
|
2020-01-12 08:16:09 +00:00
|
|
|
import { Account } from './Account.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { Transactions, TransactionDetail } from './Transactions.js';
|
2020-02-21 07:46:13 +00:00
|
|
|
import { Paymaster } from './Paymaster.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { Cards } from './Cards.js';
|
2020-01-10 00:29:52 +00:00
|
|
|
import { Training } from './Training.js';
|
2020-02-22 05:22:39 +00:00
|
|
|
import { AdminTransactions } from './AdminTransactions.js';
|
2020-02-16 04:57:55 +00:00
|
|
|
import { Admin } from './Admin.js';
|
2020-02-17 03:28:17 +00:00
|
|
|
import { Paste } from './Paste.js';
|
2021-12-08 22:02:30 +00:00
|
|
|
import { Sign } from './Sign.js';
|
2020-01-10 06:24:37 +00:00
|
|
|
import { Courses, CourseDetail } from './Courses.js';
|
2022-01-26 04:21:47 +00:00
|
|
|
import { ClassFeed, Classes, ClassDetail } from './Classes.js';
|
2020-01-11 23:53:42 +00:00
|
|
|
import { Members, MemberDetail } from './Members.js';
|
2020-04-21 21:15:04 +00:00
|
|
|
import { Charts } from './Charts.js';
|
2022-02-08 02:28:10 +00:00
|
|
|
import { Usage } from './Usage.js';
|
2020-09-18 05:04:00 +00:00
|
|
|
import { Auth } from './Auth.js';
|
2021-08-18 20:40:11 +00:00
|
|
|
import { Subscribe } from './PayPal.js';
|
2020-06-20 03:50:09 +00:00
|
|
|
import { PasswordReset, ConfirmReset } from './PasswordReset.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
import { NotFound, PleaseLogin } from './Misc.js';
|
2022-04-10 07:11:53 +00:00
|
|
|
import { Debug } from './Debug.js';
|
2023-05-30 19:35:07 +00:00
|
|
|
import { StorageDetail } from './Storage.js';
|
2022-05-17 02:38:20 +00:00
|
|
|
import { Garden } from './Garden.js';
|
2020-01-11 08:56:31 +00:00
|
|
|
import { Footer } from './Footer.js';
|
2023-04-05 04:54:49 +00:00
|
|
|
import { LCARS1Display, LCARS2Display } from './Display.js';
|
2020-01-09 09:15:01 +00:00
|
|
|
|
2022-09-05 22:03:34 +00:00
|
|
|
const APP_VERSION = 5; // TODO: automate this
|
2022-01-21 22:48:51 +00:00
|
|
|
|
2020-01-06 23:32:29 +00:00
|
|
|
function App() {
|
2020-01-08 23:43:59 +00:00
|
|
|
const [token, setToken] = useState(localStorage.getItem('token', ''));
|
|
|
|
const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false')));
|
2020-01-18 01:27:56 +00:00
|
|
|
const [refreshCount, refreshUser] = useReducer(x => x + 1, 0);
|
2020-01-21 23:45:54 +00:00
|
|
|
const [yousure, setYousure] = useState(false);
|
2020-01-23 02:54:33 +00:00
|
|
|
const history = useHistory();
|
2020-01-08 23:43:59 +00:00
|
|
|
|
2020-01-09 09:04:32 +00:00
|
|
|
function setTokenCache(x) {
|
2020-01-08 23:43:59 +00:00
|
|
|
setToken(x);
|
|
|
|
localStorage.setItem('token', x);
|
|
|
|
}
|
|
|
|
|
2020-01-09 09:04:32 +00:00
|
|
|
function setUserCache(x) {
|
2020-01-08 23:43:59 +00:00
|
|
|
setUser(x);
|
|
|
|
localStorage.setItem('user', JSON.stringify(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-01-13 01:03:02 +00:00
|
|
|
requester('/user/', 'GET', token)
|
2020-01-08 23:43:59 +00:00
|
|
|
.then(res => {
|
|
|
|
setUserCache(res);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
2020-02-04 08:32:01 +00:00
|
|
|
setUserCache(null);
|
2020-01-08 23:43:59 +00:00
|
|
|
});
|
2020-01-18 01:27:56 +00:00
|
|
|
}, [token, refreshCount]);
|
2020-01-08 23:43:59 +00:00
|
|
|
|
2020-01-09 09:04:32 +00:00
|
|
|
function logout() {
|
2020-01-21 23:45:54 +00:00
|
|
|
if (yousure) {
|
|
|
|
setTokenCache('');
|
2020-02-04 08:32:01 +00:00
|
|
|
setUserCache(null);
|
2020-01-21 23:45:54 +00:00
|
|
|
setYousure(false);
|
2020-01-23 02:54:33 +00:00
|
|
|
history.push('/');
|
2020-01-23 03:32:54 +00:00
|
|
|
window.scrollTo(0, 0);
|
2020-01-21 23:45:54 +00:00
|
|
|
} else {
|
|
|
|
setYousure(true);
|
|
|
|
}
|
2020-01-08 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 08:32:01 +00:00
|
|
|
useEffect(() => {
|
2020-08-03 03:26:20 +00:00
|
|
|
if (user) {
|
|
|
|
const data = {
|
|
|
|
id: user.member.id,
|
|
|
|
username: user.username,
|
|
|
|
path: history.location.pathname,
|
|
|
|
};
|
|
|
|
requester('/ping/', 'POST', token, data)
|
|
|
|
.then()
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
if (err.data && err.data.detail === 'Invalid token.') {
|
|
|
|
logout(); // You Sure?
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-02-04 08:32:01 +00:00
|
|
|
}, [history.location]);
|
|
|
|
|
2020-04-05 22:00:33 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const options = {
|
|
|
|
bottom: '16px',
|
|
|
|
right: '16px',
|
2020-04-16 05:04:48 +00:00
|
|
|
buttonColorDark: '#666',
|
|
|
|
buttonColorLight: '#aaa',
|
2023-02-18 02:56:48 +00:00
|
|
|
label: '🌓',
|
2023-02-18 02:55:04 +00:00
|
|
|
autoMatchOsTheme: false,
|
2020-04-05 22:00:33 +00:00
|
|
|
}
|
|
|
|
const darkmode = new Darkmode(options);
|
|
|
|
darkmode.showWidget();
|
|
|
|
}, []);
|
|
|
|
|
2022-01-21 22:48:51 +00:00
|
|
|
if (user && user?.app_version !== APP_VERSION) {
|
|
|
|
setUserCache(false);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
2020-01-07 02:10:25 +00:00
|
|
|
return (
|
2020-01-23 02:54:33 +00:00
|
|
|
<div>
|
2020-02-17 00:19:44 +00:00
|
|
|
<ManageScroll />
|
|
|
|
|
2020-01-11 08:56:31 +00:00
|
|
|
<div className='content-wrap'>
|
|
|
|
<div className='content-wrap-inside'>
|
2020-01-13 01:03:02 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Switch>
|
|
|
|
<Route exact path='/classfeed'>
|
|
|
|
<ClassFeed />
|
|
|
|
</Route>
|
|
|
|
|
2022-02-08 02:28:10 +00:00
|
|
|
<Route exact path='/usage/:name'>
|
2022-05-10 01:22:45 +00:00
|
|
|
<Usage token={token} />
|
2022-02-08 02:28:10 +00:00
|
|
|
</Route>
|
|
|
|
|
2022-08-09 07:21:40 +00:00
|
|
|
<Route exact path='/display/lcars1'>
|
|
|
|
<LCARS1Display token={token} />
|
|
|
|
</Route>
|
|
|
|
|
2023-04-05 04:54:49 +00:00
|
|
|
<Route exact path='/display/lcars2'>
|
|
|
|
<LCARS2Display token={token} />
|
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/'>
|
|
|
|
<Container>
|
|
|
|
<div className='hero'>
|
|
|
|
<Link to='/'>
|
|
|
|
<img src='/logo-long.svg' className='logo-long' />
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{window.location.hostname !== 'my.protospace.ca' &&
|
|
|
|
<p style={{ background: 'yellow' }}>~~~~~ Development site ~~~~~</p>
|
|
|
|
}
|
|
|
|
</Container>
|
|
|
|
|
|
|
|
<Menu>
|
|
|
|
<Container>
|
|
|
|
<Menu.Item
|
2022-04-05 20:36:46 +00:00
|
|
|
icon='home'
|
2020-02-21 07:46:13 +00:00
|
|
|
as={Link}
|
2022-01-26 04:21:47 +00:00
|
|
|
to='/'
|
2020-02-21 07:46:13 +00:00
|
|
|
/>
|
2021-12-08 22:02:30 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Dropdown item text='Member' id='ps-menu'>
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Account'
|
|
|
|
as={Link}
|
|
|
|
to='/account'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Transactions'
|
|
|
|
as={Link}
|
|
|
|
to='/transactions'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Paymaster'
|
|
|
|
as={Link}
|
|
|
|
to='/paymaster'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Training'
|
|
|
|
as={Link}
|
|
|
|
to='/training'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Cards / Access'
|
|
|
|
as={Link}
|
|
|
|
to='/cards'
|
|
|
|
/>
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
|
|
|
|
<Dropdown item text='Space' id='ps-menu'>
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Member List'
|
|
|
|
as={Link}
|
|
|
|
to='/members'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Classes'
|
|
|
|
as={Link}
|
|
|
|
to='/classes'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Utilities'
|
|
|
|
as={Link}
|
|
|
|
to='/utils'
|
|
|
|
/>
|
|
|
|
<Dropdown.Item
|
|
|
|
content='Charts'
|
|
|
|
as={Link}
|
|
|
|
to='/charts'
|
|
|
|
/>
|
|
|
|
|
|
|
|
{user && isAdmin(user) && <Dropdown.Item
|
|
|
|
content='Admin'
|
|
|
|
as={Link}
|
|
|
|
to='/admin'
|
|
|
|
/>}
|
|
|
|
|
|
|
|
{user && isAdmin(user) && <Dropdown.Item
|
|
|
|
content='Transactions'
|
|
|
|
as={Link}
|
|
|
|
to='/admintrans'
|
|
|
|
/>}
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
|
|
|
|
{user && <Menu.Menu position='right'>
|
|
|
|
<Menu.Item
|
2022-05-09 22:36:11 +00:00
|
|
|
content={yousure ? 'Log out?' : ''}
|
2022-01-26 04:21:47 +00:00
|
|
|
onClick={logout}
|
2022-04-05 20:36:46 +00:00
|
|
|
icon='sign out'
|
2022-01-26 04:21:47 +00:00
|
|
|
/>
|
|
|
|
<Menu.Item fitted content='' />
|
|
|
|
</Menu.Menu>}
|
|
|
|
</Container>
|
|
|
|
</Menu>
|
|
|
|
|
|
|
|
<Route exact path='/'>
|
|
|
|
<Home token={token} setTokenCache={setTokenCache} user={user} refreshUser={refreshUser} />
|
2020-04-21 21:15:04 +00:00
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<div className='topPadding'>
|
2020-02-17 03:28:17 +00:00
|
|
|
<Switch>
|
2023-05-30 19:35:07 +00:00
|
|
|
<Route path='/storage/:id'>
|
|
|
|
<StorageDetail token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
|
2022-04-10 07:11:53 +00:00
|
|
|
<Route path='/debug'>
|
|
|
|
<Debug token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/password/reset/confirm/:uid/:token'>
|
|
|
|
<ConfirmReset />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/password/reset'>
|
|
|
|
<PasswordReset />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
2020-01-10 00:29:52 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/utils'>
|
|
|
|
<Paste token={token} />
|
2020-02-21 07:46:13 +00:00
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/sign'>
|
|
|
|
<Sign token={token} />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/charts'>
|
|
|
|
<Charts />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/auth'>
|
|
|
|
<Auth user={user} />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
2020-01-11 02:50:55 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route path='/subscribe'>
|
|
|
|
<Subscribe />
|
2020-02-16 04:57:55 +00:00
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
<Route exact path='/classes'>
|
2022-05-04 01:27:50 +00:00
|
|
|
<Classes token={token} user={user} refreshUser={refreshUser} />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
|
|
|
|
2022-05-17 02:38:20 +00:00
|
|
|
<Route path='/garden'>
|
|
|
|
<Garden />
|
|
|
|
</Route>
|
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
{user && user.member.set_details ?
|
|
|
|
<Switch>
|
|
|
|
<Route path='/account'>
|
|
|
|
<Account token={token} user={user} refreshUser={refreshUser} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/transactions/:id'>
|
|
|
|
<TransactionDetail token={token} user={user} refreshUser={refreshUser} />
|
|
|
|
</Route>
|
|
|
|
<Route path='/transactions'>
|
|
|
|
<Transactions user={user} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/paymaster'>
|
2022-08-23 02:54:19 +00:00
|
|
|
<Paymaster token={token} user={user} refreshUser={refreshUser} />
|
2022-01-26 04:21:47 +00:00
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/cards'>
|
|
|
|
<Cards token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/training'>
|
|
|
|
<Training user={user} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/courses/:id'>
|
2022-05-24 05:02:15 +00:00
|
|
|
<CourseDetail token={token} user={user} refreshUser={refreshUser} />
|
2022-01-26 04:21:47 +00:00
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/courses'>
|
|
|
|
<Courses token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/classes/:id'>
|
|
|
|
<ClassDetail token={token} user={user} refreshUser={refreshUser} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/members/:id'>
|
|
|
|
<MemberDetail token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
<Route path='/members'>
|
|
|
|
<Members token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
{user && isAdmin(user) &&
|
|
|
|
<Route path='/admin'>
|
|
|
|
<Admin token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
}
|
|
|
|
|
|
|
|
{user && isAdmin(user) &&
|
|
|
|
<Route path='/admintrans'>
|
|
|
|
<AdminTransactions token={token} user={user} />
|
|
|
|
</Route>
|
|
|
|
}
|
|
|
|
|
|
|
|
<Route path='/:page'>
|
|
|
|
<NotFound />
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
:
|
|
|
|
<Route path='/:page'>
|
|
|
|
<PleaseLogin />
|
2020-02-17 03:28:17 +00:00
|
|
|
</Route>
|
|
|
|
}
|
|
|
|
</Switch>
|
2022-01-26 04:21:47 +00:00
|
|
|
</div>
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
2020-01-13 01:03:02 +00:00
|
|
|
|
2020-01-11 08:56:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-09 09:04:32 +00:00
|
|
|
|
2020-01-11 08:56:31 +00:00
|
|
|
<Footer />
|
2020-01-23 02:54:33 +00:00
|
|
|
</div>
|
2020-01-09 07:38:49 +00:00
|
|
|
)
|
|
|
|
};
|
2020-01-06 23:32:29 +00:00
|
|
|
|
|
|
|
export default App;
|