Skip to content

Commit

Permalink
chore(base): toggle phone ingame
Browse files Browse the repository at this point in the history
  • Loading branch information
antonstjernquist committed Sep 9, 2024
1 parent 5996ff8 commit 341578b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion scripts/move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ echo "Moving $name to destination $destination"
source="./dist"

# Move source to destination
cp -r $source "$destination/$name"
cp -Tr $source "$destination/$name"

17 changes: 13 additions & 4 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
let isFocused = false;
const exps = global.exports;
let isPhoneOpenState = false;

RegisterCommand(
'mock-command',
'npwd-toggle-phone',
() => {
console.log('calling mock command');
if (isPhoneOpenState) {
isPhoneOpenState = false;
global.SendNUIMessage({ type: 'SET_PHONE_OPEN', payload: false });
SetNuiFocus(false, false);
} else {
isPhoneOpenState = true;
global.SendNUIMessage({ type: 'SET_PHONE_OPEN', payload: true });
SetNuiFocus(true, true);
}
},
false,
);

RegisterKeyMapping('npwd-toggle-phone', 'Open Phone', 'keyboard', 'M');
1 change: 1 addition & 0 deletions src/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@tanstack/react-query-devtools": "4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-fivem-hooks": "^1.0.3",
"react-router": "^6.26.1",
"react-router-dom": "^6.26.1"
},
Expand Down
10 changes: 10 additions & 0 deletions src/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from 'react';
import { setTheme } from './utils/theme';
import { Footer } from './components/Main/Footer';
import { Header } from './components/Main/Header';
import { useNuiEvent } from 'react-fivem-hooks';

export const lightTheme = {
textColor: {
Expand Down Expand Up @@ -35,6 +36,15 @@ function App() {
: setTheme(lightTheme);
}, []);

const { data: isOpen } = useNuiEvent<boolean>({
event: 'SET_PHONE_OPEN',
defaultValue: false,
});

if (!isOpen) {
return null;
}

return (
<Frame>
<main className="flex flex-col flex-1 overflow-hidden">
Expand Down
7 changes: 5 additions & 2 deletions src/ui/src/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { PropsWithChildren } from 'react';
import { NuiProvider } from 'react-fivem-hooks';

export const Providers = ({ children }: PropsWithChildren) => {
const queryClient = new QueryClient({
Expand All @@ -19,8 +20,10 @@ export const Providers = ({ children }: PropsWithChildren) => {

return (
<QueryClientProvider client={queryClient}>
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
{children}
<NuiProvider>
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
{children}
</NuiProvider>
</QueryClientProvider>
);
};

0 comments on commit 341578b

Please sign in to comment.