Skip to content

Commit

Permalink
basic keybinds, fixed navbar hierarchy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhartigan committed Mar 21, 2022
1 parent 2c8df0b commit c8be3c8
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 95 deletions.
15 changes: 15 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@use-it/event-listener": "^0.1.7",
"clsx": "^1.1.1",
"fuse.js": "^6.5.3",
"fuzzysort": "^1.1.4",
Expand Down
25 changes: 22 additions & 3 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function App(props) {
}, [])

useEffect(() => {
if(errorPage !== null){
if (errorPage !== null) {
setLoading(false)
}
})
Expand Down Expand Up @@ -251,10 +251,10 @@ function App(props) {
</Route>

<Route path="/collection">
{Config.ENABLED_PAGES.collection === true ? <CollectionHome /> : <Redirect to="/" />}
<VIMMain target={"collection"} />
</Route>
<Route path="/buddies">
{Config.ENABLED_PAGES.buddies === true ? <BuddiesHome /> : <Redirect to="/" />}
<VIMMain target={"buddies"} />
</Route>
</HashRouter>

Expand All @@ -265,4 +265,23 @@ function App(props) {
);
}

function VIMMain(props) {
const target = props.target

const routes = {
"collection": Config.ENABLED_PAGES.collection === true ? <CollectionHome /> : <Redirect to="/" />,
"buddies": Config.ENABLED_PAGES.buddies === true ? <BuddiesHome /> : <Redirect to="/" />,
}

return (
<>
<div style={{ height: "100vh", width: "100vw", display: "flex", overflow: "auto" }}>
<NavBar />
{routes[target]}
</div>

</>
)
}

export default App;
12 changes: 10 additions & 2 deletions client/src/components/misc/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { Grid, Grow, Typography, Toolbar, IconButton, Slide, Paper, Tooltip } fr
//icons
import { Settings, Shuffle, Autorenew, SportsEsports } from '@material-ui/icons';

import socket from "../../services/Socket";
import { useTypingEffect } from '../../services/TypingEffect';
import BackdroppedConfig from "../config/BackdroppedConfig.js"

import socket from "../../services/Socket";
import useKeyboardListener from '../../services/useKeyboardListener.js';


const useStyles = makeStyles((theme) => ({

Expand Down Expand Up @@ -72,6 +73,7 @@ function Header(props) {
const [inGame, setInGame] = React.useState(false);

const [openSettings, setOpenSettings] = React.useState(false);
const [keysDown] = useKeyboardListener();

useEffect(() => {
function ingameCallback(response){
Expand All @@ -81,6 +83,12 @@ function Header(props) {
socket.send({"request": "force_update_game_state"})
}, [])

useEffect(() => {
if (String(keysDown) === "r"){
randomize();
}
}, [keysDown])

async function randomize() {
setRandomizing(true);
function callback(response) {
Expand Down
22 changes: 13 additions & 9 deletions client/src/components/misc/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ function NavBar() {
{
"name": "Skins",
"icon": mdiPistol,
"path": "/collection"
"path": "/collection",
"enabled": Config.ENABLED_PAGES.collection,
},
{
"name": "Buddies",
"icon": mdiSpade,
"path": "/buddies"
"path": "/buddies",
"enabled": Config.ENABLED_PAGES.buddies,
},
]

Expand Down Expand Up @@ -78,13 +80,15 @@ function NavBar() {

<div style={{ width: "100%", marginTop: "10px" }}>
{tabs.map((tab, index) => (
<ListItem button key={tab.name} onClick={() => { selectPage(tab.path) }}>
<ListItemIcon><Icon
path={tab.icon}
size={iconSize}
/></ListItemIcon>
<ListItemText primary={tab.name} />
</ListItem>
(tab.enabled ?
<ListItem button key={tab.name} onClick={() => { selectPage(tab.path) }}>
<ListItemIcon><Icon
path={tab.icon}
size={iconSize}
/></ListItemIcon>
<ListItemText primary={tab.name} />
</ListItem>
: null)
))}
</div>

Expand Down
28 changes: 28 additions & 0 deletions client/src/components/weaponEditor/WeaponEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import WeaponHeader from './sub/WeaponHeader.js';
import ActionsDrawer from './sub/ActionsDrawer.js';
import WeightDialog from './sub/WeightDialog.js'

import useKeyboardListener from '../../services/useKeyboardListener.js'


const useStyles = makeStyles((theme) => ({

Expand Down Expand Up @@ -148,6 +150,9 @@ function WeaponEditor(props) {
//weight dialog states
const [weightDialogOpen, setWeightDialogOpen] = useState(false);

//keyboard state
const [keysDown] = useKeyboardListener();


//effect listeners
useEffect(() => {
Expand All @@ -169,6 +174,29 @@ function WeaponEditor(props) {
}, [])


// keyboard listeners
useEffect(() => {
console.log(keysDown)

switch (keysDown.join(' ')){
case 'f':
toggleFavoritedSkin();
break;

case 'l':
toggleLock();
break;

case 'Escape':
save();
break;

default:
break;
}

}, [keysDown])

// functions
function refresh() {
updateAlternateMedia();
Expand Down
2 changes: 0 additions & 2 deletions client/src/pages/BuddiesHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { makeStyles, useTheme } from '@material-ui/core/styles';
//components
import Header from '../components/misc/Header.js'
import Footer from '../components/misc/Footer.js'
import NavBar from '../components/misc/Navigation.js'

import Buddies from '../components/buddies/Buddies.js'

Expand Down Expand Up @@ -53,7 +52,6 @@ function CollectionHome(props) {
return (
<>
<div style={{ height: "100vh", width: "100vw", display: "flex", overflow: "auto" }}>
<NavBar />
<div style={{ height: "100%", margin: "auto", display: "flex", flexDirection: "column", justifyContent: "space-between", overflow: "auto", flexGrow: 1 }}>
<Header />
<Container maxWidth={null} style={{ maxHeight: "calc(100% - 122px)", display: "flex", flexGrow: 1, }}>
Expand Down
23 changes: 9 additions & 14 deletions client/src/pages/CollectionHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Footer from '../components/misc/Footer.js'
import WeaponEditor from '../components/weaponEditor/WeaponEditor.js'
import Collection from '../components/collection/Collection.js'

import NavBar from '../components/misc/Navigation.js'

import socket from "../services/Socket";

import { Grid, Container, Typography } from '@material-ui/core'
Expand Down Expand Up @@ -113,18 +111,15 @@ function CollectionHome(props) {
}

return (
<div style={{ height: "100vh", width: "100vw", display: "flex", overflow: "auto" }}>
<NavBar />
<div style={{ height: "100%", margin: "auto", display: "flex", flexDirection: "column", justifyContent: "space-between", overflow: "auto", flexGrow: 1 }}>
<Header />
{inventoryData !== {} ?
<Container maxWidth={false} style={{ display: "flex", height: "auto", flexGrow: 1, }}>
{weaponEditor}
<Collection style={{ padding: "20px 0px 20px 0px" }} weaponEditorCallback={modificationMenu} loadout={loadout} setLoadout={setLoadout} skinsOwned={uniqueSkinsOwned} />
</Container>
: null}
<Footer />
</div>
<div style={{ height: "100%", margin: "auto", display: "flex", flexDirection: "column", justifyContent: "space-between", overflow: "auto", flexGrow: 1 }}>
<Header />
{inventoryData !== {} ?
<Container maxWidth={false} style={{ display: "flex", height: "auto", flexGrow: 1, }}>
{weaponEditor}
<Collection style={{ padding: "20px 0px 20px 0px" }} weaponEditorCallback={modificationMenu} loadout={loadout} setLoadout={setLoadout} skinsOwned={uniqueSkinsOwned} />
</Container>
: null}
<Footer />
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/services/ClientConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const Config = {
WEIGHT_INTERVALS: 10,
SKIN_CHANGER_WARNING_THRESHOLD: 5,

NAVIGATION_ENABLED: true,
NAVIGATION_ENABLED: false,
ENABLED_PAGES: {
"collection": true,
"buddies": true,
"buddies": false,
}
}

Expand Down
31 changes: 0 additions & 31 deletions client/src/services/TypingEffect.js

This file was deleted.

32 changes: 0 additions & 32 deletions client/src/services/useEventListener.js

This file was deleted.

19 changes: 19 additions & 0 deletions client/src/services/useKeyboardListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useState, useEffect } from 'react';
import useEventListener from '@use-it/event-listener'

export default function useKeyboardListener() {
const [keysDown, setKeysDown] = useState([])

useEventListener("keydown", ({ key }) => {
var k = String(key)
if(!keysDown.includes(k)){
setKeysDown([...keysDown, k])
}
})
useEventListener("keyup", ({ key }) => {
var k = String(key)
setKeysDown(keysDown.filter(k2 => k2 !== k))
})

return [keysDown];
}

0 comments on commit c8be3c8

Please sign in to comment.