-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
3,568 additions
and
1,077 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
import tseslint from 'typescript-eslint' | ||
|
||
export default tseslint.config( | ||
{ ignores: ['dist'] }, | ||
{ | ||
extends: [js.configs.recommended, ...tseslint.configs.recommended], | ||
files: ['**/*.{ts,tsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@npwd/nui", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite --mode dev", | ||
"dev:game": "vite build --watch --mode game", | ||
"build": "vite build --mode game", | ||
"build:watch": "vite build --watch --mode game", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@npwd/keyos": "workspace:*", | ||
"@tanstack/react-query": "^5.62.8", | ||
"@tanstack/react-query-devtools": "^5.62.8", | ||
"jotai": "^2.10.4", | ||
"jotai-devtools": "^0.10.1", | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0", | ||
"react-router": "^7.0.2" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.17.0", | ||
"@types/react": "^19.0.2", | ||
"@types/react-dom": "^19.0.2", | ||
"@vitejs/plugin-react": "^4.3.4", | ||
"autoprefixer": "^10.4.14", | ||
"eslint": "^9.17.0", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-refresh": "^0.4.16", | ||
"globals": "^15.13.0", | ||
"postcss": "^8.4.21", | ||
"tailwindcss": "^3.4.0", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.18.1", | ||
"vite": "^6.0.3", | ||
"vite-tsconfig-paths": "^5.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RouterProvider } from 'react-router'; | ||
import { createRouter } from '@navigation/navigator'; | ||
import { useInitApps } from '@system/hooks/useApps'; | ||
|
||
function Phone() { | ||
const apps = useInitApps(); | ||
const router = createRouter(apps); | ||
|
||
return <RouterProvider router={router} /> | ||
} | ||
|
||
export default Phone; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AppGrid } from "@native/launcher/components/AppGrid" | ||
|
||
export const Launcher = () => { | ||
return ( | ||
<div className="h-full w-full bg-gray-500 rounded-xl"> | ||
<AppGrid /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AppRoute } from '@navigation/navigator'; | ||
import { Dialer } from './screens/Dialer'; | ||
|
||
export default { | ||
name: 'Phone', | ||
path: '/phone', | ||
Component: Dialer, | ||
} satisfies AppRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
|
||
export const Dialer: React.FC = () => { | ||
return ( | ||
<div> | ||
<h1>Dialer</h1> | ||
<h1>Coming soon...</h1> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AppRoute } from '@navigation/navigator'; | ||
import { Messages } from './screens/Messages'; | ||
|
||
export default { | ||
name: 'Messages', | ||
path: '/messages', | ||
Component: Messages, | ||
} satisfies AppRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const Messages = () => { | ||
return ( | ||
<div> | ||
<h1>Messages</h1> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export async function fetchApi<T>(url: string, options: RequestInit): Promise<T> { | ||
const res = await fetch(url, options); | ||
|
||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
|
||
return res.json() as Promise<T>; | ||
} | ||
|
||
export async function fxFetch<T = unknown, D = unknown>(eventName: string, data?: D): Promise<T> { | ||
const options = { | ||
method: 'post', | ||
headers: { | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}, | ||
body: JSON.stringify(data), | ||
}; | ||
|
||
// @ts-expect-error global nui property | ||
const resourceName = (window as any).GetParentResourceName | ||
? (window as any).GetParentResourceName() | ||
: 'npwd'; | ||
|
||
return await fetchApi<T>(`https://${resourceName}/${eventName}`, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
|
||
export const queryClient = new QueryClient() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import './index.css'; | ||
import Phone from './Phone.tsx'; | ||
import { DevTools } from 'jotai-devtools'; | ||
import 'jotai-devtools/styles.css'; | ||
import { Provider } from 'jotai'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; | ||
import { queryClient } from '@http/query.ts'; | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<QueryClientProvider client={queryClient}> | ||
<Provider> | ||
<DevTools /> | ||
<Phone /> | ||
</Provider> | ||
<ReactQueryDevtools /> | ||
</QueryClientProvider> | ||
</StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Outlet } from 'react-router'; | ||
|
||
export const PhoneFrame = () => { | ||
return ( | ||
<div className="bg-red-200 min-h-screen min-w-screen"> | ||
<div className="bg-white fixed bottom-5 right-5 w-[450px] h-[900px] rounded-xl shadow-lg"> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
apps/new-phone-react/src/native/launcher/components/AppGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useApps } from '@system/hooks/useApps'; | ||
import { Link } from 'react-router'; | ||
|
||
export const AppGrid = () => { | ||
const apps = useApps(); | ||
|
||
return ( | ||
<div className="grid grid-cols-4 gap-6 p-6"> | ||
{apps.map((app) => ( | ||
<Link | ||
to={app.path} | ||
key={app.path} | ||
className="p-6 bg-gray-300 rounded-xl flex items-center justify-center" | ||
> | ||
<h2>{app.name[0]}</h2> | ||
</Link> | ||
))} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { atom, useAtomValue, useSetAtom } from "jotai"; | ||
import { AppRoute } from "./navigator"; | ||
|
||
const navigatorAtom = atom<AppRoute[]>([]); | ||
|
||
export const rwNavigatorAtom = atom((get) => get(navigatorAtom), (get, set, update: AppRoute) => { | ||
const current = get(navigatorAtom); | ||
if (current.find((route) => route.path === update.path)) { | ||
return; | ||
} | ||
|
||
set(navigatorAtom, [...current, update]); | ||
}); | ||
|
||
export const useSetNavigator = () => useSetAtom(rwNavigatorAtom); | ||
export const useNavigators = () => useAtomValue(rwNavigatorAtom); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Launcher } from "@apps/Launcher"; | ||
import { PhoneFrame } from "@native/components/PhoneFrame"; | ||
import { createHashRouter } from "react-router"; | ||
|
||
export interface AppRoute { | ||
name: string; | ||
path: string; | ||
Component: React.ComponentType; | ||
} | ||
|
||
export const createRouter = (navigators: AppRoute[]) => { | ||
return createHashRouter([{ | ||
path: "/", | ||
Component: PhoneFrame, | ||
children: [ | ||
{ | ||
index: true, | ||
Component: Launcher, | ||
}, | ||
...navigators.map(({ path, Component }) => ({ | ||
path, | ||
Component, | ||
})), | ||
] | ||
}]) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useNavigators, useSetNavigator } from "@navigation/navigator.state"; | ||
|
||
export const useInitApps = () => { | ||
const setNavigator = useSetNavigator(); | ||
|
||
const modules = import.meta.glob('/src/apps/*/app.routes.ts', { eager: true }); | ||
const apps = Object.values(modules).map((mod) => mod.default).filter((app) => app); | ||
|
||
for (const app of apps) { | ||
if (!app) { | ||
continue; | ||
} | ||
|
||
setNavigator(app); | ||
} | ||
|
||
return apps; | ||
}; | ||
|
||
export const useApps = () => { | ||
const navigator = useNavigators(); | ||
return navigator; | ||
} |
Empty file.
Empty file.
Oops, something went wrong.