Skip to content

Commit

Permalink
run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Dec 13, 2023
1 parent e5d54d1 commit 3f650b3
Show file tree
Hide file tree
Showing 83 changed files with 15,251 additions and 11,515 deletions.
18 changes: 15 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@
"parserOptions": { "sourceType": "module" }
},
{
"files": ["*.ts", "*.tsx"],
"files": ["*.js"],
"rules": {
"no-undef": "off"
"@typescript-eslint/no-var-requires": "off"
}
}
],
// overrides airbnb, use sparingly
"rules": {
// Required for dependency injection
"no-useless-constructor": "off",
"no-empty-function": "off",

"@typescript-eslint/no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_.+$",
"argsIgnorePattern": "^_.+$"
}
],

"prettier/prettier": [
"error",
{
Expand All @@ -52,8 +59,13 @@
}
],

"@typescript-eslint/no-explicit-any": "off",

// Annoying shit
"no-undef": "off",
"no-redeclare": "off",
"no-await-in-loop":"off",
"no-constant-condition":"off",
"strict": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off"
Expand Down
253 changes: 120 additions & 133 deletions apps/mcdu/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,152 +15,139 @@ let soundParam = false;
let aspect43Param = false;
const params = window.location.href.split('?');
if (params.length > 1) {
params[1].split('&').forEach((p) => {
switch (p) {
case 'fullscreen':
fullscreenParam = true;
break;
case 'sound':
soundParam = true;
break;
case '43':
aspect43Param = true;
fullscreenParam = true;
break;
default:
console.error('wrong param provided');
}
});
params[1].split('&').forEach((p) => {
switch (p) {
case 'fullscreen':
fullscreenParam = true;
break;
case 'sound':
soundParam = true;
break;
case '43':
aspect43Param = true;
fullscreenParam = true;
break;
default:
console.error('wrong param provided');
}
});
}

const App = () => {
const [fullscreen, setFullscreen] = useState(fullscreenParam);
const [soundEnabled] = useState(soundParam);
const [dark, setDark] = useState(false);

// as http and websocket port are always the same we can read it from the URL
let socketUrl = `ws://${window.location.host}/interfaces/v1/mcdu`;
const [fullscreen, setFullscreen] = useState(fullscreenParam);
const [soundEnabled] = useState(soundParam);
const [dark, setDark] = useState(false);

// automaticaly upgrate to wss if the page is served over https
if (window.location.protocol === 'https:') {
socketUrl = socketUrl.replace('ws', 'wss');
}
// as http and websocket port are always the same we can read it from the URL
let socketUrl = `ws://${window.location.host}/interfaces/v1/mcdu`;

const [content, setContent] = useState(
{
lines: [
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
],
scratchpad: '',
title: '',
titleLeft: '',
page: '',
arrows: [false, false, false, false],
},
);
// automaticaly upgrate to wss if the page is served over https
if (window.location.protocol === 'https:') {
socketUrl = socketUrl.replace('ws', 'wss');
}

const {
sendMessage,
lastMessage,
readyState,
} = useWebSocket(socketUrl, {
shouldReconnect: () => true,
reconnectAttempts: Infinity,
reconnectInterval: 500,
});
const [content, setContent] = useState({
lines: [
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
['', '', ''],
],
scratchpad: '',
title: '',
titleLeft: '',
page: '',
arrows: [false, false, false, false],
});

const { onKeyboardInput } = new McduKeyboardEvents(sendMessage);
const rootPanelRef = useRef(null);
const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl, {
shouldReconnect: () => true,
reconnectAttempts: Infinity,
reconnectInterval: 500,
});

useEffect(() => {
rootPanelRef.current.focus();
}, []);
const { onKeyboardInput } = new McduKeyboardEvents(sendMessage);
const rootPanelRef = useRef(null);

useEffect(() => {
if (readyState === ReadyState.OPEN) {
sendMessage('requestUpdate');
}
}, [readyState]);
useEffect(() => {
rootPanelRef.current.focus();
}, []);

useEffect(() => {
if (lastMessage != null) {
const messageType = lastMessage.data.split(':')[0];
if (messageType === 'update') {
setContent(JSON.parse(lastMessage.data.substring(lastMessage.data.indexOf(':') + 1)).left);
}
}
}, [lastMessage]);
useEffect(() => {
if (readyState === ReadyState.OPEN) {
sendMessage('requestUpdate');
}
}, [readyState]);

let backgroundImageUrl = bg;
if (dark) {
backgroundImageUrl = darkBg;
useEffect(() => {
if (lastMessage != null) {
const messageType = lastMessage.data.split(':')[0];
if (messageType === 'update') {
setContent(JSON.parse(lastMessage.data.substring(lastMessage.data.indexOf(':') + 1)).left);
}
}
}, [lastMessage]);

let backgroundImageUrl = bg;
if (dark) {
backgroundImageUrl = darkBg;
}

return (
<div ref={rootPanelRef} tabIndex={-1} onKeyDown={onKeyboardInput}>
{!fullscreen && (
<>
<div className="normal">
<div className="App" style={{ backgroundImage: `url(${backgroundImageUrl})` }}>
<WebsocketContext.Provider value={{ sendMessage, lastMessage, readyState }}>
<McduScreen content={content} />
<McduButtons soundEnabled={soundEnabled} />
<div
className="button-grid"
style={{
left: `${184 / 10.61}%`,
top: `${158 / 16.50}%`,
width: `${706 / 10.61}%`,
height: `${60 / 16.50}%`,
}}
>
<div className="button-row">
<div
className="button"
title="Fullscreen"
onClick={() => setFullscreen(!fullscreen)}
/>
</div>
</div>
<div
className="button-grid"
style={{ left: '82%', top: '50%', width: '8%', height: '8%' }}
>
<div className="button-row">
<div className="button" title="Dark" onClick={() => setDark(!dark)} />
</div>
</div>
</WebsocketContext.Provider>
</div>
</div>
</>
)}
{fullscreen && (
<>
<div className={aspect43Param ? 'fullscreen aspect43' : 'fullscreen'}>
<div className="App">
<WebsocketContext.Provider value={{ sendMessage, lastMessage, readyState }}>
<div title="Exit fullscreen" onClick={() => setFullscreen(false)}>
<McduScreen content={content} aspect43={aspect43Param} />
</div>
</WebsocketContext.Provider>
</div>
</div>
</>
)}
</div>
);
return (
<div ref={rootPanelRef} tabIndex={-1} onKeyDown={onKeyboardInput}>
{!fullscreen && (
<>
<div className="normal">
<div className="App" style={{ backgroundImage: `url(${backgroundImageUrl})` }}>
<WebsocketContext.Provider value={{ sendMessage, lastMessage, readyState }}>
<McduScreen content={content} />
<McduButtons soundEnabled={soundEnabled} />
<div
className="button-grid"
style={{
left: `${184 / 10.61}%`,
top: `${158 / 16.5}%`,
width: `${706 / 10.61}%`,
height: `${60 / 16.5}%`,
}}
>
<div className="button-row">
<div className="button" title="Fullscreen" onClick={() => setFullscreen(!fullscreen)} />
</div>
</div>
<div className="button-grid" style={{ left: '82%', top: '50%', width: '8%', height: '8%' }}>
<div className="button-row">
<div className="button" title="Dark" onClick={() => setDark(!dark)} />
</div>
</div>
</WebsocketContext.Provider>
</div>
</div>
</>
)}
{fullscreen && (
<>
<div className={aspect43Param ? 'fullscreen aspect43' : 'fullscreen'}>
<div className="App">
<WebsocketContext.Provider value={{ sendMessage, lastMessage, readyState }}>
<div title="Exit fullscreen" onClick={() => setFullscreen(false)}>
<McduScreen content={content} aspect43={aspect43Param} />
</div>
</WebsocketContext.Provider>
</div>
</div>
</>
)}
</div>
);
};

export default App;
Loading

0 comments on commit 3f650b3

Please sign in to comment.