171 lines
5.5 KiB
JavaScript
171 lines
5.5 KiB
JavaScript
/************************************************************************
|
|
Copyright (C) Ayushya Amitabh - All Rights Reserved
|
|
Unauthorized copying of this file, via any medium is strictly prohibited
|
|
Proprietary and confidential
|
|
Written by Ayushya Amitabh <admin@chromewatchparty.com>, 2020
|
|
https://www.chromewatchparty.com/copyright
|
|
=========================================================================
|
|
ALL CONTENT ON WATCH PARTY'S WEBSITE OR IN WATCH PARTY'S CHROME EXTENSION APP, UNLESS OTHERWISE
|
|
CITED ARE THE SOLE INTELECTUAL PROPERTY OF AYUSHYA AMITABH, AND MAY NOT BE
|
|
COPIED, EDITED, OR REPRODUCED WITHOUT PERMISSION.
|
|
************************************************************************/
|
|
import React, { useState, useEffect } from 'react';
|
|
import Router from 'route-lite';
|
|
import { Fab, createMuiTheme, ThemeProvider, Snackbar, Tooltip } from '@material-ui/core';
|
|
import Create from './Create';
|
|
import Loading from './Loading';
|
|
import firebase from 'firebase/app';
|
|
import 'firebase/firestore';
|
|
import Inactive from './Inactive';
|
|
import { getUserUid, getPlayerSource, PLAYER_SOURCE } from './Api';
|
|
|
|
const APP_VERSION = '1.6.0';
|
|
const APP_VERSION_STRING = APP_VERSION.replace(/\./g, '');
|
|
|
|
const darkTheme = createMuiTheme({
|
|
palette: {
|
|
type: 'dark',
|
|
primary: {
|
|
main: '#FF0000',
|
|
},
|
|
secondary: {
|
|
main: '#c0f300',
|
|
},
|
|
},
|
|
});
|
|
|
|
const Routes = (props) => (
|
|
<Router>
|
|
<Create {...props} />
|
|
</Router>
|
|
);
|
|
|
|
const resetResize = () => {
|
|
const checkedX = 400;
|
|
document.documentElement.style.setProperty('--party-width', `${checkedX}px`);
|
|
document.documentElement.style.setProperty('--neg-party-width', `-${checkedX}px`);
|
|
};
|
|
|
|
const doResize = (ev) => {
|
|
const checkedX =
|
|
window.innerWidth -
|
|
Math.min(window.innerWidth - 300, Math.max(window.innerWidth * 0.5, ev.clientX));
|
|
document.documentElement.style.setProperty('--party-width', `${checkedX}px`);
|
|
document.documentElement.style.setProperty('--neg-party-width', `-${checkedX}px`);
|
|
};
|
|
|
|
const stopResize = (ev) => {
|
|
document.documentElement.removeEventListener('mousemove', doResize, false);
|
|
document.documentElement.removeEventListener('mouseup', stopResize, false);
|
|
};
|
|
|
|
const startResize = (ev) => {
|
|
document.documentElement.addEventListener('mousemove', doResize, false);
|
|
document.documentElement.addEventListener('mouseup', stopResize, false);
|
|
};
|
|
|
|
const App = () => {
|
|
const closedNotification = { open: false, message: '' };
|
|
|
|
const [status, setStatus] = useState({ active: false, message: '' });
|
|
const [visible, setVisible] = useState(false);
|
|
const [loading, setLoading] = useState(false);
|
|
const [notification, setNotification] = useState(closedNotification);
|
|
|
|
let hasAttached = false;
|
|
|
|
useEffect(() => {
|
|
setLoading(true);
|
|
getUserUid();
|
|
firebase
|
|
.firestore()
|
|
.collection('server')
|
|
.doc('status')
|
|
.onSnapshot((statusSnap) => {
|
|
setStatus(statusSnap.data());
|
|
setLoading(false);
|
|
});
|
|
}, []);
|
|
|
|
// HANDLE VISIBILITY STYLING
|
|
const PartyRoutesWrapper = document.getElementById('party-routes-wrapper');
|
|
if (visible) {
|
|
document.body.classList.add('visible');
|
|
PartyRoutesWrapper && PartyRoutesWrapper.classList.add('visible');
|
|
if (
|
|
!hasAttached &&
|
|
(getPlayerSource() === PLAYER_SOURCE.HBOMAX || getPlayerSource() === PLAYER_SOURCE.HBONOW)
|
|
) {
|
|
document.addEventListener(
|
|
'mousedown',
|
|
function (ev) {
|
|
if (document.body.querySelector('body.visible')) {
|
|
ev.preventDefault();
|
|
ev.stopPropagation();
|
|
ev.stopImmediatePropagation();
|
|
}
|
|
},
|
|
{ capture: true }
|
|
);
|
|
hasAttached = true;
|
|
}
|
|
} else {
|
|
document.body.classList.remove('visible');
|
|
PartyRoutesWrapper && PartyRoutesWrapper.classList.remove('visible');
|
|
}
|
|
|
|
// HANDLE FULLSCREEN EVENT
|
|
document.onfullscreenchange = () => {
|
|
if (document.fullscreenElement) setVisible(false);
|
|
};
|
|
|
|
return (
|
|
<ThemeProvider theme={darkTheme}>
|
|
<Snackbar
|
|
className="party-notification-container"
|
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
|
|
open={notification.open}
|
|
onClose={() => setNotification(closedNotification)}
|
|
message={notification.message}
|
|
autoHideDuration={6000}
|
|
/>
|
|
<div className="party-content-wrapper">
|
|
<div id="party-routes-wrapper">
|
|
<Tooltip
|
|
placement="right-end"
|
|
title="Resize Sidebar / Double Click To Reset"
|
|
aria-label="Resize Sidebar / Double Click To Reset"
|
|
>
|
|
<div onDoubleClick={resetResize} onMouseDown={startResize} id="party-width-dragger">
|
|
||
|
|
</div>
|
|
</Tooltip>
|
|
{loading && <Loading />}
|
|
{status[APP_VERSION_STRING] && status[APP_VERSION_STRING].active === true ? (
|
|
<Routes
|
|
updateLoading={setLoading}
|
|
notify={(message) => setNotification({ open: true, message })}
|
|
appVersion={APP_VERSION}
|
|
appVersionString={APP_VERSION_STRING}
|
|
status={status[APP_VERSION_STRING]}
|
|
/>
|
|
) : (
|
|
<Inactive
|
|
status={
|
|
status[APP_VERSION_STRING]
|
|
? status[APP_VERSION_STRING].message
|
|
: "Uh oh, can't connect to server. Trying again..."
|
|
}
|
|
/>
|
|
)}
|
|
</div>
|
|
<Fab onClick={() => setVisible(!visible)} className="watch-party-fab">
|
|
<span />
|
|
</Fab>
|
|
</div>
|
|
</ThemeProvider>
|
|
);
|
|
};
|
|
|
|
export default App;
|