Skip to content

Commit

Permalink
Merge pull request #688 from andrew-bierman/feat/vite-routing
Browse files Browse the repository at this point in the history
Feat/vite routing
  • Loading branch information
andrew-bierman authored Mar 10, 2024
2 parents cda9810 + 9b44e12 commit 4954007
Show file tree
Hide file tree
Showing 128 changed files with 2,133 additions and 1,082 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Docker related
docker-compose.yml

# Vite TanStack codegen
routeTree.gen.ts

# Node modules and package files
node_modules/
package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion apps/bun-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "tsc"
},
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"dependencies": {
"@elysiajs/html": "^0.7.3",
Expand Down
5 changes: 3 additions & 2 deletions apps/expo/app/(app)/(drawer)/(tabs)/(stack)/profile/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useSearchParams, Stack } from 'expo-router';
import { Stack } from 'expo-router';
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Platform } from 'react-native';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import Head from 'expo-router/head';
import { useProfileId } from 'app/hooks/user';

const Profile = () => {
const { id } = useSearchParams();
const { id } = useProfileId();

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/app/(app)/(drawer)/(tabs)/search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Platform, TextInput } from 'react-native';
import { Platform, type TextInput } from 'react-native';
import { useCallback, useRef } from 'react';
import { Stack, useFocusEffect } from 'expo-router';
import Head from 'expo-router/head';
Expand Down
19 changes: 18 additions & 1 deletion apps/expo/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ config.transformer.minifierConfig.compress.drop_console = true;
config.resolver.assetExts.push('cjs');

// Include 'mjs' and 'cjs' in source extensions
config.resolver.sourceExts.push('mjs', 'cjs');
config.resolver.sourceExts.push('mjs', 'cjs', '.solito.js');

// Find the project and workspace directories
const projectRoot = __dirname;
Expand All @@ -31,4 +31,21 @@ config.resolver.nodeModulesPaths = [
// Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;

const customAliases = {
'@crosspath-resolver': './resolver.solito.js',
};

config.resolver.extraNodeModules = new Proxy(
{
...config.resolver.extraNodeModules,
...customAliases,
},
{
get: (target, name) =>
target.hasOwnProperty(name)
? target[name]
: path.join(projectRoot, 'node_modules', name),
},
);

module.exports = config;
10 changes: 5 additions & 5 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@hookform/resolvers": "^3.3.1",
"@hookform/resolvers": "^3.3.4",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/clipboard": "^1.5.1",
"@react-native-community/geolocation": "^3.0.6",
Expand Down Expand Up @@ -85,7 +85,7 @@
"expo-document-picker": "~11.5.4",
"expo-file-system": "~15.4.4",
"expo-font": "~11.4.0",
"expo-image-picker": "~14.3.2",
"expo-image-picker": "^14.7.1",
"expo-linear-gradient": "~12.3.0",
"expo-linking": "~5.0.2",
"expo-location": "~16.1.0",
Expand All @@ -107,7 +107,7 @@
"osmtogeojson": "^3.0.0-beta.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.46.1",
"react-hook-form": "^7.50.1",
"react-native": "0.72.10",
"react-native-dotenv": "^3.4.8",
"react-native-elements": "^3.4.3",
Expand Down Expand Up @@ -146,7 +146,7 @@
"@babel/preset-typescript": "^7.22.5",
"@tanstack/eslint-plugin-query": "^5.14.6",
"@tsconfig/react-native": "^3.0.2",
"@types/jest": "^29.5.3",
"@types/jest": "^29.5.11",
"@types/lodash": "^4.14.202",
"@types/node": "^20.8.3",
"@types/react": "^18.2.55",
Expand All @@ -163,7 +163,7 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
"prettier": "^3.0.2",
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"overrides": {
"metro": "0.73.7",
Expand Down
2 changes: 2 additions & 0 deletions apps/next/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { withTamagui } = require('@tamagui/next-plugin');
const { join } = require('path');
const path = require('path');
const webpack = require('webpack');
const { withCrossPath } = require('@packrat/crosspath/adapter');
const million = require('million/compiler');

const boolVals = {
Expand Down Expand Up @@ -38,6 +39,7 @@ const plugins = [
// ],
}),
withExpo,
withCrossPath('solito'),
];

const nextConfig = function () {
Expand Down
8 changes: 4 additions & 4 deletions apps/next/pages/profile/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Platform } from 'react-native';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { createParam } from 'solito';
import { useProfileId } from 'app/hooks/user';
import { AuthWrapper } from 'app/auth/AuthWrapper';

const { useParam } = createParam();

// export const runtime = 'experimental-edge'

const Profile = () => {
const [id] = useParam('id');
const [id] = useProfileId();

console.log({ id });

return (
<>
Expand Down
6 changes: 2 additions & 4 deletions apps/tauri/pages/profile/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Platform } from 'react-native';
import ProfileContainer from 'app/screens/user/ProfileContainer';
import { createParam } from 'solito';
import { useProfileId } from 'app/hooks/user';
import { AuthWrapper } from 'app/auth/AuthWrapper';

const { useParam } = createParam();

// export const runtime = 'experimental-edge'

const Profile = () => {
const [id] = useParam('id');
const [id] = useProfileId();

return (
<>
Expand Down
8 changes: 8 additions & 0 deletions apps/vite/envResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ export const API_URL = process.env.API_URL || 'http://localhost:3000/api';
export const NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN =
process.env.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN;

export const MAPBOX_ACCESS_TOKEN = process.env.MAPBOX_ACCESS_TOKEN;
export const CLIENT_URL = process.env.CLIENT_URL || 'http://localhost:3000';

export const NEXT_PUBLIC_API_URL = process.env.NEXT_PUBLIC_API_URL;

export default {
NODE_ENV,
API_URL,
NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN,
MAPBOX_ACCESS_TOKEN,
CLIENT_URL,
NEXT_PUBLIC_API_URL,
};
4 changes: 2 additions & 2 deletions apps/vite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<div id="app"></div>
<script type="module" src="/src/App.tsx"></script>
</body>
</html>
6 changes: 5 additions & 1 deletion apps/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"dependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@packrat/ui": "*",
"@packrat/validations": "*",
"@tamagui/vite-plugin": "^1.91.3",
"@tanstack/react-router": "^1.16.5",
"@tanstack/router-devtools": "^1.16.5",
"@tanstack/router-vite-plugin": "^1.16.5",
"@vitejs/plugin-react-swc": "^3.6.0",
"app": "*",
"esbuild-plugin-flow": "^0.3.2",
Expand All @@ -29,7 +33,7 @@
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"typescript": "^5.3.3",
"vite": "^5.1.0"
}
}
65 changes: 22 additions & 43 deletions apps/vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
import { useState } from 'react';
import reactLogo from './assets/react.svg';
import viteLogo from '/vite.svg';
import './App.css';
import '@tamagui/core/reset.css';
import React, { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider, createRouter } from '@tanstack/react-router';

import { RButton, YStack } from '@packrat/ui';
import { LinearGradient } from 'tamagui/linear-gradient';
import LandingPage from 'app/components/landing_page';
import { Provider } from 'app/provider';
// Import the generated route tree
import { routeTree } from './routeTree.gen';

function App() {
const [count, setCount] = useState(0);
// Create a new router instance
const router = createRouter({ routeTree });

return (
<Provider>
<LandingPage />
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<YStack f={1} ai="center" jc="center">
<RButton>Hello world</RButton>
<LinearGradient zIndex={-1} fullscreen colors={['red', 'blue']} />
</YStack>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
</Provider>
);
// Register the router instance for type safety
declare module '@tanstack/react-router' {
interface Register {
router: typeof router;
}
}

export default App;
// Render the app
const rootElement = document.getElementById('app')!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
);
}
10 changes: 0 additions & 10 deletions apps/vite/src/main.tsx

This file was deleted.

Loading

0 comments on commit 4954007

Please sign in to comment.